i have a problem with a small Lejos app. i've wrote..
The programm should:
1) move forward until he hits a wall.
2) Then he should go backward and turn right.
3) back to 1)
I have 2 issues with this.. First he is doing 2) twice.. I've tryed around but can't figure out wheres the problem..
2nd problem is the loop. I have no idea how to realise it, so I've done some provisorily: (try {Thread.sleep(800000);} )...
Heres the code:
- Code: Select all
import josx.platform.rcx.*;
class berührung
{
public static void main(String args[])
{
Sensor.S1.setTypeAndMode(1,0x20);
Sensor.S1.activate();
Sensor.S3.setTypeAndMode(1,0x20);
Sensor.S3.activate();
Motor.A.forward(); Motor.C.forward();
Sensor.S1.addSensorListener(new SensorListener()
{
public void stateChanged (Sensor S1, int oldValue, int newValue)
{
Motor.A.backward(); Motor.C.backward();
try {Thread.sleep(750);} catch (Exception e) {}
Motor.A.forward(); Motor.C.stop();
try {Thread.sleep(400);} catch (Exception e) {}
Motor.A.forward(); Motor.C.forward();
}
});
Sensor.S3.addSensorListener(new SensorListener()
{
public void stateChanged (Sensor S3, int oldValue, int newValue)
{
Motor.A.backward(); Motor.C.backward();
try {Thread.sleep(750);} catch (Exception e) {}
Motor.C.forward(); Motor.A.stop();
try {Thread.sleep(400);} catch (Exception e) {}
Motor.A.forward(); Motor.C.forward();
}
});
try {Thread.sleep(80000);} catch (Exception e) {}
}
}
Thx for your help..
(copied a bit from an other post because my english is not so well
