ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

c++ api gazebo

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

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
3

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

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="libgazebo_ros_force.so">
  <alwaysOn>true</alwaysOn>
  <updateRate>1000.0</updateRate>
  <topicName>force1</topicName>
  <bodyName>body_name</bodyName>
</controller:gazebo_ros_force>

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:

 pub.publish(wrench);
 ros::spinOnce();

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

Question Tools

2 followers

Stats

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

Seen: 2,345 times

Last updated: Feb 28 '12