I added a very simple example of a node spawning a urdf model on pastebin
Robert Krug ( 2012-02-28 04:29:03 -0500 )editDear 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
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);
I added a very simple example of a node spawning a urdf model on pastebin
Robert Krug ( 2012-02-28 04:29:03 -0500 )editI 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?
Asked: 2012-02-26 14:53:17 -0500
Seen: 726 times
Last updated: Mar 22 '12
Calling gazebo service set_model_state in C++ Code
calling service from c++ code. /gazebo/set_model_state
Gazebo service through c++ code
How to use SetModelState in a C++ to enable and disable gravity of an object
Do I need to know any specific computer language or framework to use ROS?
Problem with sensor_msgs::Image::ConstPtr conversion to IplImage
ROS Answers is licensed under Creative Commons Attribution 3.0 Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.