Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a ring field to the published pointcloud #431

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions carla_ros_bridge/src/carla_ros_bridge/lidar.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,38 @@ def sensor_data_updated(self, carla_lidar_measurement):
PointField('y', 4, PointField.FLOAT32, 1),
PointField('z', 8, PointField.FLOAT32, 1),
PointField('intensity', 12, PointField.FLOAT32, 1),
PointField('ring', 16, PointField.UINT16, 1)
]

lidar_data = numpy.fromstring(
bytes(carla_lidar_measurement.raw_data), dtype=numpy.float32)
lidar_data = numpy.reshape(
lidar_data, (int(lidar_data.shape[0] / 4), 4))

channels = float(self.carla_actor.attributes.get('channels'))
lower_fov = float(self.carla_actor.attributes.get('lower_fov'))
upper_fov = float(self.carla_actor.attributes.get('upper_fov'))

norm = numpy.linalg.norm(lidar_data[:, :3], 2, axis=1)
pitch = numpy.arcsin(lidar_data[:, 2] / norm)

fov_down = lower_fov / 180.0 * numpy.pi
fov = (abs(lower_fov) + abs(upper_fov)) / 180.0 * numpy.pi

ring = (pitch + abs(fov_down)) / fov
ring *= channels
ring = numpy.floor(ring)
ring = numpy.minimum(channels - 1, ring)
ring = numpy.maximum(0, ring).astype(numpy.uint16)
ring = ring.reshape(-1, 1)

# we take the oposite of y axis
# (as lidar point are express in left handed coordinate system, and ros need right handed)
lidar_data[:, 1] *= -1

lidar_data = lidar_data.tolist()
[lidar_data[i].insert(4, *ring[i]) for i in range(len(lidar_data))]

point_cloud_msg = create_cloud(header, fields, lidar_data)
self.lidar_publisher.publish(point_cloud_msg)

Expand Down