This repository presents a complete example of how to repurpose an ANET A8 3D printer motherboard into a functional actuator system for a differential drive robot, fully integrated with the ROS 2 control framework (ros2_control). It provides both the firmware that runs on the microcontroller and the hardware interface plugin required to bridge the physical system with the ROS 2 ecosystem.
This project serves two main purposes:
- Hardware Repurposing Reference: It provides a practical, working example of how inexpensive 3D printer electronics can be reused in robotics applications.
- ROS 2 Control Integration Example: It offers a minimal but complete implementation of a custom hardware plugin for
ros2_control, useful as a reference or learning resource.
The actuator system is composed of two stepper motors, each equipped with an AS5600 absolute magnetic encoder to track shaft position. The motors are driven by A4988 stepper drivers onboard the ANET A8 motherboard. The board uses an Atmega1284p microcontroller, which is compatible with the Arduino toolchain through the Sanguino board definition, although it is not officially supported by the Arduino IDE.
All communication between the robot and the ROS 2 computer occurs over a serial connection, with velocity commands sent to the microcontroller and encoder data streamed back to the host. A custom SystemInterface plugin for ros2_control implements this logic, enabling real-time control and feedback integration.
Figure 1: System architecture overview. Two stepper actuators with magnetic encoders are driven by an ANET A8 3D printer board running custom firmware. The board communicates via serial with a ROS 2 Humble system, which uses ros2_control to manage real-time control and feedback integration.
| Component | Description |
|---|---|
| ROS 2 Humble | Target ROS 2 distribution |
ros2_control | Hardware abstraction & real-time control |
diff_drive_controller | Velocity command + odometry |
joint_state_broadcaster | Publishes joint states |
| Launch & Config | YAML + launch files |
The system is tested and functional. It supports closed-loop velocity control, publishes joint states, integrates cleanly with the ROS 2 navigation stack, and can be driven using tools such as teleop_twist_keyboard or custom commands. This setup is a solid foundation for building more complex mobile robots or for learning how to write real ros2_control hardware interfaces from scratch.
This section provides instructions for installing and using the custom hardware plugin developed for the ros2_control framework. It assumes a working installation of ROS 2 Humble and basic familiarity with ROS 2 concepts. Firmware installation for the ANET A8 board is addressed in a later section.
Begin by cloning this repository into the src/ directory of your ROS 2 workspace:
cd ~/ros2_ws/src
git clone -b humble https://github.com/ricdigi/ros2_dual_stepper_controller.gitNext, ensure that all required system dependencies are installed. The plugin relies on core components of the ROS 2 control stack, including controller management and joint state broadcasting:
sudo apt install ros-humble-ros2-control \
ros-humble-ros2-controllers \
ros-humble-diff-drive-controller \
ros-humble-joint-state-broadcaster \
ros-humble-controller-manager \
ros-humble-robot-state-publisher \
ros-humble-xacroOptional tools for manual control and visualization can be installed with:
sudo apt install ros-humble-teleop-twist-keyboard \
ros-humble-rviz2After installing system packages, use rosdep to resolve any remaining ROS-specific dependencies:
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src -r -yFinally, build the workspace. Ensure your ROS 2 environment is properly sourced before compiling:
source /opt/ros/humble/setup.bash
colcon build --symlink-installOnce the build completes, source the workspace:
source install/setup.bashYou are now ready to launch and test the system.
To bring up the dual stepper controller system, use the provided launch files. The main launch file is located in launch/dual_stepper_controller.launch.py. This file sets up the necessary nodes and configurations for the hardware interface, controllers, and robot state publisher. Moreover, it launches rviz2 for visualization and debugging.
Run the following command to start the system:
ros2 launch ros2_dual_stepper_controller test_hardware.launch.pyNote: the system will run only if the ANET A8 board is connected via USB and the firmware is correctly installed and running (see the Firmware section below).
The firmware is written in C++, and integrating some Arduino library syntax, for the Atmega1284p microcontroller on the ANET A8 motherboard. It implements a minimal serial protocol to receive velocity commands from the ROS 2 host and return encoder readings from the attached AS5600 sensors.
The firmware is designed to be compiled and uploaded using PlatformIO. To install PlatformIO, follow the instructions on the official website. A working Python installation is required. Moreover, make sure to install the shell commands.
-
Navigate to the
firmware/directory:cd firmware -
Open the
platformio.inifile and set the correct USB upload port:upload_port = /dev/ttyUSB0 ; or COM3 on Windows
-
Compile and upload the firmware:
platformio run --target upload
After upload, the microcontroller will automatically reset and start listening for velocity commands over the specified serial port. Ensure that the serial port specified here matches the one configured in your ROS 2 <ros2_control> URDF tag.