Arduino controlled two servos based robot - achieving a straight line

Introduction

In this article I will discuss how I came close to syncing the rotation speed of two continuous rotation servo motors to allow movement in straight line and control the speed of the robot forwards and backwards.

The Problem

If you are making a robot and want it to move in a straight line, and assuming you are using two motors for the drive, you need them to rotate in the same speed.

As most people know choosing the correct motor type for the job is important, but sometimes you don't have options and need to work with what you have.

Motor Types:


Motor Types
Source: https://backyardbrains.com/experiments/MuscleSpikerShield_GripperHand

Hobbyists & makers usually choose one of these motor types to drive their robot. To achieve a straight line, stepper motors seems to be the right choice since they can be controlled in terms of speed and direction accurately without encoders or feedback circuit. In my case I was stuck with servo motors, and thought why not tackle this challenge, but couldn't find much help online.

No two motors are exactly the same, that means you will find slight differences in the rotation speed for each motor, which causes the robot to drift when trying to move in a straight line.

On top of this, mounting the servo motors on opposite sides of the robot means that one rotates in clockwise direction and the other in counter clockwise direction. Which adds to the difference in rotation speed, I don't believe servo motors rotation speed is symmetrical!


Solution suggestions

First thought was to add an encoder to the continuous rotation servos, but if you worked with servos before you'll find that there isn't much space for one! So my approach was to take an attempt at this statistically!

Main idea:

Log the rotation speed of each motor individually at each pulse width speed signal and then map both motors results together.

Which means:
  1. Set motor speed speed signal to 'X' microseconds
  2. Measure the time it requires to complete a rotation (I actually measured the time needed to rotate three times)
  3. Change X and measure again
  4. Do the same for the other motor

Steps:

  1. Measure time required to rotate at each speed setting
    1. I originally setup the servo with the 6 spike arm but I then used the 2 spike arm instead
             --->      
      Using the Arduino millis() and an optocoupler as the encoder I was able to measure the time to complete three rotations (with a 2 spike arm, that means 6 counts)
    2. Measurement

      I started plotting data in the range 500 us to 2500 uS, but there was no significant changes in speed from 500 uS to 1200 and from 1800 uS to 2500 uS.
      Consequently I used the data range 1200 - 1800 uS in 25 uS speed increments.

      Measuring 9 readings and plotting the average time taken to complete 3 rotations:

      encoder countSpeed (uS)Avg. Time (Sec)(mS) 1(mS) 2(mS) 3(mS) 4(mS) 5(mS) 6(mS) 7(mS) 8(mS) 9
      612001.941195019261945195119441941194019341941
      612252.019201420092018201920252016202720192026
      612502.320232222972294230323052308236323512339
      612752.680268926692673267326882686268626702688
      613003.180317031823144316631773181319132013211
      613253.960389439063938397439853964398039894012
      613505.142498450465074513951635210520652305230
      613757.270698270037135720973197343742974607548
      6140011.977111811177911799120811206812148121381227112325
      6157513.697123681308013486137651376713974140851439314359
      616007.979772777457889801280598054808181028140
      616255.511538354295472553255275554554355895568
      616504.157411041114166418141894165414141734177
      616753.307327132813291330833083317331633353340
      617002.756276727322741274827482745275927762788
      617252.350236623542334235523352339235123562359
      617502.069207720712075208320772071205120562056
      617751.951194419561969197819611971194619181919
      618001.953194619531962198119691985194219161924

      Motor 1 - Time required (m sec) to complete three rotations at each motor speed signal (uS)

      Motor 1 - Time required to complete three rotations VS. motor speed signal

      I noted the minimum and maximum time deviations in each speed signal to log the error range:

      Speed (uS)MINMAXError Range
      12001926195125
      12252009202718
      12502294236369
      12752669268920
      13003144321167
      132538944012118
      135049845230246
      137569827548566
      140011181123251144
      157512368143932025
      160077278140413
      162553835589206
      16504110418979
      16753271334069
      17002732278856
      17252334236632
      17502051208332
      17751918197860
      18001916198569

      Motor 1 - Error range in ms for each speed signal.
      Note: As the speed decreases, approaching motor stop @1500uS signal, error range increases

      Did the same for Motor 2...

      encoder stepsSpeed (uS)Avg. Time (Sec)(mS) 1(mS) 2(mS) 3(mS) 4(mS) 5(mS) 6(mS) 7(mS) 8(mS) 9
      612001.953194919531961195419481972194419551944
      612252.017202720022026200620232031201620182008
      612502.240223622402240224122372248224522602213
      612752.559256925562565255025692554255425502561
      613003.004301629972975299829923011300530273013
      613253.687369536623697368136843663368937013713
      613504.739467946844682473447104778477348064804
      613756.464634163176400638564416461654466106680
      614009.9679606975097059853985410035101521033610414
      6157511.460113111123511050111861123911621116521183612013
      616007.021697069126950695269967027707171407171
      616255.012500249844977499149835034502750655044
      616503.868390338573882387238463850384538783878
      616753.111312130993096310430993113311231293124
      617002.621262526052607261226202621262626422632
      617252.278228222712266226722682280227623002296
      617502.016203120172016202520252022200020091996
      617751.932190919241929193519321942195119371929
      618001.932191119261933192819341936195219421929

      Motor 2 - Time required (m sec) to complete three rotations at each motor speed signal (uS)
      Motor 2 - Time required to complete three rotations VS. motor speed signal

      Again, noted the minimum and maximum time deviations in each speed signal to log the error range:

      Speed (uS)MINMAXError Range
      12001944197228
      12252002203129
      12502213226047
      12752550256919
      13002975302752
      13253662371351
      135046794806127
      137563176680363
      1400960610414808
      15751105012013963
      160069127171259
      16254977506588
      16503845390358
      16753096312933
      17002605264237
      17252266230034
      17501996203135
      17751909195142
      18001911195241

      Motor 2 - Error range in ms for each speed signal.
      Note: As the speed decreases, approaching motor stop @1500uS signal, error range increases

    3. Compare the two motors performance

      Speed mR (uS)motorRmotorLSpeed mL (uS)
      12001.951.951800
      12252.021.951775
      12502.242.071750
      12752.562.351725
      13003.002.761700
      13253.693.311675
      13504.744.161650
      13756.465.511625
      14009.977.981600
      157511.4613.701575
      16007.0211.981400
      16255.017.271375
      16503.875.141350
      16753.113.961325
      17002.623.181300
      17252.282.681275
      17502.022.321250
      17751.932.021225
      18001.931.941200
      Note: Motor 1 sorted ascendingly and Motor 2 descendingly, as they will be mounted oppositely on the robot, each motor on one wheel.
      Motor 1 & 2 comparison. Time (sec) to rotate three rotations at each speed signal (uS)

      It can be noticed that some of the values are close to each other, but we need to shift the use of motors speed signal.

      From the above table, I eliminated the use of 1800uS speed signal (in dark gray) from both motors, as it added no significant speed change, and would allow both sides of the table to shift up to a closer values on both sides.

      I also ignored the signals between 1400 - 1500 uS as the error range was already too high in the slow range near the stopping speed signal 1500uS.

      The result table would then be:

      Speed mR (uS)motorRmotorL (white)Speed mL (uS)
      12001.951.951775
      12252.022.071750
      12502.242.351725
      12752.562.761700
      13003.003.311675
      13253.694.161650
      13504.745.511625
      13756.467.981600


      16007.027.271375
      16255.015.141350
      16503.873.961325
      16753.113.181300
      17002.622.681275
      17252.282.321250
      17502.022.021225
      17751.931.941200

      Note A
      : Motor 1 sorted ascendingly and Motor 2 descendingly, as they will be mounted oppositely on the robot, each motor on one wheel.
      Note B: Both Motors time is now closer in value. which brings us closer to moving in straight line
      Motor 1 & 2 comparison at each speed signal after mapping the results

      At this point, we could see that we have improved the matching in speed between the two motors. But it's still not quite accurate. We need as much as we can to use values for each motor that would bring them closer to rotating at the same speed.

    4. To be continued...

    Comments

    Popular posts from this blog

    Tahrir @ Cairo, Egypt #Jan25 ...The humor side ;-)

    Relay circuit module