Controlling motors from ROS
Motor Control
Wolf has four motors connected to quadrature encoders. Users can control motors directly from raspberry pi serial command.
Installing necessary packages
To send serial commands from raspberry pi to micro controller board, we need to install python3-serial package.
Make sure to install the below package on the @robot
machine and not on the @dev
machine.
Run miniterm
with baud rate of 57600
(set on the micro controller board) on USB0
. If unsure on which usb it is connected, check by typing lsusb
. If Lidar is also connected, board can be connected to USB0 or USB1. In later part of tutorial, we will see how to hard code a particular port for different peripherals. To exit miniterm, press CTRL+]
The micro controller is configured as per the below commands. However, we are interested in only motor speed and encoder counts:
Type e
and it should output encoder count. If robot has not moved, it will echo 0 0 0 0
To run the robot, type the m and o
commands. However, make sure robot wheels are not touching the ground, or it is safe to drive as it moves the robot for 2 seconds in the said speed.
PWM based motor control
o 127 127 127 127
# This will run the motors at 50% speed straight
o -255 -255 -255 -255
# This will run the motors at 1000% speed reverse
Encoder based motor control
Counts per rotation of wolf motor (CPR) is 560 and PID is running at 28hz. So, to get one rotation per second, we need to send 20 ticks. The Motor driver is designed to make sure it receives signal every 2 seconds. If any signal in 2 seconds, robot stops.
m 20 20 20 20
# run the motor for 2 seconds at 1 revolutions per second
When trying encoder based motor control, the motor does not run complete two runs for 2 seconds. This is a latency issue due to Wi-Fi setup. If you set m to 25, then the wheels turn at exactly 1 revolutions per second. However, for continuous run, or navigation, it takes 20 ticks per revolution.
Reset Encoder Count
To reset the encoder count, type r
without any arguments. This resets all encoders to 0 (zero).
GUI based motor Control
Copy serial_motor_demo
package from downloaded folder to dev_ws/src
. Push the package to your GitHub repository and clone the same package on the @robot
machine. If you need a direct link to download on your raspberry pi, clone the below repository on your pi.
@robot
, type:
@dev
, type:
Use the sliders on GUI to move motors either on raw speed mode (o) or feedback mode (m
).
Last updated