ROS Lidar Translator Tutorial

This tutorial will show you how to build a basic ROS node that can take in custom PolySync messages in ROS, and republish them as native ROS types.

It also demonstrates how to include the message definition files generated from PolySync’s ROS bridge in a new ROS node project.

In order to start the tutorial, you will need the PolysyncLidarTranslator example.

1. Setup ROS workspace

To properly build this example with the generated PolySync messages in ROS, set up the catkin workspace with the ros_bridge.

If you do not have a catkin workspace already, follow these steps to create one.

1.1 Create a buildable package

Source the ROS environment and create a package in the src/ directory of the catkin workspace.

$ cd ~/catkin_ws/src
$ source /opt/ros/indigo/setup.bash
$ catkin_create_pkg polysync_lidar_translator std_msgs roscpp tf

Copy polysync_lidar_translator_node.cpp to the src directory of the polysync_lidar_translator package.

$ cd PolySync-Core-CPP-Examples/PolysyncLidarTranslator/
$ cp polysync_lidar_translator_node.cpp   ~/catkin_ws/src/polysync_lidar_translator/src/

Ensure the Build section of the CMakeLists.txt file matches the following.

## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
  ${catkin_INCLUDE_DIRS}
  "~/catkin_ws/ros_bridge/include"
)

## Declare a C++ executable
add_executable(polysync_lidar_translator_node src/polysync_lidar_translator_node.cpp)

## Add cmake target dependencies of the executable
## same as for the library above
add_dependencies(polysync_lidar_translator_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
target_link_libraries(polysync_lidar_translator_node
   ${catkin_LIBRARIES}
 )

1.2 Generate the ROS bridge

Generate the ros_bridge files and copy the ros_bridge project to the root directory of the catkin workspace.

$ cd ~/catkin_ws/src
$ pdm-gen -c -r /usr/local/polysync/modules/sensor/sensor.idl /usr/local/polysync/modules/navigation/navigation.idl /usr/local/polysync/modules/control/control.idl /usr/local/polysync/modules/dtc/dtc.idl
$ mv pdm/ros_bridge ../
$ rm -rf pdm

2. Build and run the example

Source the ros_bridge, and run catkin_make in the root directory of the catkin workspace.

$ cd ~/catkin_ws
$ source ros_bridge/setup.bash
$ catkin_make

Run the ROS bridge node after sourcing the environment.

$ source ros_bridge/setup.bash
$ cd ~/catkin_ws/ros_bridge/share/polysync_ros_bridge
$ ./BridgeNode -t ps_lidar_points_msg

The bridge accepts high level message types as command line arguments. These are translated to ROS topics by the ros_bridge node.

3. Visualize data

To visualize data from the bridge, start the PolySync runtime in hardware or replay modes, or use the data generator to publish sample data to the Core bus.

In a new terminal download, build, and start the data generator.

$ git clone git@github.com:PolySync/PolySync-Core-C-Examples.git
$ cd PolySync-Core-C-Examples/data_generator
$ sudo apt-get install libglib2.0-dev  # this is required for this example to build, documented in the examples README.md file
$ make
$ ./bin/polysync-data-generator-c

Run the translator project. The executable should be in the devel folder of the catkin workspace.

$ cd ~/catkin_ws/devel/lib/polysync_lidar_translator
$ ./polysync_lidar_translator_node

Open rviz to visualize the data with ROS nodes.

$ rosrun rviz rviz
  • Select Global Options
  • Under Fixed Frame, select world
  • Click Add, and create a new PointCloud2 visualization object
    • Select /polysync/lidar_points as the topic
    • Change this style to Points for a more realistic point cloud

4. The translated data

Each PointCloud2 message contains the source GUID of the driver sending the ps_lidar_points_msg in the frame_id field. This is used to differentiate the incoming sources of data.

Similarly, the PolySync timestamp is copied to the native PointCloud2 messages.

The transform for each incoming message of a particular GUID can be manually modified to match what is in the PolySync SDF. This allows simple sensor translation so that the data is relative to the vehicle’s frame.

5. Next steps

This application could be adapted to republish ps_radar_targets_msg to PointCloud2, allowing you to use all RADAR drivers from PolySync Core with ROS.