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

Using custom msg in custom srv

asked 2018-07-03 08:36:23 -0500

bhmth gravatar image

updated 2018-10-26 11:57:40 -0500

lucasw gravatar image

Hi,

i have a msg package with a custom message like this:

MyStruct.msg
...
/* Content of MyStruct*/
HeaderStruct header
DataStruct data

using this msg type in different Nodes

Now i want to implement a srv using MyStruct.msg I modified my CmakeLists.txt of my service package with:

find_package(my_msgs REQUIRED)

and added to the package.xml

 <build_depend>my_msgs</build_depend>
 <exec_depend>my_msgs</exec_depend>

In the srv file i added

my_msgs/MyStruct data
---
float64 result
int64 calculation_time

but when building i always get the error

AttributeError: 'ServiceSpecification' object has no attribute 'base_type'

as soon as switching to this

float64 data
---
float64 result
int64 calculation_time

it works ... am i missing something ? Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2018-07-03 23:19:02 -0500

marguedas gravatar image

updated 2018-07-04 10:32:45 -0500

My guess is that you are missing the dependency in the rosidl_generate_interfaces call.

it should look like:

rosidl_generate_interfaces(<MY_MESSAGE_TARGET>
  "srv/MySrv.srv"
  DEPENDENCIES my_msgs
)

You can refer to sensor_msgs for an example,

HTH

Edit:

should definitely be mentioned here https://github.com/ros2/ros2/wiki/Abo...

I agree that this should be documented. Though, that wiki page is about the structure of the msg/srv files and doesn't make reference to the cmake code to generate them so I don't think this is the right place for it. A rosidl tutorial would be more appropriate. I started a draft at https://github.com/ros2/ros2/wiki/Ros... but didnt get to finishing it and submitting the corresponding code yet.

edit flag offensive delete link more

Comments

That was the deal. Thank you very much ! should definitely be mentioned here

https://github.com/ros2/ros2/wiki/About-ROS-Interfaces

bhmth gravatar image bhmth  ( 2018-07-04 02:50:52 -0500 )edit
1

If this answer solves your problem, please mark it as accepted (using the checkmark) so that community members know the question has been answered successfully

marguedas gravatar image marguedas  ( 2018-07-04 10:28:22 -0500 )edit

@bhmth the page you referenced in your comment is a publically editable wiki. Please feel free to contribute to it by adding additional information where you think it would be helpful.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-07-05 08:52:49 -0500 )edit

Misspelling a type in a srv like int64 produces an error like rosidl_parser.InvalidResourceName: int364, misspelling std_msgs/Header results in the AttributeError, but look a few lines below for the fatal error: std_msg/msg/header__struct.h: No such file or directory (std_msg -> std_msgs)

lucasw gravatar image lucasw  ( 2018-10-26 11:40:59 -0500 )edit

Making same error in a .msg produces more helfpul message like 'Message interface ... contains an unknown field type: std_msg/Header header' (both of these are for bouncy)

lucasw gravatar image lucasw  ( 2018-10-26 11:42:16 -0500 )edit

In Ubuntu a 'Crash report' dialog pops up for every failed build with this type of error 'Sorry, the application rosidl_generator_c has stopped unexpectedly'.

lucasw gravatar image lucasw  ( 2018-10-26 11:47:40 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2018-07-03 08:36:23 -0500

Seen: 2,537 times

Last updated: Oct 26 '18