"""Publish first-hit clearing rays and measured hazards to Nav2 ObstacleLayer. Collision free space is not ground support or permission to drive. Those independent gates keep the existing observed terrain and semantic evidence. """ import math import struct import numpy as np from detector_exclusion import DetectorExclusion from geometry_msgs.msg import TransformStamped from rclpy.time import Time from sensor_msgs.msg import PointCloud2, PointField def cloud(stamp, frame, points): message = PointCloud2() message.header.stamp, message.header.frame_id = stamp, frame message.height, message.width = 1, len(points) message.fields = [PointField(name=name, offset=4*i, datatype=PointField.FLOAT32, count=1) for i, name in enumerate(('x','y','z'))] message.is_bigendian, message.is_dense = False, True message.point_step, message.row_step = 12, 12*len(points) message.data = b''.join(struct.pack(' .8: return False stamp = Time(nanoseconds=self.node.get_clock().now().nanoseconds-int(age*1e9)).to_msg() transforms=[] for i, origin in enumerate(rays['origins']): tf = TransformStamped() tf.header.frame_id, tf.child_frame_id, tf.header.stamp = 'map','range'+str(i),stamp tf.transform.translation.x, tf.transform.translation.y = map(float, origin[:2]) tf.transform.rotation.w = 1. transforms.append(tf) self.node.tf.sendTransform(transforms) for i, (publisher, origin) in enumerate(zip(self.rays, rays['origins'])): points=[[end[0]-origin[0],end[1]-origin[1]] for end, owner in zip(rays['ends'], rays['origin_indices']) if owner==i] publisher.publish(cloud(stamp,'range'+str(i),points)) # The body collision map contains physical/detector obstacles. Ground # permission and rejected support patches are search costs: treating # them as solid objects blocks an overhanging camera during BackUp/Spin. # Smac retains both; every native proposal still passes the separate # full ground-contact/semantic gates before reaching the actuator. hazards = terrain[terrain[:,3]>self.max_step+1e-4,:2] search = search_terrain[search_terrain[:,3]>self.max_step+1e-4,:2] reserve = self.detector_exclusion.points(detected, request['pose']) self.hazards.publish(cloud(stamp,'map',np.concatenate((hazards,reserve)))) self.search.publish(cloud(stamp,'map',np.concatenate((search,reserve)))) return True