Пример #1
1
  CircleEx1() {
    NxtRobot robot = new NxtRobot();
    Gear gear = new Gear();
    robot.addPart(gear);
    gear.setSpeed(60);

    /*The robot move in a circle with the radius 0.2 for 7500 ms.
     *Instead of using a locking-method, the method leftArc(0.2) can be used together with the command Tools.delay(7500)
     */
    gear.leftArc(0.2, 7500);

    /* No blocking Methode rightArc()*/
    gear.rightArc(0.2);
    Tools.delay(5000);
    robot.exit();
  }
  public parcourse() {
    NxtRobot robot = new NxtRobot();
    Gear gear = new Gear();
    TouchSensor ts1 = new TouchSensor(SensorPort.S3);
    TouchSensor ts2 = new TouchSensor(SensorPort.S4);
    robot.addPart(ts1);
    robot.addPart(ts2);
    gear.setSpeed(60);
    robot.addPart(gear);
    gear.forward();

    while (true) {
      if ((ts1.isPressed()) && (count1 % 2 != 0)) {

        gear.backward(900);
        gear.left(375);
        gear.backward();
        count1++;
      }

      if ((ts1.isPressed()) && (count1 % 2 == 0)) {

        gear.backward(900);
        gear.right(375);
        gear.forward();
        count1++;
        count2++;
      }
      /*if ((ts2.isPressed()) &&(count1 %2 == 2)){

      	gear.backward(900);
      	gear.right(375);
      	gear.forward();
      	count1++;
      }*/

      if (ts2.isPressed() && (count2 % 2 != 0)) {

        // gear.forward(300);
        // gear.left(375);
        gear.forward();
      }

      if ((ts2.isPressed()) && (count2 % 2 == 0)) {

        gear.forward(900);
        gear.right(375);
        gear.forward();
      }
    }
  }