This is demonstration of a ROS 2 interface to an esp32 running differential-drive motor control code.
The codes are as follows.
esp32_2_pi_demo
- Demonstration for wifi communication from esp32 to piesp32_motor_demo
- ros2 code for the motor driver and gui nodesesp32_motor_demo_msgs
- support variables for the esp32_motor_demo coderos_esp32_bridge_wifi
- sketch for the esp32, to run the wireless communications. Done in platformioros_esp32_bridge_serial
- sketch for the esp32 to run the serial communication with the ros2. Done in arduino IDE. Only works with original serial ros2 demo.
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 esp32 code (see Arduino side documentation for details)esp32_ip
- This is the ip of the esp32. I'm using a static ip (defaulthttp://192.168.1.211
)baud_rate
- Obsolete since I'm using a wifi connectionserial_port
- Obsoleteserial_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
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.