How to Control Pioneer2DX in Gazebo...?
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>