Download Distributed Behavior-Based Control Pioneer Mobile Robots
Transcript
}
ayDefBehaviorClass(DelayedStarter)
{
ayINTERFACE {
ayIntPort(StopCommand, 0);
ayIntPort(Switch, 0);
ayMonostable(StartDelay, seconds(10));
}
ayPROCESSES {
ayInitProcess(delayafterswitch, ratepersecond(20));
}
}
/*
*** Safe Velocity Behavior ***
*/
/* Sets the translational velocity of the robot to the maximum
safe value - avoids collisions with walls and other robots */
ayDefProcess(sonarwatcher)
{ ayLocalPort MinSonar, VelCom;
int min, speed;
min = ayReadIntPort(MinSonar);
speed = MAX_SPEED;
if (min < DANGER_DISTANCE)
speed = BACKUP_SPEED;
else if (min < SAFETY_DISTANCE)
speed = (min - DANGER_DISTANCE) * MAX_SPEED
/ (SAFETY_DISTANCE - DANGER_DISTANCE);
ayWriteIntPort(VelCom, speed);
ayWriteIntPort(MinSonar, MAX_SONAR_READING);
return;
/* Reset MinPort */
}
ayDefProcess(SafetyReport)
{ ayLocalPort MinSonar, VelCom;
printf("Min Sonar is %i, Velocity Command is %i\n",
ayReadIntPort(MinSonar), ayReadIntPort(VelCom));
return;
}
ayDefBehaviorClass(SafeVelocity)
{
ayINTERFACE {
ayIntMinPort(MinSonar, MAX_SONAR_READING);
ayIntPort(VelCom, 0);
}
ayPROCESSES {
ayInitProcess(sonarwatcher, ratepersecond(4));
ayInitProcess(SafetyReport, ratepersecond(1));
}
}
/*
*** Shutdown Behavior ***
*/
/* Turns off robot and quits program when a key is hit */
ayDefProcess(StopWhenKeyHit)
{ if (kbhit()) ayStopBehaviors(); /* This is the Macintosh function - */
return;
/* use a similar non-blocking fn
*/
Extended Examples
51