marvin:lab8
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
marvin:lab8 [2008/11/09 10:21] – deva | marvin:lab8 [2008/11/09 10:34] – deva | ||
---|---|---|---|
Line 11: | Line 11: | ||
* Test individual behaviors seperately and re-calibrate constants. | * Test individual behaviors seperately and re-calibrate constants. | ||
* Make modular priority system. | * Make modular priority system. | ||
- | * Investegate | + | * Investigate |
====Execution==== | ====Execution==== | ||
Line 17: | Line 17: | ||
{{marvin: | {{marvin: | ||
- | * The constant tooCloseThreshold was initially set to be 20 cm, but this was not enough to take into account our modified Marvin which has a plate seperating | + | * The constant |
- | * The constants in the thread RandonDrive.java has been change to accomdate | + | * 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 nessesarily | + | 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 |
===AvoidFront=== | ===AvoidFront=== | ||
- | Implemented using a sonic sensor. Prints a b on the screen to indecate | + | Implemented using a sonic sensor. Prints a b on the screen to indicate |
===PlaySound=== | ===PlaySound=== | ||
Line 38: | Line 39: | ||
</ | </ | ||
This however makes shuffling of the priorities, as well as making the introduction of new Behaviors, a very tedious task. We therefore rewrote the priority system to make it more modular and flexible.\\ | This however makes shuffling of the priorities, as well as making the introduction of new Behaviors, a very tedious task. We therefore rewrote the priority system to make it more modular and flexible.\\ | ||
- | Below is the new stucture: | + | Below is the new structure: |
<code java> | <code java> | ||
ArrayList behaviors = new ArrayList(); | ArrayList behaviors = new ArrayList(); | ||
Line 55: | Line 56: | ||
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> | ||
- | private ArrayList behaviors;; | + | private ArrayList behaviors; |
public Behavior(String name, ArrayList behaviors) | public Behavior(String name, ArrayList behaviors) | ||
Line 79: | Line 80: | ||
} | } | ||
</ | </ | ||
+ | The code in its entirety can be found in the '' | ||
====Java Thread==== | ====Java Thread==== | ||
The '' | The '' | ||
- | |||
====Threaded implementation of " | ====Threaded implementation of " | ||
- | Bent writes this part | + | The '' |
+ | The wanted behavior is the following: | ||
+ | * suppress lower behaviors | ||
+ | * read light values | ||
+ | * assign modified light values as motor power (l1 -> m2, l2 -> m1). | ||
+ | * unsuppress lower behaviors | ||
+ | Here is the most important code from the class: | ||
+ | <code java> | ||
+ | private LightSensor l1; | ||
+ | private LightSensor l2; | ||
+ | private int offset = 60; | ||
+ | |||
+ | public DriveTowardsLight(String name, ArrayList behaviors) | ||
+ | { | ||
+ | ... | ||
+ | l1 = new LightSensor(SensorPort.S2); | ||
+ | l2 = new LightSensor(SensorPort.S3); | ||
+ | l1.setFloodlight(false); | ||
+ | l2.setFloodlight(false); | ||
+ | } | ||
+ | |||
+ | public void run() | ||
+ | { | ||
+ | while (true) | ||
+ | { | ||
+ | // Read value from light sensors | ||
+ | int val1 = l1.readValue() + offset; | ||
+ | int val2 = l2.readValue() + offset; | ||
+ | |||
+ | suppressLower(); | ||
+ | forward(val2, | ||
+ | delay(500); | ||
+ | unsuppressLower(); | ||
+ | } | ||
+ | </ | ||
+ | This code however would take over entirely the control of the car since it is active all the time.\\ | ||
+ | We therefore introduced a light threshold to make the car search for light, only when there is some light to search for.\\ | ||
+ | the code for that is shown below: | ||
+ | <code java> | ||
+ | private int threshold = 80; | ||
+ | |||
+ | public void run() | ||
+ | { | ||
+ | . | ||
+ | . | ||
+ | . | ||
+ | |||
+ | if(val1 > threshold || val2 > threshold) { | ||
+ | suppressLower(); | ||
+ | forward(val2, | ||
+ | delay(500); | ||
+ | unsuppressLower(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | The code in its entirety can be found in the '' | ||
**Video for "Drive towards light test" | **Video for "Drive towards light test" | ||
Line 91: | Line 147: | ||
====Conclusion==== | ====Conclusion==== | ||
- | The layered behavior model seems to work very well for the implementation of an autonomous | + | The layered behavior model seems to work very well for the implementation of an autonomous |
marvin/lab8.txt · Last modified: 2008/11/14 08:50 by rieper