0
$\begingroup$

Rosanswers logo

Hi all, I've been on this for hours now and I can't figure it out. It seems as if not this forum or the tutorials have a solution for this simple question. I have downloaded the Vesc stack here, without the vesc_ackerman package. It all builds nicely with the addition of the serial library, and even connects to the device and publishes topics stated in vesc_msgs. You can rostopic echo them, you can rosmsg list them (VescState and VescStateStamped). Now, what I am trying to do is to use these messages in another package, so that I can manipulate it.

I have a standard python node code, but it starts with: #import rospy, then #import VescState.msg (or from VescState import XXX) , and continues on (If any1 can point me on how to paste the code here without having only the first line as code format and everything else outside, plus hash-tags making the font huge, i'de love that...). I could go on but it doesnt really matter, because all I get when I try to run the code is:

Traceback (most recent call last):
  File "/home/tim/catkin_ws/src/vesc_comm/src/vesc_comm.py", line 5, in <module>
    from VescState.msg import *
ImportError: No module named VescState.msg

I have tried every conceivable way of doing this. i have tried to rename the message files, adding them as native messages to my package, including all the package.xml and cmakelists.txt additions just to make a sanity check. tried catkin_make install. none of it worked.

I actually do not want to make these messages native anyway. what I do want is to get my vesc_comm.py script to recognize the VescState.msg file from the other package (again - the messages work with the vesc_driver node and are listed in rosmsg!).

Why can I use every single message offered by ROS (std, geometry, pointcloud2...) but get the error stated above when I try and use a custom message?? my ROS is just not recognizing it. what am I doing wrong?

Thanks in advance, Steve


Originally posted by StevenCoral on ROS Answers with karma: 167 on 2017-09-09

Post score: 1


Original comments

Comment by gvdhoorn on 2017-09-09:\

If any1 can point me on how to paste the code here

copy-paste code, select lines, press ctrl+k or click the Preformatted Code button (the one with 101010 on it).

Comment by StevenCoral on 2017-09-10:
Thank you! i was clicking the icon first and then tried to paste code instead of "enter code here". wasnt working.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

import rospy
import VescState.msg   # (or from VescState import XXX)

In rospy, the ROS package name is the module name, and the message filename is the classname. As a package can include both messages and services, either a msg or srv submodule needs to be added.

So the .msg is not the .msg extension of the filename, but a module.

For the package you link (vesc_msgs), the import statement should probably be:

from vesc_msgs.msg import VescState

or if you just want to import all messages:

from vesc_msgs.msg import *

It seems as if not this forum or the tutorials have a solution for this simple question

This is always difficult, but I have the impression (but I've obviously been doing this for so long that it's easy for me to find this) that most tutorials and example code shows examples of this.

See wiki/ROS/tutorials/Defining Custom Messages - Including or Importing Messages - Python fi.


Originally posted by gvdhoorn with karma: 86574 on 2017-09-09

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by StevenCoral on 2017-09-10:
Yeah, thas exactly what I thought! knowing python, it felt weird to use the .msg for the filename while periods indicate modules. therefore i completely understood the error message, just didnt know why it worked for std_msgs.msg (that file exists). thanks a lot! ill try this.

Comment by StevenCoral on 2017-09-10:
btw, also tried 'from vesc_msgs import VescState', didnt work. in my own corrupt way i worked around this issue by copying "_VescState.py" into my src folder and using 'from _vescState import VescState', that did the trick. Thanks again for the explanation as well!

Comment by gvdhoorn on 2017-09-10:
I'm a bit unsure what to make of your last comments. Just make sure to use the from package_name.msg import X approach. That should work. If it doesn't, something is wrong, but not with the import statement.

Comment by StevenCoral on 2017-09-10:
update: it works, thanks a lot. I was just mentioning the bad way I got it to work (using the actual python build files from the build directory), but I rather do it the right way (especially for future work).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.