Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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 force be set to zero by SetForce(0, 0).

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

public: void Update(const common::UpdateInfo &_info) { if (update_num == 0) { this->jointController.reset(new physics::JointController( this->model));

        float leftTargetAngle = 1.57;
        float leftP = leftTargetAngle - this->model->GetJoint("purple_joint")->GetAngle(0).Radian();

        leftP *= 10;

        this->model->GetJoint("purple_joint")->SetForce(0, leftP);

        this->model->GetJointController()->SetPositionPID(this->model->GetJoint("purple_joint")->GetScopedName(), common::PID(100, 0, 0));

        this->model->GetJointController()->SetPositionTarget(this->model->GetJoint("purple_joint")->GetScopedName(), leftTargetAngle);

        this->jointController->Update();

    }
    update_num++;

    if(update_num==500)
    {
        this->model->GetJoint("purple_joint")->SetForce(0, 0);
    }

    return ;

}

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!

xinaxjm

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

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 force PID be set to zero by SetForce(0, 0).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.

public: void Update(const common::UpdateInfo &_info) {

    std::string name;
    if (update_num == 0)
     {
 
        //Joint velocity using PID controller
        this->jointController.reset(new physics::JointController(
                                            this->model));

        float leftTargetAngle physics::JointController(this->model));
        this->jointController->AddJoint(model->GetJoint("purple_joint"));
        name = 1.57;
        float leftP = leftTargetAngle - this->model->GetJoint("purple_joint")->GetAngle(0).Radian();

        leftP *= 10;

        this->model->GetJoint("purple_joint")->SetForce(0, leftP);

        this->model->GetJointController()->SetPositionPID(this->model->GetJoint("purple_joint")->GetScopedName(), model->GetJoint("purple_joint")->GetScopedName();
        //          this->jointController->SetVelocityPID(name, common::PID(100, 0, 0));

        this->model->GetJointController()->SetPositionTarget(this->model->GetJoint("purple_joint")->GetScopedName(), leftTargetAngle);

        this->jointController->SetPositionPID(name, common::PID(100, 0, 0));
        this->jointController->SetPositionTarget(name,1.57);
        //          this->jointController->SetVelocityTarget(name, 1.0);

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

    }
    update_num++;

    if(update_num==500)
    {
        this->model->GetJoint("purple_joint")->SetForce(0, 0);
    }

    return ;

}

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!

xinaxjm