I cant import sensor_msgs.point_cloud2
I am trying to read the data from a pointcloud2 on ros2 foxy. I am successfully subscribing to a topic containing pointcloud2 data, but I cant import sensormsgs.pointcloud2 to use the method read_points. I just need to read the data to filter out the points that are not white. I only want the point cloud to contain white points.
when I try to import sensormsgs.pointcloud2 it give me this error "Import "sensormsgspy.point_cloud2" could not be resolved Pylance (reportMissingImports)"
Asked by joshuaG on 2023-01-15 13:19:18 UTC
Answers
Many headers and naming conventions has changed in ROS2(got snake-cased). I'm not sure about python, but when using C++ you'll probably want to use:
#include <sensor_msgs/msg/point_cloud2.hpp>
or
#include <sensor_msgs/point_cloud2_iterator.hpp>
I'm guessing that for python it'll be simliar(i.e sensor_msgs.msg.point_cloud2).
Hope this helps.
Asked by AibohphobiA on 2023-01-23 07:54:11 UTC
Comments
In 2020 it wasn't ported yet... https://answers.ros.org/question/357944/why-is-point_cloud2py-missing-from-sensor_msgs-in-ros2/ but it was supposed to have been finished that year. https://github.com/ros2/common_interfaces/pull/128
UPDATE:
use sensor_msgs_py. The following assume Ubuntu 20/ROS2 Foxy.
download with: sudo apt-get install ros-foxy-sensor-msgs-py
in your script:
from sensor_msgs.msg import PointCloud2 #used as the subscription message type
from sensor_msgs_py import point_cloud2 #used to read points
...
self.subscription = self.create_subscription( PointCloud2, 'topic', self.listener_callback, 10 )
...
xyz_points = list(point_cloud2.read_points(msg, field_names=('x','y','z')))
Asked by Hazel-rah on 2023-04-06 21:01:14 UTC
Comments