| Chasing a Ball Example Last Modified: 2006-11-14 | | |
| Acroname Robotics | PDF webpage version | ||
| Introduction In this example, a BrainStem PPRK robot chases a ball. It can implement the ball-chasing behavior with a single TEA program. Source Code The robot spins clockwise until one or more of its sensors detects an object. A bit is set in a flag variable for each sensor that has a detection. By looking for specific flag values, the robot can determine when only one of its sensors detects an object. When the robot detects something in front of one sensor, it stops spinning and starts to move in the direction of the detected object. If more than one sensor detects an object, the robot just keeps spinning since it can only chase in one direction. If the robot loses the detection, it will start spinning again to look for an object. If there is one object nearby, the robot will find it and move towards it. If the object is a ball, the robot will move towards it and eventually push it. When it pushes the ball out of the sensor field of view, it will spin to reacquire the ball. /* filename: chase.tea */
/* BrainStem PPRK Program */
/* Move toward sensor detection, otherwise spin */
/* Can chase a ball or another robot */
#include <aCore.tea>
#include <aPPRK.tea>
#include <aA2D.tea>
#define SPEEDR 100
#define SPEEDL 100
#define DRANGE 175
void main()
{
int b;
int r1;
int r2;
int r3;
/* five second wait before starting */
aCore_Sleep(30000);
aCore_Sleep(20000);
while (1)
{
r1=aA2D_ReadInt(APPRK_IR1);
r2=aA2D_ReadInt(APPRK_IR2);
r3=aA2D_ReadInt(APPRK_IR3);
b=0;
if (r1>DRANGE) b = b | 1;
if (r2>DRANGE) b = b | 2;
if (r3>DRANGE) b = b | 4;
switch (b)
{
case 1:
aPPRK_Go(0,SPEEDL,-SPEEDL,0);
b=1;
break;
case 2:
aPPRK_Go(-SPEEDL,0,SPEEDL,0);
b=1;
break;
case 4:
aPPRK_Go(SPEEDL,-SPEEDL,0,0);
b=1;
break;
default:
b=0;
break;
}
if (b==0)
{
aPPRK_Go(0,0,0,SPEEDR);
}
else
{
aCore_Sleep(5000);
aPPRK_Go(0,0,0,0);
aCore_Sleep(5000);
}
}
}
Revision History:
| |||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2008 Acroname, Inc., Boulder, Colorado. All rights reserved. |