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

I cant import sensor_msgs.point_cloud2

asked 2023-01-15 12:19:18 -0500

joshuaG gravatar image

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 sensor_msgs.point_cloud2 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 sensor_msgs.point_cloud2 it give me this error "Import "sensor_msgs_py.point_cloud2" could not be resolved Pylance (reportMissingImports)"

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2023-01-23 06:54:11 -0500

AibohphobiA gravatar image

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.

edit flag offensive delete link more
0

answered 2023-04-06 21:32:52 -0500

Hazel-rah gravatar image

updated 2023-05-03 13:25:01 -0500

In 2020 it wasn't ported yet... https://answers.ros.org/question/3579... but it was supposed to have been finished that year. https://github.com/ros2/common_interf...

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')))

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2023-01-15 12:19:18 -0500

Seen: 1,279 times

Last updated: May 03 '23