Ask Your Question
0

How can I use the C++ program to add , delete object in ros gazebo

asked 2012-02-26 14:53:17 -0500

zhenli gravatar image zhenli
249 21 31 36

updated 2012-02-27 11:55:06 -0500

Mac gravatar image Mac flag of United States
3639 17 56 74
http://www.cs.duke.edu/~m...

Dear All. While read the following documentation, I can not know how to use it to create c++ program to add or delete object in ros gazebo automatically by program. http://www.ros.org/wiki/simulator_gazebo/Tutorials/SpawningObjectInSimulation

edit retag flag offensive close delete

3 Answers

Sort by ยป oldest newest most voted
5

answered 2012-02-27 03:33:19 -0500

Lorenz gravatar image Lorenz flag of Germany
17491 61 144 285
http://ias.in.tum.de/peop...

updated 2012-02-27 10:49:44 -0500

This shows which services to call and how and this shows how to call a service in C++.

edit flag offensive delete publish link more
2

answered 2012-02-27 15:17:33 -0500

Robert Krug gravatar image Robert Krug
93 6 6 17

updated 2012-02-27 16:06:10 -0500

You can use either the /gazebo/spawn_urdf_model service (for .urdf files) or the /gazebo/spawn_gazebo_model service (for gazebo .xml files). In your code you need a service client for the service, e.g., for urdf models:

ros::ServiceClient gazebo_spawn_clt_ = node_handle_.serviceClient< gazebo_msgs::SpawnModel> ("/gazebo/spawn_urdf_model");

Then you need to read the contents of the urdf file into the model_xml field of a gazebo_msgs::SpawnModel service. The generated service then can be used to call your client:

gazebo_spawn_clt_.call(spawn_model_srv);

edit flag offensive delete publish link more

Comments

Can you give me a detail example for URDF file.

zhenli ( 2012-02-27 16:19:48 -0500 )edit

I added a very simple example of a node spawning a urdf model on pastebin

Robert Krug ( 2012-02-28 04:29:03 -0500 )edit
0

answered 2012-02-27 16:31:36 -0500

zhenli gravatar image zhenli
249 21 31 36

updated 2012-03-22 20:44:53 -0500

hsu gravatar image hsu
4573 10 43 69

I use the following function to create box in the gazebo world. It is here, but why it is not visible? I can not see it, but sure it is in the gazebo world with name and position information. The step: 1.I download the object.urdf 2. I use : rosrun gazebo urdf2model -f object.urdf -o object.model 3. Based on the talker program package, I add the gazebo package

-----  
#include <gazebo/SpawnModel.h>  
#include <gazebo/urdf2gazebo.h>

#include<iostream>
#include<fstream>
#include <tf/transform_datatypes.h>

The in the function I define the following:

gazebo::SpawnModel sm;

    std::ifstream ifs;
    ifs.open("object.model");

    sm.request.model_name = "box";
    ifs >> sm.request.model_xml;



    sm.request.initial_pose.position.x = 4.0;
    sm.request.initial_pose.position.y = 4.0;
    sm.request.initial_pose.position.z = 1.0;

    sm.request.initial_pose.orientation = tf::createQuaternionMsgFromYaw(0.0);

    sm.request.reference_frame = "";

    ros::service::call( "/gazebo/spawn_gazebo_model", sm );

So I do not why we can not see it but it is in the gazebo world?

edit flag offensive delete publish link more

Comments

which object.model are you using? please post the xml. thanks.

hsu ( 2012-03-22 20:47:59 -0500 )edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

subscribe to rss feed

Stats

Asked: 2012-02-26 14:53:17 -0500

Seen: 726 times

Last updated: Mar 22 '12