Calibrate External Encoders

Only for External Encoders!
If you are using Feedback 360° servos, go to Feedback 360° Encoder Calibration instead.

Before running any other example programs, your ActivityBot needs to be calibrated.  This is a one-time calibration that the abdrive library needs for measuring and correcting disances and speeds, using information from the ActivityBot encoders.

The calibration collects requested speed vs. measured speed data and stores it in a part of the ActivityBoard’s EEPROM memory, where it can retain data even after you turn the power off.  That way, the calibration data is available every time you turn the robot back on. 

When your program asks for a certain wheel speed, the abdrive library will use the calibration data from EEPROM to start driving the motors at speeds close to what your program asks for.  That way, abdrive doesn’t have to make large corrections, just small ones, which improves overall accuracy.

Circuit

Test Code

The calibration program takes less than 2 minutes to collect all of its data.  You will need a smooth and obstacle-free floor area that’s roughly one meter square.  While the calibration program is running, the ActivityBot will go in circles at various speeds, using only one wheel at a time.  It will let you know when its done by turning off its P26 and P27 lights (below the breadboard).  The above video shows an ActivityBot correctly performing the calibration.
 

IMPORTANT! USE FRESH BATTERIES FOR THIS STEP!

IMPORTANT!
Your ActivityBot Library needs to be installed in the correct location BEFORE attempting to run this, or any other, ActivityBot program.

The ActivityBot library folder should be in ...Documents\SimpleIDE\Learn\Simple Libraries\Robotics. If you install the library folder yourself, unzip the library folder and then make sure to close and then re-open SimpleIDE before continuing on to allow the software to cache the library location.

Return to Software and Programming for the library download and additional instructions, if necessary.

  • Set the ActivityBot's power switch to 1.
  • Click SimpleIDE’s Open Project button.
  • Open ActivityBot Calibrate from ...Documents\SimpleIDE\Learn\Examples\Robots\ActivityBot.
  • Click the Load EEPROM & Run button.  (Important: this program needs to be in EEPROM.)
  • When the program is finished loading, the P26 and P27 lights will turn on.  When they come on, turn off the robot's power (Slide PWR switch to 0).
  • Disconnect the ActivityBot from its programming cable and set it in a 1 meter, obstacle-free, smooth floor area.
  • Set the power switch to 2 and move back to give it room to spin in place and slowly roam while it gathers wheel speed data. 
  • Leave it alone until the P26 and P27 lights turn off (about 2 minutes total time). After that, calibration is complete and you can turn the power off again.

 

What if it Didn't Work?
If your robot didn't move when you started the calibration program, started going backwards first instead of forwards, started and stopped right away, or just twitched instead of moving, go to the Troubleshooting page for help.

Re-starting the Calibration Program
If you need to re-start the calibration process, you can push the reset button any time while the P26 and P27 lights are on. Once the calibration process is complete, the program image gets modified so that it cannot run a second time. This keeps it from trying to re-calibrate the next time you turn power on to load a new program.  If you want to re-run the calibration, you will need to use SimpleIDE to load ActivityBot Calibrate into EEPROM again. 

 

How it Works

This example program turns on the P26 and P27 LEDs with high(26) and high(27).  It then calls the abcalibrate library’s cal_activityBot function, which takes the robot through the sequence of motions you just observed.  While performing the maneuvers, the cal_activityBot function builds a list of wheel speeds that correspond to the various drive levels it applies to the servos.  It stores those values in EEPROM so that every ActivityBot navigation program can use them to find out what drive level is needed for going a given speed.  When the cal_activityBot function is done, the program turns off the P26 and P27 lights with low(26) and low(27).

/*
  ActivityBot Calibrate.c

  Calibrate the ActivityBot's servos and encoders
*/

#include "simpletools.h"
#include "abcalibrate.h"    

int main()
{
  cal_servoPins(12, 13);
  cal_encoderPins(14, 15);
 
  high(26);
  high(27);
  cal_activityBot();
  low(26);
  low(27);
}


Did You Know?

Encoder Ticks - Each ActivityBot encoder shines infrared light at the ring of 32 spokes in the wheel next to it.  If the light passes between the spokes, the encoder sends the Propeller a high signal.  If it bounces off a spoke and reflects back to the encoder’s light sensor, it sends a low signal to the Propeller.  Each time the signal changes from high to low, or low to high, the Propeller chip counts it as an encoder tick.

Sensing Direction — The Propeller chip knows what direction the servos turn based on the signal it uses to make the servo move.  All it needs from the encoder is to know how fast it’s turning. It does this by counting encoder ticks over a period of time.  The libraries keep track of all this for you, so your programs just need to tell the robot robot how far or how fast to go.

 

Interpolation — The cal_activityBot function builds a table of data points for motor drive level and the actual speed the wheels turned.  Navigation programs will use those data points to figure out how hard to drive a wheel to get a certain speed.  If the speed the program asks for is between two data points, the navigation library will figure out the best drive value between two of the known values.  For example, if the table has data points for 60 and 80 encoder ticks per second, and your program asks for 70 ticks per second, the navigation library will use a motor drive level that’s half way between the 60 and 80 ticks per second levels.  This process is called interpolation and the data set is called a linear interpolation table.


 

Try This

You can check to see if the calibration was successful, and if not, see a message that may help diagnose the problem.

You can use the program below to view it.

  • In SimpleIDE, open ActivityBot Display Calibration Results from ...Documents\SimpleIDE\Learn\Examples\Robots\ActivityBot.
  • Set the PWR switch to 1.
  • Then, click the Run with Terminal button.
/*
ActivityBot Display Calibration Results.c
*/

#include "simpletools.h"
#include "abdrive.h"

int main()

{
 drive_calibrationResults();
}

The Terminal will display a message either confirming that your calibration was successful, or a suggestion for troubleshooting your connections if calibration failed.

The function drive_displayInterpolation will display the actual lists of values that are stored in EEPROM. This interpolation table data can be very helpful for troubleshooting if your robot does not drive as expected after calibration.

  • Modify and run the program to display the interpolation table data.


 

Your Turn

Now that your ActivityBot has been calibrated, it is time to run a simple test program to make it drive straight forward.  The test code below makes both wheels turn forward at 64 encoder ticks per second for 4 seconds. This should make your ActivityBot roll forward about 1 meter (3 ft.).

  • Open the program shown below.
/* Forward then Stop.c */
#include "simpletools.h"
#include "abdrive.h"

int main()                    
{
  drive_speed(64, 64);
  pause(4000);
  drive_speed(0, 0);
}
  • Reconnect your ActivityBot to your computer with the USB cable, and set the power switch to 1.
  • Set the COM port, then click the Load EEPROM & Run button.
  • After the program is done loading, set the power switch to 0 and disconnect the USB cable.
  • While holding the reset button down, set the power switch to 2, and set the robot down on a hard, smooth floor.
  • Release the reset button, and monitor the robot’s travel.

Your robot should travel forward for about 1 meter (3 ft.) in a straight line.  You may see slight shifts as the robot adjusts its course based on encoder feedback.

How it Works

First, the lines #include "simpletools.h"and #include "abdrive.h" make the functions of these two libraries available to the program.  ALL of the programs for your ActivityBot with external encoders will need abdrive.h specifically. abdrive360.h will not work. 

Then, inside main, the function drive_speed(64, 64) starts the ActivityBot wheels rotating at a rate of 64 ticks per second.  Once you send your ActivityBot a drive_speed instruction, its servos will turn at the specified rate until it receives another drive... instruction, even while other functions are being executed.  For example, the function pause(4000) elapses while the ActivityBot drives forward at that rate for 4 seconds. Finally, drive_speed(0, 0) makes the wheels stop turning.