The contents of this page include:
When creating a new robot or sensor, first check the available controllers. Sometimes a pre-existing controller will suit your needs. For example, a new type of camera could potentially use the
generic_camera controller. Or if a new robot has a drive train similar to a Pioneer2dx, then use the
gazebo/server/controllers/camera, and 2d position controllers should go in
gazebo/server/controller/position2d. Create a new directory as appropriate.
Copy the example controller,
gazebo/server/controler/ControllerStub.* to your new controller directory. Replace the names as appropriate.
LoadChildfunction, which is called after initial creationg of the controller.
A controller should have one or more interfaces. Make sure to get a valid pointer to the controllers inteface.
If we are creating a position2d controller, this code would be:
this->myIface = dynamic_cast<PositionIface*>(this->ifaces); if (!this->myIface) gzthrow("NAME controller requires a PositionIface");
Use the XMLConfigNode pointer to load in any other necessary parameters. For example, the Pioneer2d_Position controller need two hinge joints:
std::string leftJointName = node->GetString("leftJoint", "", 1); std::string rightJointName = node->GetString("rightJoint", "", 1); this->joints[LEFT] = dynamic_cast<HingeJoint*>(this->myParent->GetJoint(leftJointName)); this->joints[RIGHT] = dynamic_cast<HingeJoint*>(this->myParent->GetJoint(rightJointName)); if (!this->joints[LEFT]) gzthrow("couldn't get left hinge joint"); if (!this->joints[RIGHT]) gzthrow("couldn't get right hinge joint");
InitChildfunction is called. Use this function to initialize any variables.
UpdateChildfunction is called. Use this function to get command from the libgazebo interface, manipulate any physical objects, and publish new data.
For a good example of manipulating joints, look at the Pioneer2dx_Position2d controller. For a a good example of publishing data, look at the SickLMS200_Laser controller.