zteel created page: Week8 Embodied Agents and Adaptive Flocks of Agents authored by Sune Brinch Sletgård's avatar Sune Brinch Sletgård
...@@ -46,6 +46,35 @@ while (!Button.ESCAPE.isDown()){ ...@@ -46,6 +46,35 @@ while (!Button.ESCAPE.isDown()){
*Vehicle 2a/b mounted with light sensors.* *Vehicle 2a/b mounted with light sensors.*
We mouted two light sensors on the vehicle as shown above. To better compare vehicles and connections, we used the right button on the NXT to toggle between vehicle 2a and 2b, as well as the left button to toggle between excitatory and inhibitory connections. We based the engine power calculation on Tom Dean's code. The resulting code is shown below.
```java
public static int motorPowerFromLight(int light) {
int power;
// Remember min and max light
if (light < minLight) {
minLight = light;
} else if (light > maxLight) {
maxLight = light;
}
// Convert scale
power = ((light-minLight)*(maxLight - minLight))/1023;
// Apply min and max power
if (power < minPower) {
power = 0; // Prevents high frequency engine noise
}
power = Math.min(power, maxPower);
if (!isExcitatory) {
power = 100 - power;
}
return power;
}
```
#### Excitatory vs inhibitory behaviour #### Excitatory vs inhibitory behaviour
This time when using excitatory behaviour as in the more light the more motor power, This time when using excitatory behaviour as in the more light the more motor power,
... ...
......