Issues with subsumption classes under 0.7

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

Moderators: roger, imaqine, 99jonathan

mpthompson
New User
Posts: 3
Joined: Wed Mar 04, 2009 1:33 am

Issues with subsumption classes under 0.7

Postby mpthompson » Wed Mar 04, 2009 1:46 am

I'm new to Lejos, but not new to Java. I'm running into an issue with the subsumption classes using the 0.7 firmware that has me scratching my head. My code closely follows the behavioral tutorial and the files are shown below. I've added the ultrasonic sensor, but the rest of the code mirrors the tutorial.

My problem is the action() methods of the other behaviors are never called even when their takeControl() methods return true. Are there known problems with the subsumption implementation?

Any help or guidance would be appreciated.

Mike

--------------

Code: Select all

import lejos.subsumption.*;
import lejos.nxt.*;
import java.io.*;

public class DriveForward implements Behavior {
   public boolean takeControl() {
      return true;
   }

   public void suppress() {
      LCD.drawString("Forward suppress", 0, 4);
      Motor.B.stop();
      Motor.C.stop();
   }

   public void action() {
      LCD.drawString("Forward action  ", 0, 4);
      Motor.B.forward();
      Motor.C.forward();
   }
}


Code: Select all

import lejos.subsumption.*;
import lejos.nxt.*;
import java.io.*;

public class TouchObject implements Behavior {
   public TouchSensor touch = new TouchSensor(SensorPort.S2);
   
   public boolean takeControl() {
      return touch.isPressed();
   }

   public void suppress() {
      LCD.drawString("TchObj suppress", 0, 3);
      Motor.B.stop();
      Motor.C.stop();
   }

   public void action() {
      LCD.drawString("TchObj action  ", 0, 3);

      // Back up:
      Motor.B.backward();
      Motor.C.backward();
      try{Thread.sleep(1000);}catch(Exception e) {}
     
      // Rotate by causing only one wheel to stop:
      Motor.B.stop();
      try{Thread.sleep(300);}catch(Exception e) {}
      Motor.C.stop();
   }
}


Code: Select all

import lejos.subsumption.*;
import lejos.nxt.*;
import java.io.*;

public class DetectObject implements Behavior {
   public UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S1);
   
   public boolean takeControl() {
      int distance = sonic.getDistance();
      return distance < 30;
   }

   public void suppress() {
      LCD.drawString("DetObj suppress", 0, 2);
      Motor.B.stop();
      Motor.C.stop();
   }

   public void action() {
      LCD.drawString("DetObj action  ", 0, 2);

      // Back up:
      Motor.B.backward();
      Motor.C.backward();
      try{Thread.sleep(1000);}catch(Exception e) {}
     
      // Rotate by causing only one wheel to stop:
      Motor.B.stop();
      try{Thread.sleep(1000);}catch(Exception e) {}
      Motor.C.stop();
   }
}


Code: Select all

import lejos.subsumption.*;
import lejos.nxt.*;

public class TankBot {
   public static void main(String [] args) {
      LCD.clear();
      Behavior b1 = new DriveForward();
      Behavior b2 = new TouchObject();
      Behavior b3 = new DetectObject();
      Behavior [] bArray = {b1, b2, b3};
      Arbitrator arby = new Arbitrator(bArray);
      arby.start();
   }
}

User avatar
gloomyandy
leJOS Team Member
Posts: 4412
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby gloomyandy » Wed Mar 04, 2009 7:53 am


mpthompson
New User
Posts: 3
Joined: Wed Mar 04, 2009 1:33 am

Postby mpthompson » Wed Mar 04, 2009 4:26 pm

Thank you Andy, it helped a lot.

Suspecting there was a bug that was fixed I actually got it working by pulling the latest Arbitrator class from source repository and compiling it local with my other classes. However, the fix in the thread of just passing "false" as the second parameter is MUCH simpler.

Thanks again for the help.

Mike


Return to “NXJ Software”

Who is online

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