Problem with SetPositionTarget

asked 2017-04-26 11:33:37 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi guys, I'm new with Gazebo. I'm trying to make the robot handles, thanks to a plugin, a link in a certain position through a prismatic joint. The robot's structure is composed by a fixed part and a mobile one; the fixed part is under the mobile one. The two parts have the same shape and they are linked through 3 prismatic joints that allow the translation over the z axis. I want to rise the mobile part in a certain position through the z axis. Now I'm using the method SetPositionTarget but it doesn't work. Anyone has some suggestions on how to fix it? The code of the plugin is pasted below in hopes that you can identify a problem.

namespace gazebo{

class ModelPush: public ModelPlugin{

    void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf){
        this->model = _model;
        this->sdf = _sdf;
        if(this->model->GetJointCount() == 0){
            std::cerr << "Invalid joint count\n";

        this->centerJoint = this->model->GetJoint("center_chassis_joint");

        this->leftJoint = this->model->GetJoint("left_chassis_joint");

        this->rightJoint = this->model->GetJoint("right_chassis_joint");

        this->pid_right = common::PID(0.1, 0, 0);
        this->pid_left = common::PID(0.1, 0, 0);
        this->pid_center = common::PID(0.1, 0, 0);

        this->model->GetJointController()->SetPositionPID(this->rightJoint->GetScopedName(), this->pid_right);
        this->model->GetJointController()->SetPositionPID(this->centerJoint->GetScopedName(), this->pid_center);
        this->model->GetJointController()->SetPositionPID(this->leftJoint->GetScopedName(), this->pid_left);

        this->model->GetJointController()->SetPositionTarget(this->rightJoint->GetScopedName(), 2);
        this->model->GetJointController()->SetPositionTarget(this->centerJoint->GetScopedName(), 2);
        this->model->GetJointController()->SetPositionTarget(this->leftJoint->GetScopedName(), 2);

public: physics::JointPtr centerJoint;
    public: physics::JointPtr leftJoint;
    public: physics::JointPtr rightJoint;
    public: physics::JointPtr backJoint;
    public: physics::ModelPtr model;
    public: sdf::ElementPtr sdf;
    public: common::PID pid_right,pid_left,pid_center;
edit retag flag offensive close merge delete


Have you tried playing with the PID values? You could use the right panel to change the values in real time.

chapulina gravatar imagechapulina ( 2017-04-27 10:18:06 -0500 )edit

I solved by modifing the PID values. Thanks for your answer!

antonio_ia gravatar imageantonio_ia ( 2017-05-02 08:21:00 -0500 )edit

I try to built the same code but I get this error: ‘class gazebo::physics::JointController’ has no member named ‘SetPositionTarget’. The same for SetPositionPID. I have included gazebo.hh, physics.hh, common.hh and stdio.h. I have gazebo 2.2.6 installed gravatar ( 2017-07-13 12:29:41 -0500 )edit