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

Can custom messages be located within a package?

asked 2018-10-21 14:35:01 -0500

jburns gravatar image

updated 2018-10-21 14:38:56 -0500

I am attempting to use a custom message inside of a publisher. Currently they exist in the same package. The python file in src/ and the message in msg/. It seems like in most examples, people do not put them in the same package. It also seems like msg/ is stored at the workspace level.

I am having trouble importing the message from a python file in the same package as the message.

Please let me know what the convention is around this topic, and if you have any suggestions as to why the import statement is not working.

(CMakeLists.txt and package.xml of the package are fine)

Thank you,

edit: rosmsg show package_name/msg_name works

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-03-04 05:27:31 -0500

I ran into the same problem. Turns out it is very simple to use your custom message within the same package: Your custom message gets imported by default, so do not attempt to import it yourself.

Import custom message that you defined in another package:

from package_name_with_message_definition.msg import my_custom_message

Import custom message that you defined in the very same package:

don't attempt to import the message. it is already available by default.

edit flag offensive delete link more

Comments

Unless something has changed recently, this doesn't seem to agree with what I've observed in my packages with custom messages.

gvdhoorn gravatar image gvdhoorn  ( 2022-03-05 01:39:12 -0500 )edit

You are right, @gvdhoorn. I was mistaken, my answer didn't work for me either. Although I don't remember how I did it, but in the end I got it working somehow :D

phil_rudd69 gravatar image phil_rudd69  ( 2022-05-12 09:43:27 -0500 )edit
0

answered 2018-10-21 16:01:29 -0500

gvdhoorn gravatar image

Currently they exist in the same package. The python file in src/ and the message in msg/. It seems like in most examples, people do not put them in the same package.

Examples maybe, but in reality this is not necessarily always the case. I know plenty packages that ship msgs (and srvs and actions) in the same package in which they are used.

It also seems like msg/ is stored at the workspace level.

This seems very strange to me. I've never seen that and it would also not work.

I am having trouble importing the message from a python file in the same package as the message.

Please let me know what the convention is around this topic, and if you have any suggestions as to why the import statement is not working.

(CMakeLists.txt and package.xml of the package are fine)

So something isn't working for you, but you have already concluded that your build script and package manifest are correct.

In reality in most cases the issue is with those two, especially when dealing with messages, so it would be a good idea to show us:

  1. your CMakeLists.txt and package.xml, and
  2. the actualy error you see when trying to import your msgs, because right now you only tell us that "it is not working", which is not enough for anyone to figure out what is going wrong
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-10-21 14:35:01 -0500

Seen: 994 times

Last updated: Mar 04 '22