How to Make a Robot Car Go in a Straight Line#
After messing around with my micropython-based esp8266 chip, I’ve finally got to the point where I can make the robot go in a straight line.
The Hardware#
My robot car is a dual-motored car. This means that unavoidably I’ll need to correct the tiny differences
between the two motors so as to make it go in a straight line. To achieve this goal, I bought an MPU9250
motion sensor which can detect its acceleration
The Original Algorithm#
My original algorithm is to increaase the speed of one motor and decrease the speed of the other when I detect the robot is turning to one direction. As the motors are controlled by the voltages supplied, when I apply a voltage difference between the two motors, the motors will operate at different speeds.
The following is a theoretical analysis of my original algorithm.
The scalar angular velocity
can be determined by projecting the vector onto the gravitational unit vector:The angular velocity can be approximated as a linear function of
, the voltage difference between the two motors I apply:The voltage difference is assumed to have a linear relationship with respect to he angle
and the angular velocity :In step 3,
is determined by numerically integrating :Then a differential equation can be set up and solved with separation of variables:
This implies that my original algorithm should never be able to achieve a perfect straight line.
Nevertheless, I tried it out.
Note
The units of
Result |
|||
---|---|---|---|
10 |
20 |
0.2 |
oscillates |
10 |
10 |
0.2 |
tilts about 25 degrees |
50 |
10 |
0.2 |
oscillates |
20 |
10 |
0.2 |
tilts about 25 degrees |
20 |
12 |
0.2 |
tilts about 15 degrees |
20 |
10 |
0.6 |
tilts about 5 degrees |
(
As you can see, the results are far from satisfactory. Oscillation is not shown in the theoretical derivation but it was probably a result of latency. Another significant problem was that none of them works on relatively smooth surfaces. (It oscillates violently)
The Solution#
I eventually solved this problem by using accumulative voltage difference with weight decay.
Instead of using a fixed formula for
where
This not only smooths out the curve for