Gazebo service through c++ code
I have created a server and client about set model state service of gazebo. This is the error I get when I run make:
/home/phadjic/ros_workspace/pool_party/src/client.cpp: In function ‘int main(int, char)’: /home/phadjic/ros_workspace/pool_party/src/client.cpp:36:39: error: no match for ‘operator=’ in ‘setmodelstate.gazebo_msgs::SetModelState::request.gazebo_msgs::SetModelStateRequest_<std::allocator<void> >::model_state = modelstate’ /opt/ros/electric/stacks/simulator_gazebo/gazebo_msgs/msg_gen/cpp/include/gazebo_msgs/ModelState.h:23:20: note: candidate is: gazebo_msgs::ModelState_<std::allocator<void> >& gazebo_msgs::ModelState_<std::allocator<void> >::operator=(const gazebo_msgs::ModelState_<std::allocator<void> >&) /home/phadjic/ros_workspace/pool_party/src/client.cpp:39:22: error: ‘SetModelState’ was not declared in this scope /home/phadjic/ros_workspace/pool_party/src/client.cpp:42:8: error: no matching function for call to ‘print(int, log4cxx::Logger&, ros::console::Level&, const char [54], int, const char [22], double&)’ /opt/ros/electric/stacks/ros_comm/tools/rosconsole/include/ros/console.h:132:22: note: candidates are: void ros::console::print(ros::console::FilterBase, log4cxx::Logger, ros::console::Level, const char, int, const char, const char, ...) /opt/ros/electric/stacks/ros_comm/tools/rosconsole/include/ros/console.h:136:22: note: void ros::console::print(ros::console::FilterBase, log4cxx::Logger, ros::console::Level, const std::stringstream&, const char, int, const char)
The lines of my client file mentioned above are:
ros::ServiceClient client = n.serviceClient<gazebo_msgs::setmodelstate("/gazebo_msgs/SetModelState");
gazebo_msgs::SetModelState setmodelstate;
setmodelstate.request.model_state=modelstate;
client.call(setmodelstate);
if (client.call(setModelState))
{
ROS_INFO("BRILLIANT!!!");
ROS_INFO(start_pose.position.x);
}
else
{
ROS_ERROR("Failed to call service ");
return 1;
}
Correction for the first line; ros::ServiceClient client = n.serviceClient<gazebo_msgs::setmodelstate>("/gazebo_msgs/SetModelState");