# Homework 2 - Coding the Behavior-Based Approach

## Due Wednesday, February 26, 2003

NOTE: This assignment, UNLIKE others in this class, cannot be turned in late for partial credit. This is because I want to post a solution immediately after class on Wednesday, February 26, so that you can have most of two days to study the solution before your exam on Friday, February 28. This means that if you are even a minute late, you lose 100%. If you are worried about potentially being late, turn in your homework ahead of time. Do this by submitting them to me during office hours or by sliding it under my office door. Do not send assignments to me through email or leave them in my departmental mail box.

In class we covered an example of coding the behavior-based approach borrowed with modifications from Joseph L. Jones, Anita M. Flynn, and Bruce A. Seiger, Mobile Robots: Inspiration to Implementation, Second Edition, Section 9.5, Behavior Control in IC, pages 302-306, A. K. Peters, 1999. This code has also been posted to the class web pages for your review. In class we discussed modifying this code in order to improve it and adapt it in various ways. Modifying such code, or producing our own, can be very useful exercises to help us understand the principles of the approach.

## The assignment.

The code, as given, is incomplete. In particular, the motor control function called `motor_driver` is called by `arbitrate` and assumed to exist, yet the code for `motor_driver` is not given.

Exercise 1. Write the code for `motor_driver`, assuming that your target robot has two motors, one connected to each of two drive wheels and a caster for balance.

One difference between the code you have just augmented and the subsumption architecture of Brooks is that the code abstracts away the motor commands from the functions in which sensing is done and places them in the centralized motor control function called `motor_driver` that you have just created.

Exercise 2. Rewrite the code to more closely match the subsumption architecture approach by eliminating the difference just discussed.

One feature of the subsumption architecture is that layers may inhibit and/or suppress other layers. However, in the given code, only one of these is done.

Exercise 3a. Answer the following questions and explain your answers:

1. Does the code given show inhibition or suppression?
2. Would it be reasonable for any of the layers given to do whichever of these two (inhibition or suppression) is not found in the given code? (That is, if you said inhibition is not found in the given code, would it be make sense to add it anywhere, given the idea behind each layer? Alternately, if you said suppression is not found in the given code, would it be make sense to add it anywhere, given the idea behind each layer?)

Exercise 3b. Regardless of whether you said it would be reasonable, modify the code to show an example of the missing subsumption architecture feature under discussion. Be sure to do this in a general way so that it would be easy (whether reasonable or not) to add examples of other layers subsuming control in this way.

The subsumption architecture is only one way of implementing behavior-based control. The other method we covered in depth in this class was schema theory. In the version of schema theory we covered, each behavior is divided into a perceptual schema and a motor schema.

Exercise 4. Starting again from the code as given on the class web pages, modify it to conform to this aspect of schema theory. Use the same assumption regarding the target robot platform that you used in exercise 1.

One purported advantage of schema theory over the subsumption architecture is that schema theory promotes code reuse and easy modification if the hardware changes, whereas the subsumption architecture does not because it is so closely tied to the hardware. Here is your chance to verify it for yourself, at least for one particular case.

Exercise 5a. Answer the following questions and explain your answers:

1. If you were to replace the motor setup described above with an adder-subtractor transmission (in which one motor drives the vehicle forward or backward and the other causes it to rotate left or right and their combination causes it to move in arcs of one sort or another), how many functions could be reused without change from the code as given on the web pages?
2. If you were to replace the motor setup described above with an adder-subtractor transmission, how many functions from the code as given on the web pages would need to be changed?
3. If you were to replace the motor setup described above with an adder-subtractor transmission, how many functions could be reused without change from the code you produced in exercise 2?
4. If you were to replace the motor setup described above with an adder-subtractor transmission, how many functions from the code you produced in exercise 2 would need to be changed?
5. If you were to replace the motor setup described above with an adder-subtractor transmission, how many functions could be reused without change from the code you produced in exercise 4?
6. If you were to replace the motor setup described above with an adder-subtractor transmission, how many functions from the code you produced in exercise 4 would need to be changed?
7. Given your answers to the previous six questions and any additional analysis you care to provide, which version of the code best promotes code reuse and easy modification?

Exercise 5b. Given your answer to question seven in part a of this exercise, choose the easiest code version to modify and modify it to accommodate an adder-subtractor transmission.

The previous versions of the code we have been dealing with all combine the output of the behaviors by simple replacement. That is, a dominant behavior will prevent another behavior from taking its normal action. Another possibility is to have the output of these behaviors fused additively. That is, we could add together the output of two or more behaviors to get a single resultant output motion. For example, adding together a FORWARD and a LEFT_TURN command might be equivalent to a LEFT_ARC command while adding a LEFT_ARC and a RIGHT_ARC command might yield something equivalent to a FORWARD command.

Exercise 6. Choose any version of the code above that you wish and modify it to use additive behavioral fusion. Indicate which version you have chosen and why. You may define the results of the combinations in any way you choose, as long as it is reasonable and general. (It isn't reasonable to add together a FORWARD and a LEFT_TURN command to give something equivalent to a BACKWARD command, for example. Moreover, to make it general, you should consider what would happen if you added many more behaviors to the system and needed to add together one FORWARD command and a couple of dozen LEFT_TURN commands, and so forth.)

## What to turn in.

Turn in a typed copy of your answers to these questions. In total, your answers should run from 1.5 to 2 pages in length (roughly 80 characters per line, 50 lines per page). This does not count any figures that you may choose to include, which may be of any size. It also does not count the modified code itself, just the text accompanying it.