Test and Tune Your ActivityBot

This page has been removed from the Propeller C Programming with the ActivityBot tutorial.

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 will make both wheels turn at 32 encoder ticks per second for eight seconds.  This will make the ActivityBot go  forward, with both wheels traveling the same distance at the same speed.

Test Code

  • Click SimpleIDE’s Open Project button.
  • Open Test for Trim from ...Documents\SimpleIDE\Learn\Examples\ActivityBot. 
  • Set the 3-position switch to position-1, then click the Load EEPROM & Run button.
  • After the program is done loading, set the 3-position switch to 0 and disconnect the USB cable.
  • While holding the reset button down, set the 3-position switch to position-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 80 cm in a straight line.  You may see slight shifts as the robot adjusts its course based on encoder feedback.

What if it Didn't Work?
If your robot didn't move, or went backwards, or moved in a series of short, jerky arcs instead of heading forward, see the Troubleshooting page.

 

How it Works

Except for pause, which is part of simpletools, all the other calls in this program are to functions in the abdrive library. 

First, drive_trimSet(0, 0, 0) clears any trim settings a robot might already have (such as from a previous student in a robotics class).

Next, drive_speed(32, 32) sets both wheels to go at a speed of encoder 32 ticks (1/2 a turn) per second.  Since it is followed by pause(8000), the servos continue turning at that speed for 8 seconds. Finally, drive_speed(0, 0) stops the servos.

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

int main()                   
{
  drive_trimSet(0, 0, 0);
  drive_speed(32, 32);
  pause(8000);
  drive_speed(0, 0);
}

 


Did You Know?

Updates — The ActivityBot updates the motor speeds 50 times per second, based on encoder feedback, to correct any small differences between how far it should have turned and how far it actually has turned. 

Encoder Ticks and Distance — Each encoder tick makes the wheel travel 3.25 mm forward. Remember, an encoder tick is counted when the encoder sensor detects a transition from spoke to hole or hole to spoke.  Since there are 32 spokes and 32 holes, there’s a total of 64 encoder ticks per wheel turn.

Ramping — Ramping is the term for gradually increasing or decreasing wheel speed so the ActivityBot can ease into and out of maneuvers, instead of starting and stopping abruptly.


 

Try This

Want to go the same distance, but twice as fast? 

  • Click on Save Project As, rename the program Go Faster.
  • Modify the code as shown below.
  • Put the PWR switch to 1, then click Load EEPROM & Run.
  • Set PWR to 0, and disconnect from the USB cable.
  • Now set the robot down again while holding the reset button, set PWR to 2, then let go and watch it drive.

 

Your Turn

The program below lets you see the concept of ramping, both as code and with the robot in action. A for loop and a variable named speed are used to gradually increase and then decrease the rate at which the wheels turn.   The abdrive library also has a built-in functions for ramping, but we’ll use that in a later activity.

  • In SimpleIDE, click Project and then New, and give this program a name.
  • Enter the code below, and then load it into EEPROM.
  • Can you see robot's speed gradually increase, then decrease?
#include "simpletools.h"
#include "abdrive.h"

int main()                    
{
  for(int speed = 0; speed <= 128; speed += 2)  
  {
    drive_speed(speed, speed);
    pause(20);
  }

  pause(2000);

  for(int speed = 128; speed >= 0; speed -= 2)
  {
    drive_speed(speed, speed);
    pause(20);
  }
}