16) Programming the prey robot

6) Programming the Prey Robot

Date: 05/06 2012
Group members participating: Falk, Jeppe and Jakob
Duration of activity: 8 hours

6.1) Goal

Improve the prey by adding an internal state [Bibliography item krink not found.], and program the remote controlled predator.

6.2) Plan

  • For the prey
    • Implement an InternalState class (see [Bibliography item krink not found.]).
  • For the predator
    • Programm it to be remotely controlled by a human user on the pc.

6.3) Results

6.3.1) Implementing InternalState Class

The internal state of a prey is meant to contain information about the internal 'sensors' of the robot, such as hunger, sleep, happiness, scaredness, panic and so on.
The importance to perform actions like "avoid border" or "eat food" is determined by motivation values. Before the motivations were all in an interval from 0 to 100. For some actions the interval should be different. I.e. the motivation for "Eat food" is now in an interval from 0 to 90, since it should not prevent the robot from avoiding close obstacles.

6.3.2) Behaviors

Behaviors have the following motivations.

Behavior Motivation
eatFood 0 - 90
avoidEdge 0, 50 (while avoiding), 100 (on edge)
avoidObst 50 (while running), max(0, 2.5*(15 - dist)
runAway 0, 50 (while running), 100 if IR value > 170 Improvements to Behaviors

Now the robot backs up and turns in the same direction the obstacle was detected at. So when it continues to go forward it drives away from the obstacle.

If the predator is detected, the robot turns 180° and runs away at full speed. Then it turns around again and looks out for the predator.

The wandering was changed, so the robot coveres a wider area of the track. Before it was just turning in smaller circles and did not really wander. Problems

After implementing the internal state, the readings of the color sensor turned out to be very unstable. Sometimes the sensor even showed -1. First this seemed to be a physical problem (shadow, sensor to close to the floor) but it turned out to be an issue in the code. Debugging it, the following results were found:

  • The problem occurs only during "eat food".
  • If returning a constant motivation of 0 the sensor seems to work correctly
  • If eatFood and avoidBorder are the only "active" behaviors, the sensor works.
    • that leads to the assumtion, that there are too many threads (more than 8?) running at the same time
  • When calling the rotateTo methods of the motors (in the HeadTurner and setting it to return immediately, there are more threads started in the background which led to exceeding the maximum number of threads.

To reduce the number of threads and usage of memory, the way rotateTo is called is changed. Instead of calling rotateTo in the HeadTurner every single time a movement order is given to the Mover class, it only calls rotateTo when changing the direction of the head.

public static void turnRight() {
    if ((regMotor.isMoving() && lastDirection != RIGHT) 
        || !regMotor.isMoving()) {
        regMotor.rotateTo(turningDegrees, true);
    lastDirection = RIGHT;

Afterwards the sensor worked as it should.

6.3.3) The Predator

The original idea for building a predator that hits a touch sensor on the prey robots did not turn out to be good. Instead the focus was changed to making the predator push over the prey robot, and the prey can maybe detect if it has been pushed over and stop executing. This means that the design of the predator has to be changed.

The controlling of the predator is intended to be done via bluetooth, but connecting to the NXT using bluetooth was difficult and did not succeed, and has to be tried on a different computer next time.

6.4) Conclusion

If we had time enough, we could implement a variable to indicate the robots fear in the internalState. This could be used to refine the motivation for running away (similar to hunger for EatFood).

Next time the predator should be re-designed, and the bluetooth communication to the predator should be tried with a different pc.

6.5) Movies

The first movie shows the preys driving around without the predator.

In the second movie the effect of the IR ball is tested.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License