Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Based on nkoenig's suggestion and an answer by AndreiHaidu to another question (see http://answers.gazebosim.org/question/2341/set-and-get-position-of-gazebo-model-using-ros-plugin/) my solution that seems to work so far is:

  • created a PID object for each joint I want to control
  • created an Update method for the controller (based on link above and the Update method in JointController.cc of Gazebo-7 source code) , code snippet given below
    • finally, in the the OnUpdate step of my plugin class i set my desired steering angle set-point (m_setpoint) via a different function and call the Update method I implemented for all my joints' PIDs.

void PID_JointController::Update(){

common::Time currTime = this->m_model->GetWorld()->GetSimTime();
common::Time stepTime = currTime - this->m_prevUpdateTime;
this->m_prevUpdateTime = currTime;

if ( stepTime > 0 ) {
    m_cmd_force = this->m_PositionPID.Update(
                this->m_JointPtr->GetAngle(m_axis_index).Radian() -
                this->m_setpoint, stepTime);
    this->m_JointPtr->SetForce(m_axis_index, m_cmd_force);
}

Based on nkoenig's suggestion and an answer by AndreiHaidu to another question (see http://answers.gazebosim.org/question/2341/set-and-get-position-of-gazebo-model-using-ros-plugin/) my solution that seems to work so far is:

  • created a PID object for each joint I want to control
  • created an Update method for the controller (based on link above and the Update method in JointController.cc of Gazebo-7 source code) , code snippet given below
    • finally, in the the OnUpdate step of my plugin class i set my desired steering angle set-point (m_setpoint) via a different function and call the Update method I implemented for all my joints' PIDs.

void PID_JointController::Update(){

common::Time currTime = this->m_model->GetWorld()->GetSimTime();
common::Time stepTime = currTime - this->m_prevUpdateTime;
this->m_prevUpdateTime = currTime;

if ( stepTime > 0 ) {
    m_cmd_force = this->m_PositionPID.Update(
                this->m_JointPtr->GetAngle(m_axis_index).Radian() -
                this->m_setpoint, stepTime);
    this->m_JointPtr->SetForce(m_axis_index, m_cmd_force);
}