Home | Tutorials | Wiki | Issues
Ask Your Question
0

How to Control Pioneer2DX in Gazebo...?

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

icepaka89 gravatar image

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

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.


UPDATE

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
GZ_REGISTER_MODEL_PLUGIN(PioneerProg)
}

And here is my world file xml code:

<?xml version="1.0" ?>
<sdf version="1.5">
<world name="default">
    <!-- A global light source -->
    <include>
        <uri>model://sun</uri>
    </include>

    <!-- A ground plane -->
    <include>
        <uri>model://ground_plane</uri>
    </include>

    <!-- Generate Population -->
    <population name="pioneer_population1">
        <!-- Define the population model type -->
        <model name="pioneer1">
            <include>
                <static>false</static>
                <uri>model://pioneer2dx</uri>
            </include>
            <plugin name="pioneer_prog" filename="libpioneer_prog.so"/>
        </model>

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

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

        <!-- 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 -->
        <distribution>
            <type>random</type>
        </distribution>
    </population>
</world>

</sdf>

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

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);

Or

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

Comments

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 -0600 )edit

You should take a look at some existing plugin. Source file : https://github.com/ros-simulation/gazebo_ros_pkgs/blob/jade-devel/gazebo_plugins/src/gazebo_ros_diff_drive.cpp How to use it in your world description file : http://gazebosim.org/tutorials?tut=ros_gzplugins

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

Question Tools

1 follower

Stats

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

Seen: 638 times

Last updated: Jul 07 '16