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
Originally posted by [email protected] on ROS Answers with karma: 31 on 2017-04-22
Post score: 0