Advertisement
Guest User

Untitled

a guest
Feb 28th, 2012
826
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ros/ros.h>
  2. #include <gazebo_msgs/SpawnModel.h>
  3. #include <iostream>
  4. #include <fstream>
  5.  
  6. int main(int argc, char** argv)
  7. {
  8.   ros::init(argc, argv, "my_node");
  9.   ros::NodeHandle nh;
  10.   ros::ServiceClient gazebo_spawn_clt = nh.serviceClient<gazebo_msgs::SpawnModel> ("/gazebo/spawn_urdf_model");
  11.  
  12.   gazebo_msgs::SpawnModel model;
  13.   std::ifstream file("/opt/ros/electric/stacks/simulator_gazebo/gazebo_worlds/objects/coke_can.urdf");
  14.   std::string line;
  15.  
  16.    while(!file.eof()) // Parse the contents of the given urdf in a string
  17.     {
  18.       std::getline(file,line);
  19.       model.request.model_xml+=line;
  20.     }
  21.   file.close();
  22.  
  23.   model.request.model_name="my_model";
  24.   model.request.reference_frame="world";
  25.   gazebo_spawn_clt.call(model); //Call the service
  26.   return 0;
  27. }
Advertisement
RAW Paste Data Copied
Advertisement