Electronics_Motor controller (hardware and firmware)
As mentioned before changing the original brushed DC motor with a gear-box brushed DC motor eliminated the need for controlling the rotation speed. The max speed is low and it does not really make sense to lower it. So to just changing the direction will suffice.
I designed a simple part for it to be able to control the motor direction or to turn it off using serial:
One channel relay control module x2
LM2596S DC-DC 4.5-40V Adjustable Step Down Power Supply Module
![]() |
| DC motor rotation control |
The functionality is simple. There are two relays that can have 4 states overall:
00 the motor is off
11 the motor is off
10 the direction is x
01 the direction is ~x
The assembled part is like this:
![]() |
| The rotation controller |
![]() |
| Relays |
![]() | ||
| Final part |
the source for the controller firmware can be found here:
serial_motor_rotation_controller
It is a small and highly readable piece of code and does not need much elaboration. It reads the input string from USART until it sees an '@' character or a timeout happens, then looks to see if the input string matches any of "query", "on", "off, "stp", "fwd", "bwd". These commands result in turning device on/off, stop the motor and changing its direction.
After uploading the code on the Arduino (Arduino is connected using a USB
cable), connecting the convertor to the power and connecting the motor
to the output connector we can simply write (for example in Linux, assuming the Arduino port to be /dev/ttyUSB0):
$sudo stty 57600 -F /dev/ttyUSB0
$sudo -i
for listening to device:
$cat -v /dev/ttyUSB0
and writing to it using another terminal:
$sudo i
$echo 'on@'> /dev/ttyUSB0
we will get a message on the other terminal:
motor_controller on
after that:
$echo 'fwd@'> /dev/ttyUSB0
$echo 'bwd@'> /dev/ttyUSB0
$echo 'stp@'> /dev/ttyUSB0
With all parts assembled, plus a raspberry pi4 ,LCD and a rotatable camera(using two orthogonal servos) we have something like this:
| Final look of the cub |
Now I will focus more on the software part. I am going to apply SOA (service-oriented architecture) to implement the entire software of this robot. I will implement necessary services and try to iteratively and incrementally improve them.
Arash Ardeshiri
July 13 2021




Comments
Post a Comment