Gazebo | Ignition | Community
Ask Your Question

How correctly move joints by SetPositionPID() and SetPositionTarget()

asked 2018-03-21 02:33:30 -0500

xianxjm gravatar image

updated 2018-03-21 04:37:49 -0500

I want to set a joint to a certain angle properly and get its torque using Joint::GetForceTorque() in the process.

So I follow this tutorials try to control a joint, I try SetPositionPID() and SetPositionTarget() to contorl a joint ,but when I do this the joint cannt stop even its PID be set to zero by SetPositionPID(name, common::PID(0, 0, 0)).

P.S. I am using Gazebo-8, WITHOUT ROS. I have added (part of) the code from my plugin below.

    std::string name;
    if (update_num == 0)

        //Joint velocity using PID controller
        this->jointController.reset(new physics::JointController(this->model));
        name = model->GetJoint("purple_joint")->GetScopedName();
        //          this->jointController->SetVelocityPID(name, common::PID(100, 0, 0));
        this->jointController->SetPositionPID(name, common::PID(100, 0, 0));
        //          this->jointController->SetVelocityTarget(name, 1.0);

    else if (update_num < 200)
        // Must update PID controllers so they apply forces
    else if (update_num >= 200)
        name = model->GetJoint("purple_joint")->GetScopedName();
        this->jointController->SetPositionPID(name, common::PID(0, 0, 0));


Is there something wrong and why? How to set a joint to a certain angle properly and get its torque using Joint::GetForceTorque() in this process?

Best Regards!


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-03-21 13:12:14 -0500

sloretz gravatar image

The controller cannot stop the joint if the PID gains are set to common::PID(0, 0, 0).

The gains control how much torque the controller will apply. All zeros means everything in the equation used to calculate the torque applied by the controller is being multiplied by zero. Some torque needs to be applied to stop a moving joint.

Often the gains on the controller are set once at startup.

if (update_num == 0)
  // Initialize the controller with the gains to use
  this->jointController->SetPositionPID(name, common::PID(100, 0, 0));
else if (update_num == X)
  // time to tell the joint to go to position 1.57
  this->jointController->SetPositionTarget(name, 1.57);
else if (update_num == Y)
  // time to tell the joint to go back to position 0
  this->jointController->SetPositionTarget(name, 0);
// The controller applies torque when it is updated.
// This must be called every update that the controller should be controlling the joint position

You might be interested in reading

edit flag offensive delete link more


thank you very much~

xianxjm gravatar imagexianxjm ( 2018-04-25 01:42:19 -0500 )edit

Question Tools

1 follower


Asked: 2018-03-21 02:33:30 -0500

Seen: 1,262 times

Last updated: Mar 21 '18