A ROS2 wrapper for the socketcan_adapter library, providing ROS2 nodes and launch files for easy integration with ROS2 systems.
- socketcan_adapter - Core SocketCAN library
- rclcpp - ROS2 C++ client library
- rclcpp_lifecycle - ROS2 lifecycle node support
- can_msgs - ROS2 CAN message definitions
Install dependencies:
rosdep install -i -y --from-paths socketcan_adapter_rosBuild:
colcon build --packages-up-to socketcan_adapter_rosros2 launch socketcan_adapter_ros socketcan_bridge_launch.pycan_interface: CAN interface to connect to (default: "can0")can_error_mask: CAN error mask (default: 0x1FFFFFFF - everything allowed)can_filter_list: CAN filters as list of ID/mask pairs (default: [])join_filters: Use joining logic for filters (default: false)auto_configure: Automatically configure the lifecycle node (default: true)auto_activate: Automatically activate the lifecycle node post configuration (default: true)
ros2 launch socketcan_adapter_ros socketcan_bridge_launch.py \
can_interface:=can1 \
can_error_mask:=0x1F \
can_filter_list:="[{id: 0x123, mask: 0x7FF}, {id: 0x456, mask: 0x7FF}]"If you prefer manual control over the lifecycle:
# Launch without auto-activation
ros2 launch socketcan_adapter_ros socketcan_bridge_launch.py \
auto_configure:=false \
auto_activate:=false
# Configure the node
ros2 lifecycle set /socketcan_bridge configure
# Activate the node
ros2 lifecycle set /socketcan_bridge activate/can_rx(can_msgs/msg/Frame) - Received CAN frames from the bus
/can_tx(can_msgs/msg/Frame) - CAN frames to transmit to the bus
The socketcan_bridge node is implemented as a ROS2 lifecycle node
The node accepts the following ROS2 parameters:
can_interface(string): Name of the CAN interface (e.g., "can0", "vcan0")error_mask(int): CAN error mask for filtering error framesfilters(array): List of CAN filter objects withidandmaskfieldsjoin_filters(bool): Whether to use joining logic for multiple filters
- ROS2 (Humble or later)
- Linux system with SocketCAN support
- socketcan_adapter library
- Active CAN interface (real or virtual)