MCB419 logo  




Homework

MCB 419 Homework 4 (Spring 2008)


Questions appearing in red are to be answered in the hw04.txt file.

When you've finished the assignment, email your responses to as a plain text file, and attach a copy of your project file.

Email to mcb419@gmail.com with 'hw04' in the Subject line.

The homework is due by 11:59PM on Tue, Feb 12.


Integrating multiple behaviors

SwimmingCarrots

SwimmingCarrots
Integration of multiple behaviors: food taxis, phototaxis, and collision response
(in an organism that bears an uncanny likeness to a familiar edible root).

The project file above includes an 'aquarium' with a light gradient, a carrot-shaped 'bot' with two sensors, some green 'food' pellets, a 'rock' in the middle of the aquarium, and a 'stick' that you might find useful for prodding your bot. (You can take the stick out of the aquarium when it's not in use...but the rock should stay there.)

The sensors (snsL and snsR) have an activation variable that is related to the proximity of food bits (useful for food taxis). The sum and difference of the sensor activation levels are available as the bot's variables snsSum and snsDiff. The sensors can also be used to monitor light intensity (brightness under) and for collision detection (e.g., bot's colorA sees colorB). The tank boundaries, rock, stick, and bot's sensors all share the same color (brown). The default controller code just makes the bot swim in a circle...boring.

Food bits appear at the top of the tank and drift downward. When a food bit is 'consumed' or when it has drifted down to the bottom third of the tank it will be 'recycled' and will reappear at the top of the tank after a delay. So, once you've clicked the 'addFood' button 5 times, there will always be 5 food bits in the simulation...but some bits may not be visible during the 'recyling' delay.


Your assignment

Develop new controller code for the bot satisfying the following behavioral criteria:

  1. when no food is present, the bot should hover near the top of the tank facing upward (as if waiting for food to appear).
  2. when food appears near the bot, the bot should rapidly approach and consume it
  3. when the bot collides head-first with an obstacle (e.g. walls, rock, stick), it should back up and turn for approx. 1-2 seconds in a manner similar to the Paramecium collision response from last week

To make this happen, you'll need to find a way to integrate the food taxis, phototaxis and collision response behaviors appropriately.


A bot hovering near the surface,
'waiting' for food to appear.

Two bots foraging for food bits.
Bots turn red to 'strike' at the food.

Additional programming requirements/restrictions

Your solution must also satisfy the following programming rules:

  1. You cannot use the commands forward by and turn by directly in your code. Instead, you must set the bot's speed and turnAngle variables. Once these variables have been set, calling the doMovement script will execute Bot forward by speed and Bot turn by turnAngle, while imposing constraints that the absolute value of the velocity is less than 20 and the absolute value of the turnAngle is less than 15 (per tick).
  2. The doMovement script should only be called ONCE per clock tick. Leave it in the 'behavior' script...don't call it from other scripts.
  3. Do not use the bounce function.
  4. You cannot use the bot's x, y, or heading variables in your controller code. Your bot only knows about its relation to the external world through the information it gets from its two sensors.
  5. Modularity: you should code each individual behavior as a separate Squeak script (e.g. you might name them foodTaxis, photoTaxis, and collisionResponse); each script should set/modify the speed and turnAngle variables. Then you'll then need to modify the setSpeedAndAngle script to integrate the three behaviors appropriately. For example, if setSpeedAndAngle only called the photoTaxis script, then the bot should exhibit the hovering behavior, but not food taxis or collision response. Integrating the behaviors will likely require one or more Test blocks. For example:
    Test Bot's snsSum > 0.1
       Yes foodTaxis
       No  photoTaxis
    
  6. Do not attempt to change the color of the bot's body. The body color is already being used as part of the 'food capture' algorithm this week.

Notes/tips

  • When you click the 'addBot' button this week, it creates a 'duplicate' of the bot, rather than a 'sibling' (the reason we need a 'duplicate' is related to the embedded sensors). The practical importance of this change is that when you edit the bot's script, the changes will not automatically propagate to other bots that are already in existence. Also, you should not use 'tell all siblings' or 'bots copy' (which creates a sibling).
  • Because of the 'duplicate' vs. 'sibling' issue mentioned above, the easiest way to develop your controller code will be to drag the original bot out of the holder and drop it in the playfield. To activate the bot, open it's viewer and click on the clock next to the 'behavior' script to change it from 'normal' to 'ticking'. You can now use the STOP/STEP/GO buttons as usual and edit/test/debug your controller code. When you are finished, change the state of the 'behavior' script back to 'normal'. Then drag the bot back into the holder.
  • Sometimes when you manually move the bot around with the mouse, particularly during rotations, the sensors may become displaced from the body. If this happens, activate the 'repositionSensors' script once (click the yellow button with the exclamation mark).
  • A couple of the scripts this week (doMovement and makeDuplicate) use textual smalltalk code, rather than etoys programming tiles. (Any etoys script can be displayed as smalltalk code using the 'show code textually' menu option in the script window; however, if a script is originally written directly as smalltalk code, it cannot be converted back to etoys tiles; that's the case for two of the scripts this week.) When you run across a textual script, don't panic...you won't need to modify that script to complete the assignment.

Questions

1. When food is 'recycled' it disappears for a while and then reappears a short time later at the top of the aquarium. Based on your examination of the code, explain what happens to the food particle during the 'recycle' phase. How would you change the code to make the particle reappear immediately at the top of the tank?

2. What was the main challenge you faced when trying to integrate all three behaviors into your bot? In the future, if you wanted to add more behaviors (e.g. predator avoidance, hiding, fighting, courtship, mating, nesting, parenting, etc.) what do you think would become the major programming bottleneck for your project...implementing the individual behaviors, or integrating them together?

3. When a single bot is foraging in the tank, what is the 'dumbest' thing that you see it do? What sort of change in the controller would be needed to avoid that sort of 'dumb' behavior?

4. Describe what happens when you add 2 or 3 bots to the aquarium at the same time, along with a few bits of food. Based on behavioral observation alone (without knowing what's inside the controller program), would you say that there are 'competitive interactions' between the bots?



Copyright © Mark E. Nelson, University of Illinois at Urbana-Champaign, 2005-2008. All rights reserved.