This is demonstration of a ROS 2 interface to an Arduino running differential-drive motor control code.
The corresponding Arduino code can be found here, which is itself a fork of this repo, which also contains a similar implementation for the ROS/Python/Client side (ROS 1 though).
The esp32_motor_demo
package consists of two nodes, driver.py
and gui.py
. The idea is that the driver can be run on an onboard PC inside a robot (e.g. a Raspberry Pi), interfacing with the lower-level hardware. The driver exposes motor control through ROS topics (see below), which are to be published by the user's software.
The GUI provides a simple interface for development and testing of such a system. It publishes and subscribes to the appropriate topics.
The driver has a few parameters:
encoder_cpr
- Encoder counts per revolutionloop_rate
- Execution rate of the Arduino code (see Arduino side documentation for details)serial_port
- Serial port to connect to (default/dev/ttyUSB0
)baud_rate
- Serial baud rate (default57600
)serial_debug
- Enables debugging of serial commands (defaultfalse
)
To run, e.g.
ros2 run esp32_motor_demo driver --ros-args -p encoder_cpr:=3440 -p loop_rate:=30 -p serial_port:=/dev/ttyUSB0 -p baud_rate:=57600
It makes use of the following topics
motor_command
- Subscribes aMotorCommand
, in rads/sec for each of the two motorsmotor_vels
- Publishes aMotorVels
, motor velocities in rads/secencoder_vals
- Publishes anEncoderVals
, raw encoder counts for each motor
Has two modes, one for raw PWM input (-255 to 255) and one for closed-loop control. In this mode you must first set the limits for the sliders.
- Add service for encoder reset
- Add service for updating PID parameters
- Stability improvements
- More parameterisation