ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

c++ api gazebo

asked 2012-02-28 22:21:26 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi, i'm new in Ros. I want to see a example of a program in c++ where i can see how i can move the joints. I'm a beginner, so i can't know how I can find thiys information. Thank you Angelo

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-02-28 22:58:22 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

You can use the ros libraries and plugins. You add a controller in gazebo which listens to a topic, e.g. gazebo_ros_force. For your case you might want to use gazebo_ros_p3d, to change the position instead of force.

Add a controller to your urdf file like so:

<controller:gazebo_ros_force name="controller_name" plugin="">

This is a force controller which listen to the topic /force1.

You then use the roscpp api to publish and subscribe to the gazebo topics. You can find a good guide for creating these publisher and subscribers here.

But you change the example for publishing wrenches and listening to gazebo link states. Like i did with a force controller:

   ros::NodeHandle nh; 
   pub = nh.advertise<geometry_msgs::Wrench>("force1", 5);
   sub = nh.subscribe<gazebo_msgs::LinkStates>("gazebo/link_states", 1000, linkstatesCallback); //ROS gazebo publishes all joint states, you can use these.

I publish forces and i listen to positions and create a feedback loop. It is obviously easier to just change position with a different controller if that is what you are after.

Publishing is easy and goes like this:


You can also work around ROS by using the actual gazebo API, however in my opinion the documentation for the older version is limited. I would not recommend this unless you really need direct access to the simulator.

Combine these snippets with the tutorials it should work

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2012-02-28 22:21:26 -0500

Seen: 2,223 times

Last updated: Feb 28 '12