During the month of November, my class got the opportunity to learn about and create a robot called the "ActivityBot" as we began our unit on parallax technologies. An ActivityBot is a robot that performs automated tasks (scripts) through a coding program called SimpleIDE.
Meet Sammy; my finished "rabbit" ActivityBot. After completing all of the steps necessary to build him, I began the process of coding him to perform certain tasks. I had a few difficulties, which were fixed in two ways. The first problem I encountered was that my servos did not touch the bottom completely. The second problem was that my wheels were not centered, meaning that one wheel didn't work and it went backwards. To fix this, I ran a code that helped center the wheels through the servos, then began calibration. This helped to make Sammy completely usable.
After centering the wheels, I began the calibration process. Calibration is needed in order to set the robot up for codes. Some of the codes used performed the tasks below.
/*
Piezo Beep.c
Beep a piezo speaker connected to P4.
*/
#include "simpletools.h" // Include simpletools
int main() // main function
{
freqout(4, 1000, 3000); // pin, duration, frequency
}
/*
Test Light Sensors.c
http://learn.parallax.com/activitybot/build-light-sensor-circuits
*/
#include "simpletools.h"
int lightLeft, lightRight;
int main()
{
while(1)
{
high(9);
pause(1);
lightLeft = rc_time(9, 1);
high(5);
pause(1);
lightRight = rc_time(5, 1);
print("%clightLeft = %d, lightRight = %d%c",
HOME, lightLeft, lightRight, CLREOL);
pause(250);
}
}
/*
Blink Light.c
Blink light circuit connected to P26.
*/
#include "simpletools.h" // Include simpletools
int main() // main function
{
while(1) // Endless loop
{
high(26); // Set P26 I/O pin high
pause(100); // Wait 1/10 second
low(26); // Set P26 I/O pin low
pause(100); // Wait another 1/10 second
}
}
In order to pass, we had to code our robots to follow the Waypoint Maze.
#include "simpletools.h"
#include "abdrive.h"
int main()
{
drive_goto(128, 128);
pause(40);
drive_goto(13, -12.5);
drive_goto(118, 118);
pause(40);
drive_goto(-25, 26);
drive_goto(96, 96);
pause(40);
}
After finishing the basics of ActivityBot, we moved on to whiskers. We placed metal whiskers on the bot and coded it so as to interact based on its whiskers being pressed against two 3-pin headers. Below are the codes I used with these whiskers.
/*
Test Whiskers with Terminal.c
Display whisker states in terminal. 1 = not pressed, 0 = pressed.
*/
#include "simpletools.h" // Include simpletools header
int main() // main function
{
freqout(4, 2000, 3000); // Speaker tone: P4, 2 s, 3 kHz
while(1) // Endless loop
{
int wL = input(7); // Left whisker -> wL variable
int wR = input(8); // Right whisker -> wR variable
print("%c", HOME); // Terminal cursor home (top-left)
print("wL = %d wR = %d", wL, wR); // Display whisker variables
pause(50); // Pause 50 ms before repeat
}
}
Using code, I was able to make SimpleIDE's terminal count up to ten.
As I pressed on each whisker, P27 and P26 lit up.
As a whisker touches an obstacle such as a wall, it backs up and turns left to avoid it.
#include "simpletools.h" // Include simpletools
int main() // main function
{
while(1) // Endless loop
{
high(26); // Set P26 I/O pin high
pause(100); // Wait 1/10 second
low(26); // Set P26 I/O pin low
pause(100); // Wait another 1/10 second
}
}
/*
Test Whiskers with LEDs.c
Display whisker states in terminal. 1 = not pressed, 0 = pressed.
http://learn.parallax.com/activitybot/add-whisker-indicator-lights
*/
#include "simpletools.h" // Include simpletools header
int main() // main function
{
freqout(4, 2000, 3000); // Speaker tone: P4, 2 s, 3 kHz
while(1) // Endless loop
{
int wL = input(7); // Left whisker -> wL variable
int wR = input(8); // Right whisker -> wR variable
if(wL == 0) high(26); else low(26); // Light for left whisker
if(wR == 0) high(27); else low(27); // Light for right whisker
print("%c", HOME); // Terminal cursor home (top-left)
print("wL = %d wR = %d", wL, wR); // Display whisker variables
pause(50); // Pause 50 ms before repeat
}
}
/*
Whiskers Push Bot.c
Push the whiskers to make the ActivityBot back up.
http://learn.parallax.com/activitybot/whisker-wheel-response
*/
#include "simpletools.h" // Include simpletools header
#include "abdrive.h" // Include abdrive header
int main() // main function
{
freqout(4, 2000, 3000); // Speaker tone: 2 s, 3 kHz
while(1)
{
// Check whisker states.
int wL = input(7); // Left whisker -> wL variable
int wR = input(8); // Right whisker -> wR variable
// If whisker pressed, back up
if((wL == 0) || (wR == 0)) // Either whisker detects
{
drive_speed(-64, -64); // Back up
}
else // Neither whisker detects
{
drive_speed(0, 0); // Stay still
}
}
}
The Ping))) Ultrasonic Distance Sensor lets the bot detect obstacles and measure the distance to them. The PING))) sensor resembles a mouth and an ear, since it uses ultrasonic to detect the obstacles instead of using a camera.
/*
Detect and Turn from Obstacle.c
Detect obstacles in the ActivityBot's path, and turn a random direction to avoid them.
http://learn.parallax.com/activitybot/roaming-ultrasound
*/
#include "simpletools.h" // Include simpletools header
#include "abdrive.h" // Include abdrive header
#include "ping.h" // Include ping header
int turn; // Navigation variable
int main() // main function
{
drive_setRampStep(10); // 10 ticks/sec / 20 ms
drive_ramp(128, 128); // Forward 2 RPS
// While disatance greater than or equal
// to 20 cm, wait 5 ms & recheck.
while(ping_cm(8) >= 20) pause(5); // Wait until object in range
drive_ramp(0, 0); // Then stop
// Turn in a random direction
turn = rand() % 2; // Random val, odd = 1, even = 0
if(turn == 1) // If turn is odd
drive_speed(64, -64); // rotate right
else // else (if turn is even)
drive_speed(-64, 64); // rotate left
// Keep turning while object is in view
while(ping_cm(8) < 20); // Turn till object leaves view
drive_ramp(0, 0); // Stop & let program end
}
By using a pair of small light sensors, called phototransistors, the bot can measure and compare the light levels on its right and its left. Then, it can turn toward the brighter side as it navigates.
/*
Navigate by Light.c
http://learn.parallax.com/activitybot/roaming-light-sensors
*/
#include "simpletools.h"
#include "abdrive.h"
int lightLeft, lightRight, ndiff;
int speedLeft, speedRight;
int main()
{
while(1)
{
high(9);
pause(1);
lightLeft = rc_time(9, 1);
high(5);
pause(1);
lightRight = rc_time(5, 1);
ndiff = 200 * lightRight / (lightRight + lightLeft) - 100;
speedLeft = 100;
speedRight = 100;
if(ndiff >= 0) speedLeft -= (ndiff * 4);
else speedRight += (ndiff * 4);
drive_speed(speedLeft, speedRight);
}
}
This project makes the bot act like a cat would when it encounters people or objects while roaming around. It uses the PING))) Ultrasonic Distance Sensor to check for obstacles within range. When it detects something, it stops and plays WAV files stored on a microSD card, selecting different files if the obstacle moves out of the way or not.
#include "simpletools.h" // Include simpletools
int main() // main function
{
while(1) // Endless loop
{
high(26); // Set P26 I/O pin high
pause(100); // Wait 1/10 second
low(26); // Set P26 I/O pin low
pause(100); // Wait another 1/10 second
}
}
With its multi-core Propeller brains, the bot plays music or talk while driving, or change direction while talking, while at the same time decoding IR remote signals and monitoring for collisions with obstacle-detecting touch-whisker sensors.
Website used: http://learn.parallax.com/tutorials/robot/activitybot/propeller-c-programming-activitybot