| Branch | Build Status |
|---|---|
| main | |
| dev |
This repository implements a 4-wheel drive (4WD) differential drive robot based on the ROS2 Control framework. It extends the standard diffbot example from ros2_control_demos to support a 4WD configuration with ODrive motor controllers via CAN bus.
System components:
- Four-wheel drive with differential steering mechanism
- ODrive motor controllers with CAN communication protocol
- Docker containers for cross-architecture deployment
- ROS2 Control hardware interface implementation
git clone git@github.com:rwu-r2m/r2m_4wd_diff_drive.git && cd r2m_4wd_diff_drivegit submodule update --initdocker compose -f docker/build.yml buildDocker configuration files:
docker/build.yml: Docker image build configurationdocker/docker-compose.yml: Simulation environment with mock hardware interfacesdocker/docker-compose-hardware.yml: Hardware integration with physical motorsdocker/docker-compose-amd64.yml: AMD64 architecture configurationdocker/docker-compose-arm64.yml: ARM64 architecture configuration
Execute with simulated hardware interface:
# Grant X server access to the container (required for GUI applications)
xhost local:userdocker compose -f docker/docker-compose.yml upIf the simulation GUI fails to start, check that X server permissions are properly set. The xhost local:user command allows the Docker container to access your local X server for displaying GUI applications.
If you can an unauthorized error, try logging out from the docker registry
docker logout ghcr.ioConnect to physical hardware components via CAN interface.
-
CAN interface connection: Connect the CAN2USB adapter to the diff-base
-
CAN interface configuration: Set up the Linux CAN interface
sudo ip link set can0 up type can bitrate 250000
If interface doesn't exist:
sudo ip link add dev can0 type can bitrate 250000 sudo ip link set can0 up
-
Power system initialization:
- Connect power supply (bike cell)
- Enable main power switch
- Verify ODrive controller status LEDs
-
Launch hardware container:
docker compose -f docker/docker-compose-hardware.yml up
To send velocity commands:
ros2 topic pub --rate 30 /cmd_vel geometry_msgs/msg/TwistStamped "
twist:
linear:
x: 0.2
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.3"Single command format:
ros2 topic pub -1 /cmd_vel geometry_msgs/msg/TwistStamped "{header: {stamp: {sec: 0}, frame_id: 'base_link'}, twist: {linear: {x: 0.2, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.3}}}"Implemented extensions to the original diffbot implementation:
-
4WD configuration:
- Independent control of 4 wheel motors
- Modified controller parameters for multi-wheel configuration per side
-
ODrive integration:
- CAN bus communication interface
- odrive_ros2_control hardware_interface plugin implementation
-
Docker implementation:
- Multi-architecture compatibility (AMD64/ARM64)
- Separate runtime environments for simulation and hardware testing
-
Parameter modifications:
- Wheel geometry parameters for 4WD system
- ODrive-specific CAN bus parameters
- Simulated motor/encoder feedback
- Command reception without physical hardware
- Used for algorithm testing and development
- No hardware dependencies
- ODrive motor controller communication via CAN
- Real-time sensor data acquisition
- Physical motor command transmission
- Full hardware dependencies
Symptom: No odometry data or abnormal motor behavior
Cause: Incorrect ODrive CAN ID configuration
Solution:
- Verify ODrive CAN IDs (ID 0 for left motors, ID 1 for right motors)
- Use ODrive Tool to check/modify CAN configuration
Symptom: Wheels rotating in same direction during turn commands
Solution:
- Check controller configuration (bringup/config/)
- Rebuild and restart after parameter modification
Symptom: No response to velocity commands
Causes:
- Topic mismatch: Verify publishing to
/cmd_velwith correct message type - Controller state: Verify controller status:
ros2 control list_controllers
- Hardware communication: Check ODrive status and CAN communication
Symptom: Hardware interface errors or timeout
Diagnostics:
- Check interface status:
ip -details link show can0
- Monitor CAN traffic:
candump can0
- Reset interface if necessary:
sudo ip link set can0 down sudo ip link set can0 up type can bitrate 250000