Skip to content

Commit bbfb1b4

Browse files
committed
add pointcloud base_reference_frame lookup
1 parent 04345e1 commit bbfb1b4

File tree

1 file changed

+17
-30
lines changed
  • formant_ros2_adapter/scripts

1 file changed

+17
-30
lines changed

formant_ros2_adapter/scripts/main.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@
145145
# Seconds
146146
SERVICE_CALL_TIMEOUT = 5
147147

148+
BASE_REFERENCE_FRAME = os.getenv("FORMANT_BASE_REFERENCE_FRAME","base_link")
149+
148150

149151
class ROS2Adapter:
150152
"""
@@ -1041,45 +1043,30 @@ def handle_ros2_message(self, msg, subscriber_config):
10411043
timestamp=msg_timestamp,
10421044
)
10431045

1044-
elif msg_type == LaserScan:
1045-
# Convert LaserScan to a Formant pointcloud
1046+
elif msg_type == LaserScan or msg_type == PointCloud2:
10461047
try:
1047-
self.fclient.agent_stub.PostData(
1048-
Datapoint(
1049-
stream=formant_stream,
1050-
point_cloud=FPointCloud.from_ros_laserscan(
1051-
msg
1052-
).to_proto(),
1053-
tags=subscriber_config["tags"],
1054-
timestamp=msg_timestamp,
1055-
)
1056-
)
1057-
except grpc.RpcError as e:
1058-
return
1059-
except Exception as e:
1060-
print(
1061-
"ERROR: Could not ingest " + formant_stream + ": " + str(e)
1048+
formant_point_cloud = None
1049+
if msg_type == LaserScan:
1050+
formant_point_cloud = FPointCloud.from_ros_laserscan(
1051+
msg
1052+
)
1053+
if msg_type == PointCloud2:
1054+
formant_point_cloud = FPointCloud.from_ros(msg)
1055+
1056+
if formant_point_cloud is None:
1057+
raise Exception("%s not PointCloud2 or LaserScan" % msg_type)
1058+
1059+
formant_point_cloud.transform_to_world = self.lookup_transform(
1060+
msg, BASE_REFERENCE_FRAME
10621061
)
1063-
return
1064-
1065-
elif msg_type == PointCloud2:
1066-
try:
10671062
self.fclient.agent_stub.PostData(
10681063
Datapoint(
10691064
stream=formant_stream,
1070-
point_cloud=FPointCloud.from_ros(msg).to_proto(),
1065+
point_cloud=formant_point_cloud.to_proto(),
10711066
tags=subscriber_config["tags"],
10721067
timestamp=msg_timestamp,
10731068
)
10741069
)
1075-
except grpc.RpcError as e:
1076-
return
1077-
except Exception as e:
1078-
print(
1079-
"ERROR: Could not ingest " + formant_stream + ": " + str(e)
1080-
)
1081-
return
1082-
10831070
else:
10841071
# Ingest any messages without a direct mapping to a Formant type as JSON
10851072
self.fclient.post_json(

0 commit comments

Comments
 (0)