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

Add full PID control, plus small bug fixes #117

Closed

Conversation

AndyZe
Copy link
Contributor

@AndyZe AndyZe commented Feb 9, 2023

Use the control_toolbox PID controller instead of simple proportional control.

@AndyZe AndyZe requested a review from ahcorde as a code owner February 9, 2023 21:42
this->nh_->get_logger(),
"The position_proportional_gain parameter was not defined, defaulting to: " <<
default_gain);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this PID initialization stuff to the bottom of the function so that joint names would be available for the debug prints.

@@ -589,7 +607,7 @@ hardware_interface::return_type IgnitionSystem::write(
{
this->dataPtr->ecm->CreateComponent(
this->dataPtr->joints_[i].sim_joint,
ignition::gazebo::components::JointVelocityCmd({0}));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe it makes sense to initialize this to 0 when we have a command available.

Comment on lines -647 to -648
} else if (!vel->Data().empty()) {
vel->Data()[0] = target_vel;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, I duplicated this block of code. Plus, I think it is safer to use:

        const auto jointVelCmd =
          this->dataPtr->ecm->Component<ignition::gazebo::components::JointVelocityCmd>(
          this->dataPtr->joints_[i].sim_joint);
        *jointVelCmd = ignition::gazebo::components::JointVelocityCmd(
          {target_vel});

Than...

vel->Data()[0] = target_vel;

I might be wrong, though.

@AndyZe AndyZe force-pushed the andyz/full_pid_to_ros2_control branch from 7e94c08 to 57a8a08 Compare February 9, 2023 21:52
@AndyZe AndyZe marked this pull request as draft February 10, 2023 02:12
@AndyZe AndyZe marked this pull request as ready for review February 10, 2023 07:40
@AndyZe AndyZe force-pushed the andyz/full_pid_to_ros2_control branch from 6193718 to 94a6c4a Compare February 10, 2023 14:01
@AndyZe AndyZe marked this pull request as draft February 13, 2023 21:28
@livanov93
Copy link
Contributor

livanov93 commented Feb 16, 2023

@AndyZe I was looking at your changes in write - https://github.com/AndyZe/ign_ros2_control/blob/0c4da2204c27acdf97a3002a14507c39561d22fe/ign_ros2_control/src/ign_system.cpp#L621-L703 . I have been experimenting locally with changing whole approach here. What do you think about fully moving to foce commands. I get the inspiration from main ignition examples. Please take a look here:

We could also create cascade loop when using position interface from ros2_control with outer PD position controller and inner velocity loop with PID and final output with force/torque that is always propagated to the physics engine via JointForceCmd. Also using joint position and velocity limits as limiters in the loop.

IMHO this would be the correct way of doing this. What do you think?

@AndyZe
Copy link
Contributor Author

AndyZe commented Feb 16, 2023

That sounds like it is worth trying. I also see that (in the example you linked) they use a math::PID type of controller which has saturation (cmdMax, cmdMin) options. That would be nice to have.

I don't trust the derivative term from the control_toolbox PID controller. It gave some really weird output. Yet another reason to switch to math::PID type.

I see something weird with this PR and I haven't been able to track down the cause. After I make contact with a surface, the arm occasionally springs back rapidly. I don't know if this is coming from the PID controller or from Gazebo contact physics.

@livanov93
Copy link
Contributor

That sounds like it is worth trying. I also see that (in the example you linked) they use a math::PID type of controller which has saturation (cmdMax, cmdMin) options. That would be nice to have.

Then I will try to add those, and maybe some kind of wrapper for cascade control. Please don't mind if I hijack some commits from here.

I don't trust the derivative term from the control_toolbox PID controller. It gave some really weird output. Yet another reason to switch to math::PID type.

Too bad. I wasn't aware about that issue.

I see something weird with this PR and I haven't been able to track down the cause. After I make contact with a surface, the arm occasionally springs back rapidly. I don't know if this is coming from the PID controller or from Gazebo contact physics.

I can't tell without testing :/

Copy link
Collaborator

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

I merged the ign to gz PR, and you have some conflicts, Sorry, it was a huge change

@AndyZe
Copy link
Contributor Author

AndyZe commented Mar 1, 2023

Closing this because I think effort-based control like in #122 would be a lot better 👍

@AndyZe AndyZe closed this Mar 1, 2023
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