Arbitrator repeats only one Behavior

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

Arbitrator repeats only one Behavior

Postby dendrobates » Fri Jan 17, 2014 3:53 pm

Dear EV3 Developpers

I have programed a robot. It drives autonomous through a track. For this I use Optical Distance Sensors. When I implement it as a thread, everything is fine. But if I add it to the arbitrator it only repeats this behavior and ignores the others. What could be wrong?

Main Class:
Code: Select all
             //Initialize Behavior
        b1 = new DriveForward();
        b2 = new DetectTouchWall();
        b3 = new RoundTime();
        b4 = new QLearning();
        b5 = new Messen();

      Behavior[] behaviorList = { b1, b2, b3, b4, b5
      Arbitrator arbitrator = new Arbitrator(behaviorList);

Messen Class:
Code: Select all
import lejos.hardware.Button;
import lejos.hardware.port.SensorPort;
import lejos.robotics.subsumption.Behavior;

 * Die Klasse Messen ist dazu da die Distanzen zu messen.
 * @author Beat Lichtensteiger

public class Messen implements Behavior {
   private boolean _suppressed = false;
   private OpticalDistanceSensor irLeft;
   private OpticalDistanceSensor irRight;

    * Konstruktor der Klasse. Es wird der Farbsensor und eine Liste
    * instanziiert.
   public Messen() {
      irLeft = new OpticalDistanceSensor(SensorPort.S4);
      System.out.println("Left Sensor ok");
      irRight = new OpticalDistanceSensor(SensorPort.S1);
      System.out.println("Right Sensor ok");


    * Wenn die ColorID sieben (schwart) ist wird die Action aktive. takeControl
    * gibt dann true retour
    * (non-Javadoc)
    * @see lejos.robotics.subsumption.Behavior#takeControl()
   public boolean takeControl() {
       if (Button.readButtons() != 0)
             _suppressed = true;     
             System.out.println("Button pressed");
             if ((Button.waitForAnyPress() & Button.ID_ESCAPE) != 0)
             System.out.println("Button pressed 2");
             System.out.println("Button released");
       return true;  // this behavior always wants control.


    * Ist die systime =0 ist der EV3 zum erstem Mal über die schwarze Linie
    * gefahren und es wird mit der Messung begonnen. Jedesmal beim passieren
    * der Linie wird die Rundenzeit zur Liste hinzugefügt und ins File
    * geschrieben.
    * (non-Javadoc)
    * @see lejos.robotics.subsumption.Behavior#action()
   public void action() {
      while (!_suppressed) {
         System.out.println("In Messen");
         MND.addToLog("Start Measure");
         // Delay.msDelay(200);
         int inL = irLeft.getDistLSB();
         // System.out.println("Links input:" + inL);
         int inR = irRight.getDistLSB();
         // System.out.println("Rechts input:" + inR);
         // try{Thread.sleep(100);}catch(Exception e){}
         MND.addToLog("End Measure");


    * (non-Javadoc)
    * @see lejos.robotics.subsumption.Behavior#suppress()
    * Supress heat keine Funktionalität implementiert,
   public void suppress() {
      _suppressed = true;// standard practice for suppress methods


Tanks for your help

Kind regard
New User
Posts: 16
Joined: Tue Sep 10, 2013 7:08 am

Re: Arbitrator repeats only one Behavior

Postby M13 » Fri Jan 17, 2014 4:18 pm

Tach auch :D

I'm new to leJOS as well, but as far as I could see until now from the Arbitrator/Behavior classes, the problem here is that the Behaviors have an "implicit" priority (also see their implementation in ... bsumption/ ).

The LAST behavior has the HIGHEST priority. Your LAST behavior, 'Messen', always returns 'true' in 'takeControl'. So the Arbitrator always executes only this Behavior, because it has highest priority and always wants to take control.

You may want to compare your implementation to the "Bumper Car" sample: ... There are two Behaviors:
First one (lowest priority): "DriveForward" - always returns 'true' in 'takeControl'
Second one (highest priority): "DetectWall" returns 'true' in 'takeControl' ONLY when there really is a wall

I think it should be possible to transfer this pattern / the basic idea to your program as well.
New User
Posts: 4
Joined: Thu Jan 16, 2014 9:56 pm

Return to EV3 Software

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

more stuff