|
[DPRG] Robot Code: subsumption addenda
Subject: [DPRG] Robot Code: subsumption addenda
From: David P. Anderson
dpa at io.isem.smu.edu
Date: Sat Mar 17 11:24:25 CDT 2007
Howdy,
Here are the main() startup sequences from SR04 and
jBot, to give some context to the sensor() loops
posted in the previous subsumption addenda.
/* ---------------------------------------------------------------------- */
/* SR04 */
main()
{
srat_init();
create_process(trace,0,64);
create_process(play_note,0,128);
create_process(sing_songs,0,256);
create_process(sensors,0,512);
create_process(odometers,0,256);
create_process(user_interface,0,512);
create_process(reset_servos,0,64);
scheduler();
printf("should never get here\n");
}
/* ---------------------------------------------------------------------- */
srat_init() takes care of general housekeeping by calling an
initialization routine for each task.
The create_process() function adds tasks to a queue that are part of a
simple cooperative multi-tasker. Its arguments are the function name,
initial parameter, and stack size.
trace() is a function that calculates CPU load information.
play_note() and sing_song() are SR04's FM music synthesizer and
audible warning system. The code itself, for the Motorola HC11,
is available from the Seattle Robotics Society at:
<http://tech.groups.yahoo.com/group/SeattleRobotics/files/FM%20Synthesis%20for%20HC11/>
sensors() is the main sensor loop from the previous posting.
odometers() calculates the robot's position from measurements of the
robot's shaft encoders, and is responsible for determine boundaries
and target distance/heading.
user_interface() runs the LCD status display and reads knobs and
buttons on the robot to enable/disable and configure the individual
tasks.
reset_servos() is an initialization routine that lowers the robot's
motion detector if deployed, and retracts the robot's grippers,
then terminates iteself (i.e. removes itself from the multi-tasking
queue).
The scheduler() initiates the cooperative multi-tasking by setting
up and calling the first function in the queue.
Here is the main() startup code for jBot:
/* ---------------------------------------------------------------------- */
/* jBot */
int main()
{
system_init(); /* cpu, sysclock, lcd, led, sci, interrupts */
jbot_init(); /* behavior inits */
fprintf(stdout,"%s\nHowdy.\n",VERSION); /* serial port */
fprintf(stderr,"%s\tHowdy.\n",VERSION); /* LCD */
create_task(trace,0,64); /* CPU load */
create_task(gui,0,1024); /* user I/O */
create_task(green_led,0,64); /* heartbeat */
// create_task(red_led,0,64); /* commented out, used for radio_good */
create_task(sensors,0,1024); /* main sensor loop */
create_task(odometers,0,1024); /* calculate position */
if (g->sonar_enable)
create_task(sonar_task,0,512); /* sonar array calculations */
create_task(delayed_init,0,128); /* inits that must wait on GPS and IMU */
scheduler(); /* let's go! */
printf("Should never get here\n");
exit(0);
}
/* ---------------------------------------------------------------------- */
Most of the notes for SR04 apply here as well. jBot has a 4-element sonar
array that needs more complex calculations and sequencing than the two sensors
on SR04. That is the job of the sonar_task(). The actual behavior(s) for
this task are the "obstacle()" and "escape()" behaviors listed in the jBot
sensors() loop from the previous subsumption addenda post.
I'd like to emphasize here that the use of a simple home-brew cooperative
multitasker for these robots is a matter of convenience and not necessity.
All the same functions can be implemented without it. The only absolute
requirement is for a realtime clock running at 1000 Hz, which can be
accessed by all the tasks.
best regards,
dpa
More information about the DPRG mailing list
|