help please

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

Moderators: 99jonathan, roger, imaqine

help please

Postby Strike » Wed Apr 25, 2007 4:48 am

how can i use the takeControl method when i work with the ultrasonic and/or light sensor? (i can't give true values)
for example:

Code: Select all

import lejos.nxt.*;
import lejos.subsumption.Behavior;
import lejos.subsumption.Arbitrator;

public class Remi {

    public static void main (String [] args)throws Exception {
       
       //final TouchSensor tacto = new TouchSensor(SensorPort.S2);
       final LightSensor luz = new LightSensor(SensorPort.S1);
       final UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S3);
       
       
       Behavior Avanzar= new Behavior(){
          
       public boolean takeControl(){return true;}   
          
          public void suppress(){
             Motor.A.stop();
             Motor.B.stop();
          }
          
          public void action(){
             Motor.A.forward();
             Motor.B.forward();
          }
       };
       
       
       Behavior Busqueda = new Behavior(){
          
       public boolean takeControl(){return ????;} //here :)
       
          public void suppress(){
             Motor.A.stop();
             Motor.B.stop();   
          }
          
          public void action(){
          while ((sonic.getDistance())<40)
          {
             Motor.A.forward();
             Motor.B.forward();
             if (sonic.getDistance()<5)
             {
                Motor.A.stop();
                Motor.B.stop();
                Motor.C.setSpeed(200);
             }
             
          }
       }
       
   
    };
       
   
       
       Behavior[] bArray={Busqueda, Avanzar};
    (new Arbitrator(bArray)).start();
   
}
}


thanks.
"Esperando la revolución de las máquinas"
Strike
New User
 
Posts: 11
Joined: Wed Mar 28, 2007 5:58 am

Postby bbagnall » Wed Apr 25, 2007 4:24 pm

If you want it to take control when the object is within 25 cm's, use:
return (sonic.getDistance() < 25);
User avatar
bbagnall
Site Admin
 
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm


Return to NXJ Software

Who is online

Users browsing this forum: Baidu [Spider] and 5 guests

more stuff