Skip to content

Commit

Permalink
Port the pcap replay to ros2-foxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Samahu committed Aug 7, 2024
1 parent f1f86bd commit 3b70943
Show file tree
Hide file tree
Showing 3 changed files with 467 additions and 10 deletions.
46 changes: 36 additions & 10 deletions ouster-ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ endif()
option(CMAKE_POSITION_INDEPENDENT_CODE "Build position independent code." ON)

set(_ouster_ros_INCLUDE_DIRS
include
ouster-sdk/ouster_client/include
ouster-sdk/ouster_client/include/optional-lite
"include;ouster-sdk/ouster_client/include;ouster-sdk/ouster_client/include/optional-lite"
"include;"
"ouster-sdk/ouster_client/include;"
"ouster-sdk/ouster_client/include/optional-lite;"
"ouster-sdk/ouster_pcap/include"
)

# ==== Libraries ====
Expand All @@ -55,6 +57,11 @@ include_directories(${_ouster_ros_INCLUDE_DIRS})
# use only MPL-licensed parts of eigen
add_definitions(-DEIGEN_MPL2_ONLY)

set(OUSTER_TARGET_LINKS ouster_client)
if (BUILD_PCAP)
list(APPEND OUSTER_TARGET_LINKS ouster_pcap)
endif()

add_library(ouster_ros_library SHARED
src/os_ros.cpp
)
Expand All @@ -78,7 +85,7 @@ target_link_libraries(ouster_ros_library
ouster_build
pcl_common
# PRIVATE (unsupported)
-Wl,--whole-archive ouster_client -Wl,--no-whole-archive
-Wl,--whole-archive ${OUSTER_TARGET_LINKS} -Wl,--no-whole-archive
)

# helper method to construct ouster-ros components
Expand Down Expand Up @@ -165,6 +172,18 @@ rclcpp_components_register_node(os_driver_component
)


if (BUILD_PCAP)
# ==== os_replay_component ====
create_ros2_component(os_pcap_component
"src/os_sensor_node_base.cpp;src/os_pcap_node.cpp"
""
)
rclcpp_components_register_node(os_pcap_component
PLUGIN "ouster_ros::OusterPcap"
EXECUTABLE os_pcap
)
endif()

# ==== Test ====
if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
Expand All @@ -191,14 +210,21 @@ endif()


# ==== Install ====
set(OUSTER_INSTALL_TARGETS
ouster_ros_library
os_sensor_component
os_replay_component
os_cloud_component
os_image_component
os_driver_component
)
if (BUILD_PCAP)
list(APPEND OUSTER_INSTALL_TARGETS os_pcap_component)
endif()

install(
TARGETS
ouster_ros_library
os_sensor_component
os_replay_component
os_cloud_component
os_image_component
os_driver_component
${OUSTER_INSTALL_TARGETS}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
Expand Down
84 changes: 84 additions & 0 deletions ouster-ros/launch/replay_pcap.launch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<launch>

<arg name="ouster_ns" default="ouster"
description="Override the default namespace of all ouster nodes"/>
<!-- TODO: revisit the proper behaviour of allowing users override the default timestamp_mode during replay -->
<arg name="timestamp_mode" default=""
description="method used to timestamp measurements; possible values: {
TIME_FROM_INTERNAL_OSC,
TIME_FROM_SYNC_PULSE_IN,
TIME_FROM_PTP_1588,
TIME_FROM_ROS_TIME
}"/>
<arg name="ptp_utc_tai_offset" default="-37.0"
description="UTC/TAI offset in seconds to apply when using TIME_FROM_PTP_1588"/>
<arg name="metadata" description="path to write metadata file when receiving sensor data"/>
<arg name="pcap_file" description="file name to use for the recorded bag file"/>
<arg name="viz" default="true"
description="whether to run a rviz"/>
<arg name="rviz_config" default="$(find-pkg-share ouster_ros)/config/viz-reliable.rviz"
description="optional rviz config file"/>

<arg name="sensor_frame" default="os_sensor"
description="sets name of choice for the sensor_frame tf frame, value can not be empty"/>
<arg name="lidar_frame" default="os_lidar"
description="sets name of choice for the os_lidar tf frame, value can not be empty"/>
<arg name="imu_frame" default="os_imu"
description="sets name of choice for the os_imu tf frame, value can not be empty"/>
<arg name="point_cloud_frame" default=""
description="which frame to be used when publishing PointCloud2 or LaserScan messages.
Choose between the value of sensor_frame or lidar_frame, leaving this value empty
would set lidar_frame to be the frame used when publishing these messages."/>

<let name="_use_metadata_file" value="$(eval '\'$(var metadata)\' != \'\'')"/>

<arg name="use_system_default_qos" default="true"
description="Use the default system QoS settings"/>

<arg name="proc_mask" default="IMG|PCL|IMU|SCAN" description="
The IMG flag here is not supported and does not affect anything,
to disable image topics you would need to omit the os_image node
from the launch file"/>

<arg name="scan_ring" default="0" description="
use this parameter in conjunction with the SCAN flag
and choose a value the range [0, sensor_beams_count)"/>

<group>
<push-ros-namespace namespace="$(var ouster_ns)"/>
<node if="$(var _use_metadata_file)" pkg="ouster_ros" exec="os_pcap" name="os_pcap" output="screen">
<param name="metadata" value="$(var metadata)"/>
<param name="pcap_file" value="$(var pcap_file)"/>
<param name="use_system_default_qos" value="$(var use_system_default_qos)"/>
</node>
<node pkg="ouster_ros" exec="os_cloud" name="os_cloud" output="screen">
<param name="sensor_frame" value="$(var sensor_frame)"/>
<param name="lidar_frame" value="$(var lidar_frame)"/>
<param name="imu_frame" value="$(var imu_frame)"/>
<param name="point_cloud_frame" value="$(var point_cloud_frame)"/>
<param name="timestamp_mode" value="$(var timestamp_mode)"/>
<param name="ptp_utc_tai_offset" value="$(var ptp_utc_tai_offset)"/>
<param name="use_system_default_qos" value="$(var use_system_default_qos)"/>
<param name="proc_mask" value="$(var proc_mask)"/>
<param name="scan_ring" value="$(var scan_ring)"/>
</node>
<node pkg="ouster_ros" exec="os_image" name="os_image" output="screen">
<param name="use_system_default_qos" value="$(var use_system_default_qos)"/>
</node>
</group>

<!-- HACK: configure and activate the replay node via a process execute since state
transition is currently not availabe through launch.xml format -->
<executable if="$(var _use_metadata_file)"
cmd="$(find-exec ros2) lifecycle set /$(var ouster_ns)/os_pcap configure"
launch-prefix="bash -c 'sleep 0; $0 $@'" output="screen"/>
<executable if="$(var _use_metadata_file)"
cmd="$(find-exec ros2) lifecycle set /$(var ouster_ns)/os_pcap activate"
launch-prefix="bash -c 'sleep 1; $0 $@'" output="screen"/>

<include if="$(var viz)" file="$(find-pkg-share ouster_ros)/launch/rviz.launch.xml">
<arg name="ouster_ns" value="$(var ouster_ns)"/>
<arg name="rviz_config" value="$(var rviz_config)"/>
</include>

</launch>
Loading

0 comments on commit 3b70943

Please sign in to comment.