c++ api gazebo
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
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org |
asked 2012-02-28 22:21:26 -0500
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
answered 2012-02-28 22:58:22 -0500
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
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2012-02-28 22:21:26 -0500
Seen: 2,223 times
Last updated: Feb 28 '12
rgbdslam: send model + reset, how to automate the process?
spawn urdf model in gazebo by C++
No point cloud in Turtlebot Gazebo gmapping
Some part of the robot display below map ?
urdf_spawner -J option not working as intended
CLion error when using the debugger and image transport
Gazebo plugin for ROS2 doesn't get loaded
syntax error near unexpected token [SOLVED]
Package to Interact with the turtlebot Simulator in Gazebo.''