ROS 2 torque-vectoring control software for a four-wheel vehicle. The project contains a reusable C++ control library, a ROS 2 node, reference generators, high- and low-level controllers, traction control, and a Python TCP bridge for connecting ROS 2 to Simulink.
torque-vectoring/: ROS 2 package and C++ implementationtorque-vectoring/include/: public headers and data structurestorque-vectoring/src/: library and ROS 2 node sourcestorque-vectoring/test/: GoogleTest sourcestcp_to_ros.py: TCP bridge between Simulink and ROS 2
- ROS 2 with
rclcpp,std_msgs, andgeometry_msgs - C++17 compiler
- CMake 3.16 or newer
- Python 3 with
numpyandrclpy - A TCP client such as Simulink for the bridge, if required
Source ROS 2 in a new terminal, then build from the repository root:
source /opt/ros/<ros-distro>/setup.bash
colcon build --symlink-install
source install/setup.bashThe package can also be configured directly with CMake when the required ROS 2 environment is available:
cmake -S torque-vectoring -B build -DCMAKE_BUILD_TYPE=Release
cmake --build buildStart the torque-vectoring node:
source install/setup.bash
ros2 run torque_vectoring torque_vectoring_nodeStart the Simulink bridge in another terminal:
source /opt/ros/<ros-distro>/setup.bash
python3 tcp_to_ros.pyThe bridge listens on all interfaces. Configure the Simulink side to connect to:
TCP port 20000: Simulink to ROS 2 input dataTCP port 20001: ROS 2 to Simulink wheel-torque output
| Topic | Type | Meaning |
|---|---|---|
/vehicle/throttle |
std_msgs/msg/Float64 |
Driver throttle command |
/vehicle/steering |
std_msgs/msg/Float64 |
Driver steering command |
/vehicle/yaw_rate |
std_msgs/msg/Float64 |
Measured yaw rate |
/vehicle/velocity |
geometry_msgs/msg/Vector3 |
Vehicle velocity; x and y are used |
/vehicle/acceleration |
geometry_msgs/msg/Vector3 |
Vehicle acceleration; x and y are used |
/vehicle/slip_rl |
std_msgs/msg/Float64 |
Rear-left slip percentage |
/vehicle/slip_rr |
std_msgs/msg/Float64 |
Rear-right slip percentage |
| Topic | Type | Meaning |
|---|---|---|
/vehicle/wheel_torques |
std_msgs/msg/Float64MultiArray |
[rear_left_torque, rear_right_torque] |
/vehicle/yaw_rate_reference |
std_msgs/msg/Float64 |
Generated yaw-rate reference |
/vehicle/sideslip_reference |
std_msgs/msg/Float64 |
Generated sideslip reference |
/vehicle/yaw_moment_request |
std_msgs/msg/Float64 |
High-level yaw-moment request |
/vehicle/total_torque_request |
std_msgs/msg/Float64 |
Requested total torque |
The node uses a 1 ms timer for its control loop. Slip values received by the C++ node are interpreted as percentages and converted to ratios.
Input packets on port 20000 are interpreted as native little-endian float64 values. The first value is a message flag:
| Flag | Remaining values |
|---|---|
0 |
throttle, steering |
1 |
yaw_rate, velocity_x |
2 |
velocity_x, velocity_y, acceleration_x, acceleration_y |
3 |
slip_rl, slip_rr |
Output packets on port 20001 contain two native float64 values in this order:
rear_left_torque, rear_right_torque
The bridge currently publishes its input values on the ROS topics listed above and sends only the first two values of /vehicle/wheel_torques back to the connected TCP client.
GoogleTest source files are included under torque-vectoring/test/. The test target is currently commented out in torque-vectoring/CMakeLists.txt, so the tests are not registered with CMake or ctest yet.
After enabling the test target, run the tests with:
cd build
gctest --output-on-failureMIT