Ask Your Question
0

Cannot build simple service on Melodic (getServerMD5Sum is not a member of std_msgs::Float32)

asked 2019-08-14 11:26:42 -0500

SteveWithers gravatar image

updated 2019-08-16 05:16:03 -0500

I'm having problems compiling a simple ROS service. I'm using a fresh install of Ubuntu 18.04.3 - ROS Melodic. Ive simplified down the project as much as I can to replicate the problem.

My project structure is as follows

src/
    control_bridge/
        src/
            control_service.cpp
        srv/
            set_demand.srv
        CMakeLists.txt
        package.xml

My file content is as follows:

control_service.cpp:

#include "ros/ros.h"
#include "std_msgs/Float32.h"


bool set_demand(std_msgs::Float32 &request,std_msgs::Float32 &response)
{
    return true;
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "control_service");

  ros::NodeHandle nh;
  ros::ServiceServer service;
  service = nh.advertiseService("set_demand",set_demand);

  ros::spin();

  return 0;
}

set_demand.srv

float32 request
---
float32 response

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(control_bridge)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  genmsg
  std_msgs
)

## Generate services in the 'srv' folder
 add_service_files(
   FILES
   set_demand.srv
 )

## Generate added messages and services with any dependencies listed here
 generate_messages(
    DEPENDENCIES
    std_msgs  # Or other packages containing msgs
 )

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES control_bridge
  CATKIN_DEPENDS roscpp std_msgs message_runtime
#  DEPENDS system_lib
)

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

add_executable(ControlService src/control_service.cpp)

add_dependencies(ControlService control_bridge_generate_messages_cpp)

## Specify libraries to link a library or executable target against
 target_link_libraries(ControlService
   ${catkin_LIBRARIES}
 )

package.xml

<?xml version="1.0"?>
<package format="2">
  <name>control_bridge</name>
  <version>0.1.0</version>
  <description>The control_bridge package</description>
  <maintainer email="steve@todo.todo">steve</maintainer>
  <license>Apache 2.0</license>

  <build_depend>message_generation</build_depend>
  <build_export_depend>message_generation</build_export_depend>

  <exec_depend>message_runtime</exec_depend>
  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>std_msgs</build_depend>
  <exec_depend>std_msgs</exec_depend>

  <build_export_depend>roscpp</build_export_depend>
  <exec_depend>roscpp</exec_depend>

  <export>
  </export>
</package>

When running catkin_make I get the following error:

[ 88%] Building CXX object control_bridge/CMakeFiles/ControlService.dir/src/control_service.cpp.o
[ 88%] Built target control_bridge_generate_messages
In file included from /opt/ros/melodic/include/ros/service_client.h:33:0,
                 from /opt/ros/melodic/include/ros/node_handle.h:35,
                 from /opt/ros/melodic/include/ros/ros.h:45,
                 from /home/steve/track-o-motor-controller/track-o_ros_bridge/src/control_bridge/src/control_service.cpp:1:
/opt/ros/melodic/include/ros/service_traits.h: In instantiation of ‘static const char* ros::service_traits::MD5Sum<M>::value() [with M = std_msgs::Float32_<std::allocator<void> >]’:
/opt/ros/melodic/include/ros/service_traits.h:79:102:   required from ‘const char* ros::service_traits::md5sum() [with M = std_msgs::Float32_<std::allocator<void> >]’
/opt/ros/melodic/include/ros/advertise_service_options.h:60:25:   required from ‘void ros::AdvertiseServiceOptions::init(const string&, const boost::function<bool(MReq&, MRes&)>&) [with MReq = std_msgs::Float32_<std::allocator<void> >; MRes = std_msgs::Float32_<std::allocator<void> >; std::__cxx11::string = std::__cxx11::basic_string<char>]’
/opt/ros/melodic/include/ros/node_handle.h:1064:5:   required from ‘ros::ServiceServer ros::NodeHandle::advertiseService(const string&, bool (*)(MReq&, MRes&)) [with MReq = std_msgs::Float32_<std::allocator<void> >; MRes = std_msgs::Float32_<std::allocator<void> >; std::__cxx11::string = std::__cxx11::basic_string<char>]’
/home/steve/track-o-motor-controller/track-o_ros_bridge/src/control_bridge/src/control_service.cpp:16:56:   required from here
/opt/ros/melodic/include/ros/service_traits.h:47:34: error: ‘__s_getServerMD5Sum’ is not a member of ‘std_msgs::Float32_<std::allocator<void> >’
     return M::__s_getServerMD5Sum().c_str();
            ~~~~~~~~~~~~~~~~~~~~~~^~
/opt/ros/melodic/include/ros/service_traits.h: In instantiation of ‘static const char* ros::service_traits::DataType<M>::value() [with M = std_msgs::Float32_<std::allocator<void> >]’:
/opt/ros/melodic ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-08-16 05:50:12 -0500

pavel92 gravatar image

updated 2019-08-16 06:07:58 -0500

First, you cannot use messages like that in the service callback. You need to use a defined srv in the call. From what I can see your service should pass a std_msgs::Float32 value as request and after some processing return a std_msgs::Float32 of the same type as responce. Since this is not a standard service you will need to implement your own service.

Your set_demand srv definition should look like this:

float32 x
---
float32 y

Also note that you will need to specify what the request and response are in your service callback. You need to have the ::Request and ::Response appended to your srv (std_msgs::Float32) type:

bool set_demand(control_bridge::set_demand::Request &request,control_bridge::set_demand::Response &response)
{
    // processing logic goes here
    // you can use here the request/response like this: request.x  response.y
    return true;
}

The msg/srv generation and creating a service server/client tutorials provide enough info on how to do this.

edit flag offensive delete link more

Comments

also you will need to add message_generation in find_package your CMakeLists.txt

pavel92 gravatar imagepavel92 ( 2019-08-16 06:10:11 -0500 )edit

Ah yes thank you! I added the the include #include "control_bridge/set_demand.h" and changed the set_demand arguments as described and compiles great now.

As far as I know "genmsg" and "message_generation" under find_package are equivalent although not 100% on that.

SteveWithers gravatar imageSteveWithers ( 2019-08-16 06:40:43 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-08-14 11:26:42 -0500

Seen: 54 times

Last updated: Aug 16