Gazebo | Ignition | Community
Ask Your Question

How to Control Pioneer2DX in Gazebo...?

asked 2016-07-06 14:21:17 -0500

icepaka89 gravatar image

updated 2016-07-07 13:40:21 -0500

So I am using gazebo to simulate a pioneer2dx model, however I can't find a good documentation on how to control it properly. Right now my plugin uses the SetLinerVel function to move the robot, however this just pushed the robot along. I want to know how to be able to control the actual wheels of the robot (i.e. set the angular velocity of the hinges). Is there a way to do this? Also is there a way to get the sensor values from the robot? Thanks.


Here is my plugin c++ code:

#include <boost/bind.hpp>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <stdio.h>

namespace gazebo
class PioneerProg : public ModelPlugin
  public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
  // Store the pointer to the model
  this->model = _parent;

  // Listen to the update event. This event is broadcast every
  // simulation iteration.
  this->updateConnection = event::Events::ConnectWorldUpdateBegin(
      boost::bind(&PioneerProg::OnUpdate, this, _1));

// Called by the world update start event
public: void OnUpdate(const common::UpdateInfo & /*_info*/)
  // Apply a small linear velocity to the model.
  //this->model->SetLinearVel(math::Vector3(0.06, 0, 0));
joints[LEFT_FRONT_WHEELING] = this->parent->GetJoint(left_wheel_hinge);
joints[LEFT_FRONT_WHEELING]->SetParam("fmax", 0, torque);
joints[LEFT_FRONT_WHEELING]->SetParam("vel", 0, wheel_data_[LEFT_FRONT_WHEELING]/(wheel_diameter_/2.0));


// Pointer to the model
private: physics::ModelPtr model;

// Pointer to the update event connection
private: event::ConnectionPtr updateConnection;

// Register this plugin with the simulator

And here is my world file xml code:

<?xml version="1.0" ?>
<sdf version="1.5">
<world name="default">
    <!-- A global light source -->

    <!-- A ground plane -->

    <!-- Generate Population -->
    <population name="pioneer_population1">
        <!-- Define the population model type -->
        <model name="pioneer1">
            <plugin name="pioneer_prog" filename=""/>

        <!-- Center spawn around (0,0,0) with orientation <0,0,0> -->
        <pose>0 0 0 0 0 0</pose>

        <!-- Size of spawn area -->
            <size>8 8 0.01</size>

        <!-- world_builder will insert this line based on user params -->
        <!-- MODEL_COUNT -->

        <!-- /MODEL_COUNT -->

        <!-- Define how the models will be distributed -->
        <!-- Distribution types: random, uniform, grid, linear-x, 
        liner-y, linear-z -->


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-07-07 01:48:54 -0500

Brosseau.F gravatar image

To control the wheels you can use two methods :

joints[LEFT_FRONT_WHEELING]->SetParam("vel", 0, wheel_data_[LEFT_FRONT_WHEELING] / (wheel_diameter_ / 2.0));

You just have to get the right joint of your robot :

joints[LEFT_FRONT_WHEELING] = this->parent->GetJoint(left_front_wheeling_joint_name_);

and set the max force you want to apply on it :

joints[LEFT_FRONT_WHEELING]->SetParam("fmax", 0, torque);


joint_controller_->SetVelocityTarget(joints[LEFT_FRONT_WHEELING]->GetScopedName(),wheel_data_[LEFT_FRONT_WHEELING] / (wheel_diameter_ / 2.0) );

You will have to get the joint controller :

joint_controller_ = this->parent->GetJointController();

And set your own PID :

gazebo::common::PID PID = gazebo::common::PID(500,0,10);
joint_controller_->SetVelocityPID(joints[LEFT_FRONT_WHEELING]->GetScopedName(), PID);
edit flag offensive delete link more


Thanks for your help, however I can't seem to get this to work. I'm getting that "joints" doesn't exist. I dont really understand/know how programming in gazebo works so sorry if this is a menial issue. I have included my plugin and world file above. Please let me know where I went wrong. Thanks.

icepaka89 gravatar imageicepaka89 ( 2016-07-07 13:40:41 -0500 )edit

You should take a look at some existing plugin. Source file : How to use it in your world description file :

Brosseau.F gravatar imageBrosseau.F ( 2016-07-08 02:21:19 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-07-06 14:21:17 -0500

Seen: 929 times

Last updated: Jul 07 '16