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

failed to call service spawn_urdf_model

asked 2017-04-22 00:16:22 -0500

jasonwang538@gmail.com gravatar image

updated 2017-09-13 15:12:14 -0500

jayess gravatar image

Hi everyone

I try to spawn a hector quadrotor model in c++ file as a ros node. But it always return "failed to call the service". I attached my code below:

#include "ros/ros.h"
#include <geometry_msgs/Pose.h> 
#include <gazebo_msgs/SpawnModel.h>
#include <stdlib.h>
#include<iostream>
#include<fstream>
#include <tf/transform_datatypes.h>

int main(int argc, char **argv)
{
    ros::init(argc, argv, "commander"); // Node setup
    ros::NodeHandle nh;

        std::ifstream ifs;
        ifs.open("quadrotor_hokuyo_utm30lx.gazebo.xacro");
        ros::ServiceClient spawn = nh.serviceClient< gazebo_msgs::SpawnModel> ("/gazebo/spawn_urdf_model");

        gazebo_msgs::SpawnModel s1;
        geometry_msgs::Pose p1;
        s1.request.model_name = "uav3";
        ifs >> s1.request.model_xml;
        s1.request.robot_namespace = "uav3";
        p1.position.x = 2.0;
        p1.position.y = 2.0;
        p1.position.z = 0.0;
        p1.orientation = tf::createQuaternionMsgFromYaw(0.0);
        s1.request.initial_pose = p1;
        s1.request.reference_frame = "";

   if (spawn.call(s1))
   {
     ROS_INFO("success");
   }
   else
   {
     ROS_ERROR("Failed to call service");
     return 1;
   }
    return 0;
}

Does anyone know what is wrong with it?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-04-23 21:54:34 -0500

Geoff gravatar image

You are loading an xacro file into model_xml, which should be the contents of a URDF file. You need to run the xacro file through the xacro parser first.

You are calling spawn_urdf_model but trying to use a Gazebo model description file (probably SRDF?). So the correct service to call is spawn_sdf_model.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2017-04-22 00:16:22 -0500

Seen: 1,640 times

Last updated: Sep 13 '17