Download Reactive - Embedded Intelligent Robotics - Lecture Slides and more Slides Robotics in PDF only on Docsity!
Reactive
Control with
Interactive C
Docsity.com
Outline
- Multi-Tasking
- Subsumption Architecture
- Priority-Based Control Program
- How the Prioritization Algorithm Works
- Using Reactive Control
- Robo-Miners
- Collecting Soda Cans
- Reactive Groucho
- Extending the Prioritization Framework
Docsity.com
Multi-Tasking
- Arrows indicate a path of priority among three processes.
- Touch has the highest priority, followed by Turn and then Wander.
- This ordering makes sense because while the robot’s wandering about, if it hits something, the
obstacle avoidance should take precedence over the wandering.
Highest priority
Docsity.com
Multi-Tasking in Interactive C (IC)
- IC comes with the ability to multi-task , or run several programs at once
- Ideal for reactive robot programming, where the robot has several “behaviors”
running at the same time
- As it stands, sensor_beep() will never run, because the computer would
be stuck in an infinite loop performing back_and_forth()
void main ()
back_and_fort
h();
sensor_beep()
void back_and_forth () {
while (1) {
fd(0); msleep(500L);
bk(0); msleep(500L);
void sensor_beep () {
while (1) {
if (analog(0) < 100) b
Docsity.com
Priority-Based
Control Program
- Creates priority-based, multi-tasking robot programs
- Example program:
- priority.c, contains the prioritization code
- plegobug.c, contains standard movement and touch sensor routines for the HandyBug robot; i.e., forward(), backward(), left(), right(), left_touch(), and right_touch()
- lb1task.c, contains one robot behavior
- Generic touch sensor program: simple, clear, only deals with issues that concern the task
- Need a prioritization structure to prevent conflicts
- Assign each task a process number & priority level:
- Process numbers identify task when issuing motor commands; allows prioritization routine to identify motor commands of each different task
- Priority level allows tasks with higher priority to supersede tasks with lower priority
/* generic touch sensor pro
void touch () {
while (1) {
if (left_touch()) {
backward(); msleep(
right(); msleep(500L);
else if (right_touch()
backward(); msleep
left(); msleep(500L
Docsity.com
Priority-Based
Control Program
/* touch sensor process */
void touch (int pid) { while (1) { if (left_touch()) { enable(pid); backward(pid); msleep( right(pid); msleep( disable(pid); } else if (right_touch enable(pid); backward(pid); msle left(pid); msleep( disable(pid); } } }
Rewritten Touch Sensor Task:
- pid = process ID (process identifier) argument is used in movement commands to indicate which process is requesting which motor command s
- Pair of commands used to enable and disable a process’s functioning
- Separately (and in parallel), prioritization routine determines which process is enabled and has the highest priority, and then issues movement commands selected by that process to motors
- If a process has enabled itself and it has the highest priority of all enabled processes, then its movement commands get to run
- Disable(pid): issued after each set of movement commands that react to a touch sensor press
- Process must disable itself when done so that other processes that have lower priority get a chance to operate
- If not, then process would have control of the robot even if it were not issuing any movement commands (unless a process with higher priority were active)
Docsity.com
Priority-Based Control Program
Try out on HandyBug:
- Load the file lb1task.lis , which loads the files lb1task.c, plegobug.c,andpriority.c
- In plegobug.c, motor and sensor wiring connections are defined:
- left motor in motor port 0,
- right motor in motor port 3,
- left touch sensor in digital port 7,
- and right touch sensor in digital port 8.
•With the full program running, notice that HandyBug just sits there unless a touch sensor is pressed.
•That’s because when the touch sensors are not pressed, the touch() process is disabled, and since it’s the only control task, therefore no control tasks are active.
•The prioritize() routine realizes that no tasks are active, and it shuts the motors off and displays the message “No tasks enabled.” Docsity.com
Priority-Based Control Program
- When a touch sensor is pressed , then the touch sensor task enables itself and issues motor
commands to back up and turn away from the direction of contact.
- While the touch sensor task is active, prioritize() issues its motor commands to the motors,
and displays the message “Running touch.”
- HandyBug as an artificial creature: it can get out of the way if something hits its.
- HandyBug doesn’t go anywhere on its own, but if something comes and bother it, it will
move.
- The prioritization scheme we have been using thus far does not support one task taking
advantage of another’s capabilities; it only allows one task to override
- (or suppres s, in Brooks’ language) another.
•But it provides a good start in working with the types of ideas Brooks has developed.
Docsity.com
Priority-Based Control Program
Type Coercion:
- seconds() routine reports the elapsed time as a floating point number; e.g., 53.374 sec.
- By prefacing the functional call with “(int),” this floating point value is converted to an
integer value (e.g., 53).
- Necessary so that we may use the “%” operator, which is the arithmetic modulus function
“(int)seconds() % 10” means, “take the elapsed system time, convert it to an integer,
and report the remainder after dividing by 10”
- This provides a number from0 to 9; the rest of the if statement simply compares this value
with 9
- Thus, in the final second of every ten second period, the full expression yields a true, and the
clause of the if statement runs
- Reason for use: IC does not have a modulus operator that works on floating point numbers.
- It does support floating point division, but not remainder. So the conversion to integer is used
to circumvent this limitation.
Docsity.com
Priority-Based
Control Program
/* lb3task.c main program for LEGObug and three tasks: periodic_turn, touch and wan void main () { int pid= 0; /* touch sensor / process_priority[pid]= 3; process_name[pid]= "Touch"; start_process(touch(pid++)); / periodic turn / process_priority[pid]= 2; process_name[pid]= "Turn"; start_process(periodic_turn(pid++)); / wander / process_priority[pid]= 1; process_name[pid]= "Wander"; start_process(wander(pid++)); / motor arbitration process / num_processes= pid; start_process(prioritize()); } / wander process: just go forward */ void wander (int pid) { enable(pid); forward(pid); }
Add a Wander Task:
- Simply drives straight ahead
- “Wandering” will happen because periodic_turn() will kick in every ten seconds, causing HandyBug to veer from a straight-line path.
- Notice: no loops are needed to work: it simply enables itself, and sets its movement command as drive forward.
- wander() is installed in the standard way with a priority of 1, the least among the three processes now installed.
- Load lb3task.lis to give it a try.
- Now HandyBug is a full-fledged explorer robot, able to roam about a room, a back up and turn away from any obstacles in its way—after hitting into them, of course!
Docsity.com
Data Structures: process_name[] holds the process names as set up by main() process_priority[] holds the fixed priority values as assigned to the processes in main() process_enable[] holds dynamic enable values
- Touch is enabled, since its priority level has been copied into the process_enable[] array. Turn is disabled, and Wander is always enabled Left_motor[] and right_motor[] hold values assigned by the behavior tasks
- Even though Turn is disabled, its entries are still present in the motor arrays from a previous time. No need to clear them out
Active_process assigned by prioritize(), is zero, indicating that the process with an index 0—the touch sensor process—is active.
How the Prioritization Algorithm Works
Docsity.com
Code:
- Enable: copy process’s priority level, which is stored in process_priority[], into “enabled” array
- Disable: zero stored in process’s position in process_enable[] array
- Prioritize: Initialize local variable max=0, then scan process_enable[] array, looking for the process with the highest priority level.
- If max =0 after looking through all of the installed processes, then none of them is enabled. In this case, both motors are turned off, and the message “No tasks enabled” is displayed on the LCD screen.
- If max>0: then at least one process is enabled.
- The next step is to again search through the list of processes, and find one with a priority that matches the maximum value.
/* priority.c: arbitration program for multi-behavior robot control / / define process tables / int process_priority[10]; int process_enable[10]; char process_name[0][10]; / define motor output tables / int left_motor[10]; int right_motor[10]; / globals */ int num_processes= 0; int active_process= 0;
/* set process_enable entry to process void enable (int pid) { process_enable[pid]= process_prio } /* set process_enable entry to 0 */ void disable (int pid) { process_enable[pid]= 0; }
How the Prioritization
Algorithm Works
Docsity.com
HandyBug Movement and Touch Routines: /* plegobug.c: movement and touch sensor commands for LEGObug with priority.c / / motor and sensor ports / int LEFT_MOTOR_PORT= 0; int RIGHT_MOTOR_PORT= 3; int LEFT_TOUCH_PORT= 7; int RIGHT_TOUCH_PORT= 8; / movement commands */ void forward (int pid) { left_motor[pid]= 100; right_motor[pid]= 100; } void backward (int pid) { left_motor[pid]= -100; right_motor[pid]= -100; } void right (int pid) { left_motor[pid]= 100; right_motor[pid]= -100; }
void left (int pid) { left_motor[pid]= -100; right_motor[pid]= 100; } void halt (int pid) { left_motor[pid]= 0; right_motor[pid]= 0; } /* sensor functions */ int left_touch () { return digital(LEFT_TOUCH_PORT); } int right_touch () { return digital(RIGHT_TOUCH_PORT); }
How the Prioritization Algorithm
Works
Docsity.com
Using Reactive Control: Robo-Miners
- Table Structure:
- had central raised platform with air hoses underneath
- At start of game, balls were placed in each of the four air streams emanating from hoses
- Additional balls placed at various other points on the table surface and edges
1995 MIT Robot Design contest
points
awarded for
collecting
balls,
balls into
one’s goal
area
collected
balls