Skip to content

Commit 0681c08

Browse files
author
rorosi
committed
Add TimeStamp xavier and local
1 parent e084473 commit 0681c08

15 files changed

Lines changed: 644 additions & 411 deletions

CHANGELOG.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
Changelog for package clpe_ros
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
0.1.1 (2022-08-24)
6+
------------------
7+
* remove EEPROM
8+
59
0.1.0 (2022-04-20)
610
------------------
7-
* Provides ROS 1 Noetic driver for CANLAB CLPE-G-NVP2650D vision system
11+
* Provides ROS 2 driver for CANLAB CLPE-G-NVP2650D vision system
12+
* Support ROS 2 Foxy and ROS 2 Galactic
813
* By default the driver will publish three topics for each camera X.
9-
* /clpe_ros/cam_X/image_raw: The raw image published as sensor_msgs::msg::Image. The default encoding is yuv422. For other supported encodings, see Configuration.
10-
* /clpe_ros/cam_X/camera_info: The intrinsics of the camera published as a sensor_msgs::msg::CameraInfo message.
11-
* /clpe_ros/cam_X/clpe_camera_info: The intrinsics of the camera published as a clpe_ros_msgs::ClpeCameraInfo message.
12-
* Contributors: Teo Koon Peng, Yadunund Vijay
14+
* /clpe/cam_X/image_raw: The raw image published as sensor_msgs::msg::Image. The default encoding is yuv422. For other supported encodings, see Configuration.
15+
* /clpe/cam_X/camera_info: The intrinsics of the camera published as a sensor_msgs::msg::CameraInfo message.
16+
* /clpe/cam_X/clpe_camera_info: The intrinsics of the camera published as a clpe_ros_msgs::msg::ClpeCameraInfo message.
17+
* Contributors: Teo Koon Peng, Yadunund Vijay

CMakeLists.txt

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,88 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
55
add_compile_options(-Wall -Wextra -Wpedantic)
66
endif()
77

8-
find_package(catkin REQUIRED)
8+
find_package(ament_cmake REQUIRED)
99
find_package(clpe REQUIRED)
10-
find_package(roscpp REQUIRED)
10+
find_package(rclcpp REQUIRED)
1111
find_package(image_transport REQUIRED)
1212
find_package(geometry_msgs REQUIRED)
1313
find_package(sensor_msgs REQUIRED)
1414
find_package(cv_bridge REQUIRED)
1515
find_package(tf2 REQUIRED)
1616
find_package(clpe_ros_msgs REQUIRED)
1717

18-
catkin_package(DEPENDS roscpp image_transport clpe_ros_msgs)
19-
2018
add_library(${PROJECT_NAME}_lib INTERFACE)
2119
target_include_directories(${PROJECT_NAME}_lib INTERFACE
22-
${roscpp_INCLUDE_DIRS}
2320
${geometry_msgs_INCLUDE_DIRS}
2421
${sensor_msgs_INCLUDE_DIRS}
2522
${image_transport_INCLUDE_DIRS}
2623
${cv_bridge_INCLUDE_DIRS}
2724
${clpe_ros_msgs_INCLUDE_DIRS}
2825
)
2926
target_link_libraries(${PROJECT_NAME}_lib INTERFACE
30-
clpe
31-
${roscpp_LIBRARIES}
27+
clpe::clpe
28+
rclcpp::rclcpp
3229
${geometry_msgs_LIBRARIES}
3330
${sensor_msgs_LIBRARIES}
3431
${image_transport_LIBRARIES}
3532
${cv_bridge_LIBRARIES}
3633
${clpe_ros_msgs_LIBRARIES}
3734
)
3835
target_compile_features(${PROJECT_NAME}_lib INTERFACE cxx_std_14)
39-
4036
add_executable(${PROJECT_NAME}
4137
src/main.cpp)
4238
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib)
4339
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION lib/${PROJECT_NAME})
4440

45-
install(DIRECTORY launch
46-
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
47-
PATTERN "*~" EXCLUDE)
48-
install(DIRECTORY config
49-
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
50-
PATTERN "*~" EXCLUDE)
41+
###############################################################################
42+
# ROS2 component
43+
###############################################################################
44+
45+
include(GenerateExportHeader)
46+
find_package(rclcpp_components REQUIRED)
47+
48+
# Create shared library
49+
add_library(${PROJECT_NAME}_component SHARED
50+
src/component.cpp)
51+
target_compile_definitions(${PROJECT_NAME}_component
52+
PRIVATE "COMPOSITION_BUILDING_DLL")
53+
target_include_directories(${PROJECT_NAME}_component PRIVATE
54+
${CMAKE_CURRENT_BINARY_DIR}
55+
${rclcpp_components_INCLUDE_DIRS})
56+
target_link_libraries(${PROJECT_NAME}_component
57+
${PROJECT_NAME}_lib
58+
${rclcpp_components_LIBRARIES})
59+
set_target_properties(${PROJECT_NAME}_component PROPERTIES
60+
CXX_VISIBILITY_PRESET hidden
61+
VISIBILITY_INLINES_HIDDEN ON)
62+
63+
# Generate export headers
64+
GENERATE_EXPORT_HEADER(${PROJECT_NAME}_component)
65+
66+
# register component
67+
rclcpp_components_register_nodes(${PROJECT_NAME}_component "clpe::ClpeComponentNode")
68+
set(node_plugins "${node_plugins}clpe::ClpeComponentNode;$<TARGET_FILE:${PROJECT_NAME}_component>\n")
69+
file(GENERATE
70+
OUTPUT
71+
"${CMAKE_CURRENT_BINARY_DIR}/test_ament_index/$<CONFIG>/share/ament_index/resource_index/node_plugin/${PROJECT_NAME}"
72+
CONTENT "${node_plugins}")
73+
74+
# install target
75+
install(TARGETS ${PROJECT_NAME}_component)
76+
77+
###############################################################################
5178

5279
option(CLPE_ROS_BUILD_BENCHMARKS "build benchmarks")
5380
if (${CLPE_ROS_BUILD_BENCHMARKS})
5481
add_subdirectory(benchmarks)
5582
endif()
83+
84+
install(
85+
DIRECTORY launch
86+
DESTINATION share/${PROJECT_NAME})
87+
88+
install(
89+
FILES fastdds.xml
90+
DESTINATION share/${PROJECT_NAME})
91+
92+
ament_package()

README.md

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,86 +4,121 @@ This repository contains ROS 1 and ROS 2 drivers for the CANLAB CLPE-G-NVP2650D
44
CLPE-G-NVP2650D is a multi camera grabber board for N2.0 GMSL camera.
55
This drivers exposes camera images and information from CLPE-G-NVP2650D as ROS messages using the image_transport framework.
66

7-
**This branch contains the `ROS 1` driver. For the `ROS 2` driver, please switch to the `main` branch.**
7+
**This branch contains the `ROS 2` driver. For the `ROS 1` driver, please switch to the `noetic` branch.**
88

99
# System Requirements
1010

1111
Requirements:
1212
* CANLAB CLPE-G-NVP2650D with supplied PC running [Ubuntu 20.04](https://releases.ubuntu.com/20.04/)
1313
* [CLPE_G_NVP2650D_SDK](https://github.com/canlab-co/CLPE_G_NVP2650D_SDK)
14-
* [ROS 1 Noetic](http://wiki.ros.org/noetic)
14+
* [ROS 2 Foxy](https://docs.ros.org/en/foxy/index.html) or [ROS 2 Galactic](https://docs.ros.org/en/galactic/index.html)
1515

16-
> Note: It is strongly recommended to install `Ubuntu 20.04` on the PC shipped with CLPE-G-NVP2650D. This way ROS 1 binaries can be [installed as debian packages](http://wiki.ros.org/noetic/Installation/Ubuntu). If the PC is running `Ubuntu 18.04`, ROS 1 will need to be [built from source](http://wiki.ros.org/noetic/Installation/Source) which is not officially supported on `Ubuntu 18.04`.
16+
> Note: It is strongly recommended to install `Ubuntu 20.04` on the PC shipped with CLPE-G-NVP2650D. This way ROS 2 binaries can be [installed as debian packages](https://docs.ros.org/en/foxy/Installation/Ubuntu-Install-Debians.html). If the PC is running `Ubuntu 18.04`, ROS 2 will need to be [built from source](https://docs.ros.org/en/foxy/Installation/Ubuntu-Development-Setup.html) which is not officially supported on `Ubuntu 18.04`.
1717
Alternatively, containers or VM may be used but the CLPE-G-NVP2650D drivers has to be properly passed through.
1818

19+
1920
# Setup
2021

2122
## System dependencies
2223
```bash
2324
sudo apt update && sudo apt install git cmake wget gcc python3-colcon* python3-rosdep python3-vcstool -y
2425
```
2526

26-
## ROS 1 Installation
27-
Depending on the version of Ubuntu installed, follow the instructions in the links above to install ROS 1 Noetic binaries or from source.
28-
To source ROS 1
27+
## ROS 2 Installation
28+
Depending on the version of Ubuntu installed, follow the instructions in the links above to install ROS 2 binaries or from source.
29+
To source ROS 2
2930
```bash
30-
source /opt/ros/noetic/setup.bash # if binaries are installed
31-
source ~/ros1_noetic/install/setup.bash # if installed from source following link above
31+
source /opt/ros/foxy/setup.bash # if binaries are installed
32+
source ~/ros2_foxy/install/setup.bash # if installed from source following link above
3233
```
34+
> Note: Replace `foxy` with `galactic` if using ROS 2 Galactic
3335
34-
## Install CLPE SDK and ROS 1 Driver
36+
## Install CLPE SDK and ROS 2 Driver
3537
Create workspace
3638
```bash
3739
mkdir -p ~/ws_clpe/src
3840
cd ~/ws_clpe/
39-
wget https://raw.githubusercontent.com/canlab-co/clpe_ros/noetic-AP0202/clpe.repos
41+
wget https://raw.githubusercontent.com/canlab-co/clpe_ros/main/clpe.repos
4042
vcs import src < clpe.repos
4143
```
4244

4345
Install dependencies
4446

4547
```bash
4648
cd ~/ws_clpe
49+
# source your ROS 2 workspace before this command
4750
sudo rosdep init # if you have not done this before
4851
rosdep update
49-
rosdep install --from-paths src --ignore-src --rosdistro noetic -y
52+
rosdep install --from-paths src --ignore-src --rosdistro $ROS_DISTRO -y
5053
```
54+
5155
Build the driver
5256

5357
```bash
5458
cd ~/ws_clpe
55-
# source your ROS 1 workspace if you have not already
56-
catkin_make install --cmake-args -DCMAKE_BUILD_TYPE=Release
59+
# source your ROS 2 workspace if you have not already
60+
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release
5761
# To also build the benchmarking scripts
58-
catkin_make install --cmake-args -DCMAKE_BUILD_TYPE=Release -DCLPE_ROS_BUILD_BENCHMARKS=On
62+
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release -DCLPE_ROS_BUILD_BENCHMARKS=On
5963
```
6064

6165
# Run the driver
6266

67+
## DDS Configuration
68+
For better image transport performance over DDS, we recommend using [FastDDS](https://github.com/eProsima/Fast-DDS) with Shared Memory Transport enabled.
69+
First copy the the `fastdds.xml` config file to a suitable directory, eg. `$HOME/fastdds.xml`
70+
```bash
71+
cd ~/ws_clpe/src
72+
cp canlab/fastdds.xml ~/
73+
```
74+
75+
Next add these two lines to your `~/.bashrc`
76+
```bash
77+
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
78+
export FASTRTPS_DEFAULT_PROFILES_FILE=$HOME/fastdds.xml
79+
```
80+
81+
Make sure to `source ~/.bashrc` first on all terminals before launching any ROS 2 nodes including the driver.
82+
83+
## Launch
84+
6385
```bash
6486
cd ~/ws_clpe
6587
source install/setup.bash
66-
roslaunch clpe_ros clpe_ros.launch password:=<sudo-password> encoding:=yuv422
88+
ros2 launch clpe_ros clpe_ros.launch.py password:=<sudo-password> encoding:=yuv422
6789
```
6890

69-
> Note: If `sudo-password` is a number, say `42`, you should pass it as `password:=\'42\'`
91+
> Note: If `sudo_password` is a number, say `42`, you should pass it as `password:=\'42\'`
92+
93+
By default the driver will publish three topics per camera X.
94+
* /clpe/cam_X/image_raw: The raw image published as `sensor_msgs::msg::Image`. The default encoding is `yuv422`. For other supported encodings, see Configuration below.
95+
* /clpe/cam_X/camera_info: The intrinsics of the camera published as a `sensor_msgs::msg::CameraInfo` message.
96+
* /clpe/cam_X/clpe_camera_info: The intrinsics of the camera published as a clpe_ros_msgs::msg::ClpeCameraInfo message.
7097

71-
By default the driver will publish two topics per camera (X).
72-
* /clpe_ros/cam_X/image_raw: The raw image published as `sensor_msgs::Image`. The default encoding is `yuv422`. For other supported encodings, see Configuration below.
7398

74-
## Visualizing in Rviz
99+
## ROS2 Component
75100

76-
By default, images are published in yuv encoding. Rviz does not support yuv so it needs to be converted to a different format.
101+
The driver is also supported as a ROS2 component. To run it, start the component container
77102

78103
```bash
79-
roslaunch clpe_ros clpe_ros.launch password:=<sudo-password> encoding:=bgr8
104+
ros2 run rclcpp_components component_container
80105
```
81106

82-
Note that this conversion incurs significant overhead so should be avoided if performance is important.
107+
In another terminal, load the component
108+
109+
```bash
110+
ros2 component load /ComponentManager clpe_ros clpe::ClpeComponentNode -p password:=<password>
111+
```
112+
113+
Check that the component is loaded with
114+
115+
```bash
116+
ros2 component list
117+
```
83118

84119
# Configuration
85120

86-
The driver supports the following ROS parameters to configure its behavior. The `password` and `encoding` parameters can be overwritten at run time. Other parameters can be modified within the [config file](config/clpe_config.yaml)
121+
The driver supports the following ROS parameters to configure its behavior. The `password` and `encoding` parameters can be overwritten at run time. Other parameters can be modified within the [launch file](launch/clpe_ros.launch.py).
87122

88123
| Key | Description | Default |
89124
|-|-|-|
@@ -92,9 +127,7 @@ The driver supports the following ROS parameters to configure its behavior. The
92127
| cam_{n}_enable | Enable camera | true |
93128
| cam_{n}_pose | Pose relative to the base, 6 values corresponding to [x, y, z, roll, pitch, yaw] | [0,0,0,0,0,0] |
94129
| cam_{n}_frame_id | Defines the frame_id all static transformations refers to | base_link |
95-
| cam_{n}_image_latch | Controls latching for camera image messages | false |
96-
| cam_{n}_image_queue_size | Controls queue size for camera image messages | 10 |
97-
| cam_{n}_info_latch | Controls latching for camera info messages | false |
98-
| cam_{n}_info_queue_size | Controls queue size for camera info messages | 10 |
130+
| cam_{n}_image_qos | Sets the QoS by which the topic is published. Available values are the following strings: SYSTEM_DEFAULT, PARAMETER_EVENTS, SERVICES_DEFAULT, PARAMETERS, DEFAULT, SENSOR_DATA, HID_DEFAULT (= DEFAULT with depth of 100), EXTRINSICS_DEFAULT (= DEFAULT with depth of 1 and transient local durabilty). | SENSOR_DATA |
131+
| cam_{n}_info_qos | Sets the QoS by which the topic is published. Available values are the following strings: SYSTEM_DEFAULT, PARAMETER_EVENTS, SERVICES_DEFAULT, PARAMETERS, DEFAULT, SENSOR_DATA, HID_DEFAULT (= DEFAULT with depth of 100), EXTRINSICS_DEFAULT (= DEFAULT with depth of 1 and transient local durabilty). | SYSTEM_DEFAULT |
99132

100133
Unless specified otherwise, all parameters are read-only, that is, they must be initialized at startup and cannot be changed at runtime.

benchmarks/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
add_executable(latency latency.cpp)
2-
target_include_directories(latency PRIVATE ${roscpp_INCLUDE_DIRS} ${sensor_msgs_INCLUDE_DIRS})
3-
target_link_libraries(latency PRIVATE ${roscpp_LIBRARIES} ${sensor_msgs_LIBRARIES})
2+
target_include_directories(latency PRIVATE ${sensor_msgs_INCLUDE_DIRS})
3+
target_link_libraries(latency PRIVATE rclcpp::rclcpp ${sensor_msgs_LIBRARIES})
44
# always build in release mode
55
separate_arguments(BUILD_FLAGS NATIVE_COMMAND ${CMAKE_CXX_FLAGS_RELEASE})
66
target_compile_options(latency PRIVATE ${BUILD_FLAGS})

benchmarks/latency.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,47 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*
16-
*/
17-
18-
#include <ros/ros.h>
16+
*/
1917

18+
#include <builtin_interfaces/msg/time.hpp>
2019
#include <iomanip>
21-
#include <sensor_msgs/Image.h>
20+
#include <rclcpp/rclcpp.hpp>
21+
#include <sensor_msgs/msg/image.hpp>
2222

2323
//==============================================================================
24-
int main(int argc, char* argv[])
24+
int main(int argc, char * argv[])
2525
{
26-
ros::init(argc, argv, "clpe");
26+
rclcpp::init(argc, argv);
2727

2828
const std::size_t cam_count = 4;
2929

30-
auto node = ros::NodeHandle("canlab_benchmark_latency");
30+
auto node = rclcpp::Node::make_shared("canlab_benchmark_latency");
3131
std::array<std::size_t, cam_count> cam_sub_count;
3232
// Latency in millis
3333
std::array<double, cam_count> avg_latencies;
34-
for (auto i = 0; i < cam_count; ++i)
35-
{
34+
for (auto i = 0; i < cam_count; ++i) {
3635
cam_sub_count[i] = 1;
3736
avg_latencies[i] = 0.0;
3837
}
3938

40-
std::array<ros::Subscriber, cam_count> subs;
41-
using sensor_msgs::Image;
42-
for (int i = 0; i < cam_count; ++i)
43-
{
44-
subs[i] = node.subscribe<Image>("/clpe_node/cam_" + std::to_string(i) + "/image_raw", 10,
45-
[i, &node, &cam_sub_count, &avg_latencies](const Image::ConstPtr& image) {
46-
const auto local_time = ros::Time::now().toNSec();
47-
const auto cam_time = image->header.stamp.toNSec();
48-
const auto diff_ns = local_time - cam_time;
49-
const double latency = diff_ns / 1000000.0;
50-
avg_latencies[i] =
51-
(avg_latencies[i] * cam_sub_count[i] + latency) / (cam_sub_count[i] + 1);
52-
cam_sub_count[i]++;
53-
std::cout << "cam_" << i << " latency = " << std::fixed << std::setprecision(3)
54-
<< avg_latencies[i] << "ms" << std::endl;
55-
});
39+
std::array<rclcpp::SubscriptionBase::SharedPtr, cam_count> subs;
40+
using sensor_msgs::msg::Image;
41+
for (int i = 0; i < cam_count; ++i) {
42+
subs[i] = node->create_subscription<Image>(
43+
"cam_" + std::to_string(i) + "/image_raw", rclcpp::SystemDefaultsQoS(),
44+
[i, &node, &cam_sub_count, &avg_latencies](const Image::SharedPtr image) {
45+
const auto local_time = node->get_clock()->now().nanoseconds();
46+
const auto cam_time = rclcpp::Time(image->header.stamp).nanoseconds();
47+
const auto diff_ns = local_time - cam_time;
48+
const double latency = diff_ns / 1000000.0;
49+
avg_latencies[i] = (avg_latencies[i] * cam_sub_count[i] + latency) / (cam_sub_count[i] + 1);
50+
cam_sub_count[i]++;
51+
std::cout << "cam_" << i << " latency = " << std::fixed << std::setprecision(3) <<
52+
avg_latencies[i] << "ms" << std::endl;
53+
});
5654
}
5755

58-
ros::spin();
56+
rclcpp::spin(node);
5957

6058
return 0;
6159
}

clpe.repos

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
repositories:
2-
canlab-co/CLPE_G_AP0202_SDK:
2+
canlab-co/CLPE_G_NVP2650D_SDK:
33
type: git
4-
url: https://github.com/canlab-co/CLPE_G_AP0202_SDK.git
5-
version: noetic
4+
url: https://github.com/canlab-co/CLPE_G_NVP2650D_SDK.git
5+
version: main
66
canlab-co/clpe_ros_msgs:
77
type: git
88
url: https://github.com/canlab-co/clpe_ros_msgs.git
9-
version: noetic
9+
version: main
1010
canlab-co/clpe_ros:
1111
type: git
1212
url: https://github.com/canlab-co/clpe_ros.git
13-
version: noetic-AP0202
13+
version: main

0 commit comments

Comments
 (0)