This repository contains the Low-Level Control Unit firmware developed for differential drive autonomous mobile robots.
Designed to run on the Arduino Mega 2560, this firmware acts as a bridge between the robot hardware and the ROS 2 (Robot Operating System) navigation stack via serial communication.
This project was developed as part of an autonomous vehicle platform that achieved
🥈 2nd Place in Turkey – TEKNOFEST 2025 Industrial Digital Technologies Competition.
The firmware manages the robot’s actuators (DC motors, servo motors) and sensors (quadrature encoders, battery voltage monitoring, emergency stop).
It communicates with a high-level computer (Raspberry Pi 4) running ROS 2 and provides:
- Real-time PID speed control
- Encoder-based odometry data streaming
- Peripheral and safety management
-
ROS 2 Integration
Optimized serial communication protocol compatible withros2_controlandhardware_interfacearchitectures. -
Advanced PID Control
Closed-loop speed control customized for 1000 RPM DC motors. -
Modular Driver Architecture
Isolated driver layers for:- BTS7960 high-current motor drivers
- Quadrature encoders
-
Safety Protocols
- Hardware Emergency Stop (E-Stop)
- Automatic motor stop on communication loss
-
Peripheral Management
- DFPlayer Mini–based audio feedback
- Servo motor control
- Battery voltage and percentage monitoring
| Component | Description |
|---|---|
| Microcontroller | Arduino Mega 2560 |
| Host Computer (SBC) | Raspberry Pi 4 (ROS 2 Host) |
| Motor Driver | BTS7960 High Power Motor Driver |
| Motors | 1000 RPM DC Motors with Quadrature Encoders |
| Audio System | DFPlayer Mini (UART) |
| Power Management | Voltage divider for 3S–4S LiPo/Li-ion monitoring |
Default pin assignments defined in ROSArduinoBridge.ino and related headers:
| Component | Function | Pin (Mega 2560) | Notes |
|---|---|---|---|
| Left Motor | PWM Fwd (LPWM) | 9 | BTS7960 |
| PWM Rev (RPWM) | 6 | BTS7960 | |
| Right Motor | PWM Fwd (LPWM) | 11 | BTS7960 |
| PWM Rev (RPWM) | 10 | BTS7960 | |
| Left Encoder | Channel A | 2 | Interrupt |
| Channel B | 3 | Interrupt | |
| Right Encoder | Channel A | 18 | Interrupt |
| Channel B | 19 | Interrupt | |
| Audio (DFPlayer) | RX (SoftSerial) | 12 | To DFPlayer TX |
| TX (SoftSerial) | 13 | To DFPlayer RX | |
| Servo | PWM Signal | 4 | Mechanism control |
| Safety | Emergency Stop | 14 | Pull-up input |
| Signal | Buzzer | 8 | Audio warning |
| Battery | Voltage Read | A0 | Voltage divider |
- Arduino IDE 1.8.x or newer
- DFRobotDFPlayerMini library
(Install via Arduino Library Manager)
- Open
ROSArduinoBridge.ino - Ensure the BAUDRATE matches your ROS 2 configuration
- Default:
57600
- Default:
- Tune PID coefficients in
diff_controller.h:Kp, Ki, Kd
according to your mechanical system.
-
Select Arduino Mega 2560 as the target board
-
Compile and upload the firmware
Before launching ROS 2 nodes, it is strongly recommended to verify hardware and firmware via a direct serial connection.
Step 1: Connection
Connect the Arduino to the Raspberry Pi via USB. Ensure the device is available at:
/dev/ttyACM0
Step 2: Launch Serial Terminal
python3 -m serial.tools.miniterm /dev/ttyACM0 57600
Step 3: Command Testing
Press Enter after each command.
▶ Motor Test
m 120 120
Expected: Both wheels rotate forward.
⏹ Stop Motors
m 0 0
🔄 Read Encoders
e
Expected Output Example:
1250 1250
A lightweight, single-character command structure is used to minimize communication overhead.
| Command | Description |
|---|---|
m <L> <R> |
Set motor speeds (ticks/loop) |
e |
Read encoder values |
r |
Reset encoders and PID state |
u <Kp>:<Kd>:<Ki>:<Ko> |
Update PID coefficients |
| `b <1 | 0>` |
s <index> |
Play audio file |
v <index> |
Trigger servo (90° → wait 5s → return) |
f |
Read battery voltage and percentage |
This project is licensed under the MIT License.
This firmware was developed for TEKNOFEST 2025 and represents ongoing R&D work in autonomous systems and industrial robotics.
Developed and maintained by Adil NAS with Yigido Team