marvin:lab8
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
marvin:lab8 [2008/11/09 10:34] – deva | marvin:lab8 [2008/11/14 08:50] (current) – rieper | ||
---|---|---|---|
Line 8: | Line 8: | ||
====Plan==== | ====Plan==== | ||
- | * Modify code by Ole Caprani(([[http:// | + | * Modify code by Ole Caprani(([[http:// |
* Test individual behaviors seperately and re-calibrate constants. | * Test individual behaviors seperately and re-calibrate constants. | ||
* Make modular priority system. | * Make modular priority system. | ||
Line 14: | Line 14: | ||
====Execution==== | ====Execution==== | ||
- | We modified the code to be more modular. This was not part of the exercise, but it made it a lot easier to test individual modules. Below follows | + | We modified the code to be more modular. This was not part of the exercise, but it made it a lot easier to test individual modules. Below follows the modifications made. |
{{marvin: | {{marvin: | ||
- | * The constant '' | + | * The constant '' |
- | * The constants in the thread '' | + | * The constants in the thread '' |
**Video of Marvin running with default code**\\ | **Video of Marvin running with default code**\\ | ||
[[http:// | [[http:// | ||
===RandomDrive=== | ===RandomDrive=== | ||
- | Prints an f on the screen to show the direction of movement. The thread drives forward with different random numbers between 50 and 100 on each motor. This means that Marvin not necessarily (in fact not likely) will drive straight ahead. It will do this between 1 and 3 seconds. Then print s on the screen to indicate a stop and wait between 0.5 and 1 second. All these intervals are computed using a random function from Math library. | + | Prints an "f" (forward) |
===AvoidFront=== | ===AvoidFront=== | ||
- | Implemented using a sonic sensor. Prints a b on the screen to indicate a backwards motion, and set full power to both motors and do this for 1 second to get a away from the obstacle. | + | Implemented using a sonic sensor. Prints a "b" |
===PlaySound=== | ===PlaySound=== | ||
- | This thread waits for 10 seconds, then stops and plays a sound while printing an s on the screen. | + | This thread waits for 10 seconds, then stops and plays a sound while printing an "s" |
====Modular Priority System==== | ====Modular Priority System==== | ||
- | The priority handling was in the initial code created by handing pointers to all lower priority | + | The priority handling was in the initial code created by handing pointers to all lower priority |
<code java> | <code java> | ||
rd = new RandomDrive(" | rd = new RandomDrive(" | ||
Line 38: | Line 38: | ||
ps = new PlaySounds ("Play ", | ps = new PlaySounds ("Play ", | ||
</ | </ | ||
- | This however makes shuffling of the priorities, as well as making the introduction of new Behaviors, | + | This however makes shuffling of the priorities, as well as making the introduction of new behaviours |
Below is the new structure: | Below is the new structure: | ||
<code java> | <code java> | ||
Line 53: | Line 53: | ||
ps = new PlaySounds(" | ps = new PlaySounds(" | ||
</ | </ | ||
- | The idea is to use an array of Behaviors | + | The idea is to use an array of Behavior objects |
this array is copied and stored in the constructor of each Behavior, and can then be iterated whenever suppression of the lower levels are needed. | this array is copied and stored in the constructor of each Behavior, and can then be iterated whenever suppression of the lower levels are needed. | ||
<code java> | <code java> | ||
Line 66: | Line 66: | ||
// Clone the Behavior list. | // Clone the Behavior list. | ||
this.behaviors = new ArrayList(); | this.behaviors = new ArrayList(); | ||
+ | |||
for(int i = 0; i < behaviors.size(); | for(int i = 0; i < behaviors.size(); | ||
Behavior b = (Behavior)behaviors.get(i); | Behavior b = (Behavior)behaviors.get(i); | ||
Line 87: | Line 88: | ||
====Threaded implementation of " | ====Threaded implementation of " | ||
The '' | The '' | ||
- | The wanted | + | The wanted |
- | * suppress lower behaviors | + | * suppress lower behaviours |
* read light values | * read light values | ||
* assign modified light values as motor power (l1 -> m2, l2 -> m1). | * assign modified light values as motor power (l1 -> m2, l2 -> m1). | ||
- | * unsuppress lower behaviors | + | * unsuppress lower behaviours |
Here is the most important code from the class: | Here is the most important code from the class: | ||
<code java> | <code java> |
marvin/lab8.1226223255.txt.gz · Last modified: 2008/11/09 10:34 by deva