Attendees: Jesper Jakobsen, Mads Hansen Lund and Michael Nygaard Pedersen
Work time: 9.15 - 14.05
Goal
The goal is to investigate the subsumption interface implemented by LeJOS.
Plan
The sumsumption API implements an arbitrator class, which controls which behavior should become active in a behavior control system. The plan for investigation is written beneath.
· Build a differential driven robot with a touch sensor in the front.
· Implement a behavior based architecture with two behaviors using the behavior API implemented by LeJOS. The Behavior API is very simple, and is composed of only one interface and one class.
· Implement a third behavior using the behavior API.
· Investigate the usage of motivation functions and the need for multithread programming.
Results
Description of experiment
Two behaviors
The NXT robot (BumperCar) was programmed to include two behaviours; DriveForward and HitWall.
When started, the BumperCar drives straight ahead until it hits an obstacle which activates the touch-sensor placed in front of the car, making the car drive backwards for approximately 1 second followed by a 300ms turn. Hereinafter the car starts driving forward again.
A variety of different experiments were performed on the BumperCar with these two behaviors implemented.
Press the touch sensor and keep it pressed. What happens?
The car continues to execute the action() defined in the HitWall thread (i.e. the car drives backwards for approximately 1 second and then turns for approximately 300mS, followed by another backwards drive ...etc.) The actions to perform in the HitWall thread are shown below.
public void action() {
// Back up:
Motor.A.backward();
Motor.C.backward();
try{Thread.sleep(1000);}catch(Exception e) {}
// Rotate by causing only one wheel to stop:
Motor.A.stop();
try{Thread.sleep(300);}catch(Exception e) {}
Motor.C.stop();
}
Investigate the source code for the Arbitrator and figure out if takeControl of DriveForward is called when the triggering condition of HitWall is true.
When the HitWall condition is triggered (true), the Arbitrator only calls takeControl() methods of behaviours of higher priority than HitWall, which at the moment does not exist. So takeControl() of DriveForward is not called.
Three behaviors
Implement a third behavior, Exit. This behavior should react to the ESCAPE button and call System.Exit(0) if ESCAPE is pressed. Exit should be the highest priority behavior.
The exit behavior class is shown below.
public class escapeFunc implements Behavior {
public boolean takeControl() {
return Button.ESCAPE.isPressed();
}
public void suppress() {}
public void action() {
System.exit(0);
}
}
The suppress method is empty since the exit behavior is of highest priority, which is declared in the BumperCar class shown below.
public class BumperCar {
public static void main(String [] args) {
Behavior b1 = new escapeFunc();
Behavior b2 = new DriveForward();
Behavior b3 = new HitWall();
Behavior [] bArray = {b2, b3, b1};
Arbitrator arby = new Arbitrator(bArray);
arby.start();
}
}
Three instances of Behavior are created (b1, b2 and b3). These are placed in an array, with the lowest priority behavior taking the lowest array index. Next, the Arbitrator object is instantiated and the arbitration process is started.
Try to press ESCAPE both when DriveForward is active and when HitWall is active. Is the Exit behaviour activated immediately?
When pressing the ESCAPE button while DriveForward is active, the robot application is terminated immediately. But when pressing the ESCAPE button while HitWall is active, the robot does not respond because of the thread.sleep() methods used in the action() method of HitWall (Videos is found under Observations).
Multi threaded programming
If the robot should handle yet another behavior, which implements the ultra sonic sensor more than one thread should be used in order to ensure a certain sample frequency. This approach was not implemented, but is tried briefly explained. The class HitWall is changed beneath to illustrate the idea.
import lejos.robotics.subsumption.* ;
import lejos.nxt.*;
public class HitWall implements Behavior {
public TouchSensor touch = new TouchSensor(SensorPort.S2);
public boolean takeControl() {
return touch.isPressed() || ultraSonicDistance <>
}
public void suppress() {
Motor.A.stop();
Motor.C.stop();
}
public void action() {
// Back up:
Motor.A.backward();
Motor.C.backward();
try{Thread.sleep(1000);}catch(Exception e) {}
// Rotate by causing only one wheel to stop:
Motor.A.stop();
try{Thread.sleep(300);}catch(Exception e) {}
Motor.C.stop();
}
}
The HitWall class will now perform a redundant check, if the variable ultrasonicDistance is updated in its own thread every 20th millisecond.
If the blocking mechanism (observed and explained in the previous subparagraph) should be removed another type of motor control should be used. By studying the LeJOS API the function underneath was found.
| rotate |
This function can be interrupted if another motor method is called, this means that the suppress mechanism must include a motor method in order to stop the active behavior and continue with the behavior with a higher priority if suddenly activated.
Motivation functions
The motivation based behavior selection in agents theory is an extension of the artificial intelligence theory which has been described in lab session 8 and 9. In lab session 8 and 9 the prioritization of the layers was predefined and static. The motivation based behavior selection in agents’ theory handles the layers’ prioritization adaptive with a motivation agent.
The motivation factor can be described from a cheetah’s eating -, hunting - and sleeping behavior. The eating motivation is depending on the energy level, the hunting motivation is depending if there occur prey and the motivation for resting depending on the time. The motivation is dynamical depending on the cheetah needs illustrated from Figure 1.
Figure 1 illustrates that motivation level for the “layers” is dynamic, which leads to different prioritizing of the layers depending on the time. The priority depends on the motivation functions, which differs during the 24 hours. Note that the time axis is modified to have equal length in order to compare the functions properly.
Figure 1: Modified figure from Motivation Networks - A Biological Model for Autonomous Agent Control. The figure illustrates how the prioritization level is shuffling from the motivation factor.
Observations
Pictures of Lego model
Figure 1 - Picture of robot
Conclusion
The subsumption architecture was implemented with a great deal of success. The LeJOS arbitrator API implements usefull subsumption architecture, but it is implemented in a single thread and therefore there is no guarantee that a behavior can be executed at any time.
References
Ref1: ThiemoKrink, Motivation Networks - A Biological Model for Autonomous Agent Control., p.2
Ref2: http://lejos.sourceforge.net/p_technologies/nxt/nxj/api/lejos/nxt/Motor.html
Ingen kommentarer:
Send en kommentar