1) drive randomly
2) drive to target
3) avoid obstacle
first problem is with random movement, to make it move at random I use two comands
- Code: Select all
NavClass.nav.rotate((float)( (Math.random() - 0.5) * 90));
NavClass.nav.travel( (int)(Math.random() * 20) );
but I don't know how to loop them in behavior with out creating infinite loop
second problem is with other two behaviors, my target is point (100, 100), and behavior 2 is simply
- Code: Select all
import josx.robotics.*;
import josx.platform.rcx.*;
public class DriveToTarget implements Behavior {
public boolean takeControl() {
return true;
}
public void suppress() {
NavClass.nav.stop();
}
public void action() {
//Sound.twoBeeps();
NavClass.nav.gotoPoint(100,100);
}
}
(takeControl() returns true only in current example because of the first problem (random movement))
and behavior 3
- Code: Select all
public class HitWall implements Behavior {
public boolean takeControl() {
return !Sensor.S3.readBooleanValue();
}
public void suppress() {
Sound.beep();
}
public void action() {
NavClass.nav.travel(-10);
NavClass.nav.rotate(45);
NavClass.nav.travel(10);
}
}
the problem is that when my robot hit something it avoids obstacle and starts to move to (100,100) point but never reaches it, it stops in about (90,90) point, but LCD.showNumber() shows (100,100), the more obstacles are on its way the sooner it stops. NavClass have
- Code: Select all
static TimingNavigator nav = new TimingNavigator(Motor.C, Motor.A, 8.000f, 3.9f);
