11 __ROS_VERSION = os.getenv(
"ROS_VERSION")
12 if __ROS_VERSION
is not None:
13 __ROS_VERSION = int(__ROS_VERSION)
14 if __ROS_VERSION == 2:
16 from rclpy.node
import Node
17 from rclpy.qos
import QoSProfile
18 from rclpy.qos
import QoSReliabilityPolicy
19 from sensor_msgs.msg
import LaserScan
20 from sensor_msgs.msg
import PointCloud2, PointField
23 from sensor_msgs.msg
import LaserScan
24 from sensor_msgs.msg
import PointCloud2, PointField
30 def __init__(self, __ROS_VERSION, num_messages_decay):
33 super().
__init__(
"multiscan_laserscan_msg_to_pointcloud")
38 self.
cloud_publisher = self.create_publisher(PointCloud2,
"/laserscan_msg_cloud", 10)
41 self.
cloud_publisher = rospy.Publisher(
"/laserscan_msg_cloud", PointCloud2, queue_size=10)
43 "world_0": -22.71 * math.pi / 180,
44 "world_1": -17.56 * math.pi / 180,
45 "world_2": -12.48 * math.pi / 180,
46 "world_3": -7.51 * math.pi / 180,
47 "world_4": -2.49 * math.pi / 180,
48 "world_5": -0.07 * math.pi / 180,
49 "world_6": +2.43 * math.pi / 180,
50 "world_7": +7.29 * math.pi / 180,
51 "world_8": +12.79 * math.pi / 180,
52 "world_9": +17.28 * math.pi / 180,
53 "world_10": +21.94 * math.pi / 180,
54 "world_11": +26.73 * math.pi / 180,
55 "world_12": +31.86 * math.pi / 180,
56 "world_13": +33.42 * math.pi / 180,
57 "world_14": +37.18 * math.pi / 180,
58 "world_15": +42.79 * math.pi / 180
68 ros_pointcloud.header.seq = msg.header.seq
69 ros_pointcloud.header.stamp = msg.header.stamp
70 ros_pointcloud.header.frame_id =
"world"
71 ros_pointcloud.width = 0
73 ros_pointcloud.width = ros_pointcloud.width + len(scan_msg.ranges)
74 ros_pointcloud.height = 1
75 ros_pointcloud.is_bigendian =
False
76 ros_pointcloud.is_dense =
True
77 ros_pointcloud.fields = [
PointField(
"x", 0, PointField.FLOAT32, 1),
PointField(
"y", 4, PointField.FLOAT32, 1),
PointField(
"z", 8, PointField.FLOAT32, 1),
PointField(
"intensity", 12, PointField.FLOAT32, 1) ]
78 ros_pointcloud.point_step = 16
79 ros_pointcloud.row_step = ros_pointcloud.point_step * ros_pointcloud.width
81 cloud_data = np.zeros(4 * ros_pointcloud.width * ros_pointcloud.height, dtype=np.float32)
84 azimuth = scan_msg.angle_min
85 azimuth_inc = scan_msg.angle_increment
87 elevation_cos = math.cos(elevation)
88 elevation_sin = math.sin(elevation)
89 for point_idx, range
in enumerate(scan_msg.ranges):
90 cloud_data[4 * cloud_point_idx + 0] = range * elevation_cos * math.cos(azimuth)
91 cloud_data[4 * cloud_point_idx + 1] = range * elevation_cos * math.sin(azimuth)
92 cloud_data[4 * cloud_point_idx + 2] = range * elevation_sin
93 cloud_data[4 * cloud_point_idx + 3] = scan_msg.intensities[point_idx]
94 cloud_point_idx = cloud_point_idx + 1
95 azimuth = azimuth + azimuth_inc
96 ros_pointcloud.data = cloud_data.tostring()
102 num_messages_decay = 3 * 12 * 16
103 if __ROS_VERSION == 2:
106 rclpy.spin(subscriber)
110 node = rospy.init_node(
"multiscan_laserscan_msg_to_pointcloud")
113 while not rospy.is_shutdown():
116 if __name__ ==
'__main__':