Ask Your Question

Python cannot import geometrical Point array

asked 2022-03-23 02:37:56 -0500

shiraz_baig gravatar image

I am trying to publish an array of geometrical Points (each point having x,y,z) from a python script. I am using ros melodic, ubuntu 18.04 and python 2.7.17 Here is my msg file in the msg folder of the package.:
-------mymesg.msg ---------
geometry_msgs/Point[] points
I used message_generation and message_runtime in CMakeLists.txt and package.xml, then did catkin_make to compile the messages. It verifies generation of message.
$ rosmsg show mypkg/mymesg.msg
geometry_msgs/Point[] points
float64 x
float64 y
float64 z

Now I try to run the script for publishing. The imports in my script are:
from std_msgs.msg import Float64MultiArray
from geometry_msgs.msg import Point
from mypkg.msg import points     #line no 8 in my script

When I run the script. I get following error.
----------- error -------
Traceback (most recent call last):
File "", line 8, in <module>
from mypkg.msg import points
ImportError: cannot import name points

What is it that I am doing wrong that it is not importing the array.

edit retag flag offensive close merge delete


Thanks mike. I can see my error now. I stand corrected

shiraz_baig gravatar image shiraz_baig  ( 2022-04-02 20:54:24 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2022-04-01 22:05:56 -0500

shiraz_baig gravatar image

I think I found an answer. I need an independent package for it. It cannot co-exist with another msg folder or srv folder. When I created a new package and created the msg folder and file. It worked and I was able to publish and subscribe to Point[]. I also found another solution that is to use "geometry_msgs/Posearr" message. But in that case orientation has to be wasted out.

Could anyone tell me, if my understanding is correct?

edit flag offensive delete link more



No, you are not correct that a message must be in an independent package (but it is often a good idea for a different reason.) Your original error is that you imported the wrong name. Your message is named "mymesg", so that is the class that should be imported. You should not import the name of a field inside your message ("points").

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-04-02 10:02:44 -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



Asked: 2022-03-23 02:37:56 -0500

Seen: 108 times

Last updated: Apr 01