Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JointGroupPositionController: Set current position as target in starting() #504

Conversation

wxmerkt
Copy link
Contributor

@wxmerkt wxmerkt commented Aug 25, 2020

Currently, the target position upon starting is all zeros. This is not great if a command is not issued immediately (and even then). To be safer, set the goal position to the current sensed position and also reset the PID internal state upon starting.

(This PR is on top of #503)

Copy link
Member

@matthew-reynolds matthew-reynolds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change has no dependence on #503, could you please trim the branch down to just the relevant commit to make it easier to review and merge.


LGTM, especially because this is already what's done in most other position controllers. Set cmd=pos, reset PID.

enforceJointLimits(current_positions[i], i);
pid_controllers_[i].reset();
}
commands_buffer_.writeFromNonRT(current_positions);
Copy link
Member

@matthew-reynolds matthew-reynolds Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starting() is in the RT domain, so rather than calling writeFromNonRT(), you should write to the command buffer directly. (The realtime buffer lacks a proper writeFromRT method since it's really intended for writing from a single non-RT thread, reading from a single RT thead. I haven't worked through the accesses and how safe this aooriach is, but from these examples by people much smarter than me, it seems this is a safe solution)

Examples:

void forward_command_controller::ForwardJointGroupCommandController<T>::starting(const ros::Time& time)
{
// Start controller with current joint positions
std::vector<double> & commands = *commands_buffer_.readFromRT();
for(unsigned int i=0; i<joints_.size(); i++)
{
commands[i]=joints_[i].getPosition();
}
}

void forward_command_controller::ForwardJointGroupCommandController<T>::starting(const ros::Time& time)
{
// Start controller with 0.0 velocities
commands_buffer_.readFromRT()->assign(n_joints_, 0.0);
}

Copy link
Member

@matthew-reynolds matthew-reynolds Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at this again, I think the right solution is to just use initRT(). In practical senses, it'll be pretty much the same thing, but with less overhead and also less hackey.

I think those examples I linked should probably be updated to initRT() as well. I'll look into that (#511).

@wxmerkt wxmerkt force-pushed the wxm-jointgrouppositioncontroller-set-current-position-as-target-on-starting branch from 745f2ab to e25a037 Compare September 4, 2020 11:01
@wxmerkt
Copy link
Contributor Author

wxmerkt commented Sep 4, 2020

Thank you for the review and feedback @matthew-reynolds. I updated the PR to use initRT and split it from the changes in #503.

Copy link
Member

@matthew-reynolds matthew-reynolds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me, ping @bmagyar for another set of eyes and potential merge

@wxmerkt
Copy link
Contributor Author

wxmerkt commented Sep 23, 2020

@bmagyar are we good to merge this?

Copy link
Member

@bmagyar bmagyar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much appreciated guys, thank you!

…ition in starting

Currently, the target position upon starting is all zeros. This is not
great if a command is not issued immediately. To be safer, set the goal
position to the current sensed position and also reset the PID internal
state upon starting.
@bmagyar bmagyar force-pushed the wxm-jointgrouppositioncontroller-set-current-position-as-target-on-starting branch from 35ccf33 to 997e909 Compare September 25, 2020 07:41
@bmagyar
Copy link
Member

bmagyar commented Sep 25, 2020

I've rebased this on the latest upstream which should have the CI fixed, merging when all turns green

@bmagyar
Copy link
Member

bmagyar commented Sep 25, 2020

I still consider a diff_drive_controller failure green ;)

@bmagyar
Copy link
Member

bmagyar commented Sep 25, 2020

Thanks for the fix @wxmerkt , merging

@bmagyar bmagyar merged commit a1ef224 into ros-controls:noetic-devel Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants