Skip to content

ROS2 and SOLO: A Design-Ready Motor Control Node

Knowledge & Insights

Introduction

A demo node that spins a motor in 30 lines and a node that drives a real robot for 8 hours are two different things. The first ignores lost frames, missed deadlines, and the moment an operator hits the e-stop. The second has to survive all of them. That gap is where most robot bring-ups stall.
This guide shows how to write a ROS2 motor control node for SOLO that holds up in production. You get a package layout, the topics and services to expose, a lifecycle state machine, real-time tips, and the error handling that keeps a robot safe when the bus drops. If you want the theory of why ROS2 fits motor control at all, start with our overview of ROS2 for motor controllers. Here we stay practical and write code. Treat this as a design-ready reference: the node is your software on top of SOLO’s released CAN and UART interfaces, a pattern suited to robotics integration projects rather than a stock package you install.

Why ROS2 for Motor Control

ROS2 gives you a few things that matter for a real drivetrain. DDS-based messaging with configurable Quality of Service lets you mark motor commands as reliable or best-effort, per topic. Lifecycle nodes give you a clean way to bring a drive up and tear it down on command. And the ecosystem already speaks the language of robots: cmd_vel, joint_states, nav2, and ros2_control.
For a deeper look at the trade-offs against a bare middleware, the ROS2 for motor controllers overview covers the background. The short version: ROS2 generally costs you some latency over a raw loop, and buys you composability and tooling in return. For most robots that trade is worth it.
Takeaway: ROS2 brings QoS, lifecycle, and a standard robot vocabulary to your motor stack.

Architecture of the Node

A clean node separates three concerns: the ROS2 interface (topics, services, parameters), the control logic (mapping commands to setpoints), and the transport that talks to SOLO over CAN or UART. Keep them in separate files so you can test each one alone.

ROS2 robot control architecture diagram with diff drive controller blocks

Package Layout

Use a standard ament_cmake or ament_python package. A layout that scales looks like this:

text
solo_ros2_driver/
├── package.xml
├── CMakeLists.txt
├── config/
│   └── solo_params.yaml        # node-ID, limits, bus settings
├── launch/
│   └── solo_driver.launch.py
├── src/
│   ├── solo_driver_node.cpp    # lifecycle node, ROS2 interface
│   ├── solo_transport.cpp      # CAN/UART bridge to SOLO
│   └── command_mapper.cpp      # ROS2 commands → SOLO setpoints
└── include/solo_ros2_driver/
    ├── solo_transport.hpp
    └── command_mapper.hpp

The point is the transport layer is isolated. You can swap a USB-CAN adapter for a UART link, or mock it in a unit test, without touching the ROS2 code.

Topics, Services and Parameters

Decide your interface before you write the loop. A minimal but robust set:

DirectionNameTypePurpose
Subscribe`cmd_vel` or `~/joint_command``Twist` / `Float64`Speed or torque command in
Publish`~/joint_states``JointState`Position, velocity, effort out
Publish`~/drive_status`custom or `DiagnosticArray`Faults, temperature, bus health
Service`~/enable_drive``SetBool`Enable or disable the output stage
Service`~/clear_fault``Trigger`Reset a latched fault

Make the rest parameters, not hard-coded values: the SOLO node_id, the CAN bitrate, the speed and current limits, and the publish rate. Load them from config/solo_params.yaml so the same binary runs on different robots. Declare limits at startup and clamp every incoming command against them, because a cmd_vel from a planner can ask for more than your motor can safely give.
Takeaway: a small, parameterized interface keeps one node reusable across robots.

Talking to SOLO: CAN / UART Bridge

SOLO speaks CANopen and a UART command set. For a mobile robot, CAN is usually the right choice: it is multi-drop, noise-tolerant, and lets several drives share one bus. On a Raspberry Pi or x86 host, you reach the bus through a USB-to-CAN adapter and Linux SocketCAN, then send and receive frames in the transport layer.

Diagram of CANopen communication stack between CAN bus and process environment

A simple transport loop reads encoder feedback and writes the latest setpoint:

text
// Inside SoloTransport, called from the control timer
void SoloTransport::write_setpoint(float speed_rad_s) {
  int32_t rpm = static_cast<int32_t>(speed_rad_s * RAD_S_TO_RPM);
  solo_->SetSpeedReference(rpm, &error_);   // CANopen / SDO under the hood
}

Feedback SoloTransport::read_feedback() {
  Feedback fb;
  fb.position_rad = solo_->GetPositionCountsFeedback(&error_) * COUNTS_TO_RAD;
  fb.speed_rad_s  = solo_->GetSpeedFeedback(&error_) * RPM_TO_RAD_S;
  fb.iq_amp       = solo_->GetQuadratureCurrentIqFeedback(&error_);
  return fb;
}

Keep the bus access on one thread. CAN frames are small, and interleaving reads and writes from several threads on the same socket invites trouble. For the hardware side, a USB-to-CAN converter wired to the SOLO bus terminals is the usual setup on a Linux host.

USB-to-CAN converter board with USB-C and green terminal block

Takeaway: isolate the bus in one thread and one class, then the rest of the node stays portable.

Implementing the Control Loop

The loop itself is small. The discipline is in how you structure its states and what you publish.

Lifecycle Node and States

Use a LifecycleNode, not a plain node. It gives you explicit on_configure, on_activate, on_deactivate, and on_cleanup callbacks that map naturally onto a drive:

  • on_configure: open the CAN socket, read parameters, run motor identification if needed. Do not energize the motor yet.
  • on_activate: enable the SOLO output stage and start the control timer.
  • on_deactivate: stop the timer, command zero, disable the output stage.
  • on_cleanup: close the socket and release the adapter.

This separation matters in a real robot. A supervisor or nav2 can hold every drive in the inactive state until the whole system is ready, then activate them together. A crash during configure never leaves a motor spinning, because the output stage only comes alive in on_activate.

Publishing Feedback (position, speed, Iq)

Publish joint_states at a fixed rate from a timer, not from the subscriber callback. A common choice is 100 Hz for the state feedback and a faster internal read if your controller needs it.

text
void SoloDriverNode::publish_feedback() {
  auto fb = transport_->read_feedback();
  sensor_msgs::msg::JointState msg;
  msg.header.stamp = now();
  msg.name = {joint_name_};
  msg.position = {fb.position_rad};
  msg.velocity = {fb.speed_rad_s};
  msg.effort   = {fb.iq_amp * kt_};   // Iq scaled by torque constant
  state_pub_->publish(msg);
}

Publishing Iq as effort is useful: it gives your higher layers a real torque estimate instead of a guess. Stamp every message with the time you read the bus, so downstream filters and tf see honest timing.

Mapping ROS2 Commands to SOLO Setpoints

A cmd_vel for a differential drive carries linear and angular velocity. Your mapper turns that into a per-wheel speed, then into a SOLO speed reference. For a single joint, a Float64 command maps straight to a setpoint after clamping.
Decide which mode of operation the drive runs in: speed, torque, or position. SOLO follows the CiA 402 drive profile over CANopen, so the mode you pick on the node has to match the mode configured on the drive. For the object dictionary entries and the state machine behind these modes, see the dedicated CiA 402 guide once it is published. Keep the mapping in its own command_mapper unit so you can unit-test it with no hardware attached.
Takeaway: lifecycle states, timed feedback, and a tested mapper are what separate a robust node from a demo.

Production Concerns

This is the part demo code skips. It is also the part that decides whether your robot runs for a shift or trips on the first noisy frame.

Real-Time and Executors

The default single-threaded executor runs every callback in turn, so a slow service handler can delay your control timer. For a drive, that jitter is a problem. Two common fixes:

  • Use a MultiThreadedExecutor with callback groups. Put the control timer in a MutuallyExclusive group and the slower services in another, so they cannot block the loop.
  • Pin the control timer to a real-time priority on a PREEMPT_RT kernel, and avoid memory allocation inside the loop. Pre-allocate messages and reuse them.

You will not get hard real-time guarantees from a stock Linux desktop. You can get soft real-time that is good enough for most mobile robots, especially with a tuned kernel. For the deployment side of this on Linux, our guide on running SOLO on Linux covers the setup.

Error Handling and Recovery

Every bus call can fail. Treat a failed read or write as a signal, not an exception to swallow. A practical pattern:

text
auto fb = transport_->read_feedback();
if (!fb.valid) {
  if (++consecutive_errors_ > error_threshold_) {
    RCLCPP_ERROR(get_logger(), "CAN feedback lost, entering safe stop");
    enter_safe_stop();      // command zero, disable output, publish fault
    deactivate();           // drop to inactive lifecycle state
  }
  return;
}
consecutive_errors_ = 0;

Count consecutive failures instead of reacting to a single dropped frame. One lost frame on a busy bus is normal. Ten in a row means the link is gone. Publish the fault on drive_status so the rest of the system knows, and let an operator clear it through the clear_fault service after the cause is fixed.

Watchdog and Safe Stop

A robot must stop if commands stop arriving. Run a watchdog: if no cmd_vel lands within a timeout, say 200 ms, command zero speed and, depending on the application, disable the output. This protects against a crashed planner or a dead network, not just a hardware fault.
For a true safety stop, a software command is not enough on its own. A Safe Torque Off (STO) input cuts the drive’s ability to produce torque through hardware, independent of the firmware. Wire the e-stop chain to STO where the application needs a rated safety function, and use the software safe stop as the first, faster line of defense. The two layers work together.
Takeaway: real-time executors, counted error recovery, and a watchdog plus STO are the non-negotiables for production.

Testing the Node

Test in three layers, from no hardware to full bring-up.
First, unit-test the mapper and transport with the bus mocked. Feed it known cmd_vel values and assert the setpoints, including the clamping at your limits. No motor needed.
Second, replay real traffic with ros2 bag. Record a session on the robot, then play it back into the node on the bench to reproduce a fault or a timing edge case. This makes intermittent bugs repeatable.
Third, bring up the real drive with the motor uncoupled or on a safe fixture. Step through the lifecycle by hand: configure, activate, send a small command, watch joint_states, then trigger a fault by unplugging the CAN cable and confirm the node enters safe stop. Only after that, couple the load.
Takeaway: mock, replay, then bring up real hardware, in that order, and faults stop surprising you in the field.

How SOLO Supports ROS2 Integration

SOLO is built to fit this kind of integration. The controllers support CANopen with the CiA 402 drive profile and a UART command set, so your transport layer talks to documented, released interfaces rather than a black box. Open libraries handle the low-level framing, which keeps your node focused on the robot instead of the protocol. The ROS2 layer itself is a design-ready pattern you build on top of those interfaces, well suited to robotics integration projects, so you are never blocked waiting on a stock ROS2 package. SOLO drives cover DC, BLDC, PMSM, and AC induction motors with the same control core, so one node design can carry across several robots in a fleet. You can browse the libraries, examples, and documentation on the SOLO resources page, and ask us about ROS2 for your build.

Conclusion

A robust ROS2 node for SOLO comes down to a few decisions taken in order. Separate the ROS2 interface, the control logic, and the transport so each is testable. Use a lifecycle node so the output stage only comes alive when the system is ready. Publish timed feedback, including Iq as effort, and parameterize every limit. Then spend your effort where demos do not: a multi-threaded executor for timing, counted error recovery for the bus, and a watchdog with STO for safety. Build it in that order and you get a node that survives a real shift, not just a quick spin on the bench. To get started with the libraries and docs, the SOLO resources page is the right next step.

FAQ

How does a ROS2 node communicate with SOLO?

Through SOLO’s CANopen interface or its UART command set, wrapped in a transport layer inside your node. On a Linux host you reach the CAN bus with a USB-to-CAN adapter and SocketCAN, then send setpoints and read feedback over standard frames. Keep that bus access in one isolated class and one thread.

Can I run multiple SOLO drives from one ROS2 node?

Yes. CANopen is a multi-drop bus, so several SOLO drives with different node IDs can share one link. You can address them from a single node or run one node per drive. For larger fleets, a dedicated guide on building a multi-drive CANopen network covers device addressing and bus design once it is published.

How do I handle a lost CAN connection in ROS2?

Count consecutive failed reads or writes instead of reacting to one dropped frame. Past a threshold, command zero, disable the output stage, publish the fault on a status topic, and drop the lifecycle node to its inactive state. Add a watchdog so missing commands trigger a safe stop even when the hardware is fine.

Is ROS2 fast enough for closed-loop motor control?

For the high-rate current and speed loops, no. Those run inside SOLO’s firmware in real time, which is where they belong. ROS2 handles the outer command and feedback layer, typically at 100 Hz or so, and that is fast enough for trajectory and velocity control on most robots. A tuned PREEMPT_RT kernel and a multi-threaded executor reduce jitter further.

Tags:IntegrationRoboticsROS2

Browse all categories

Drive your next innovation today

Discover our High-Performance Motor Controllers, Test Benches, and Services trusted worldwide.