next up previous
Next: 7 josx パッケージ Up: 6.5 ロボットの行動プログラム Previous: 6.5.8 右バンパーへの反応行動

6.5.9 Wanderクラス

3種類のアクションをもったWanderクラスを定義する.
/**
 * Defines a finite state machine
 * to wander around aimlessley. Note that
 * this does not really work very well
 * as higher priority behaviours
 * could occur in the middle of a sleep
 * which means that once the higher
 * priority behaviour terminates the
 * robot will continue on its last
 * trajectory.
 */                
class Wander extends Task {
  public Wander() {
    actions = new Action[3];
    actions[0] = new Action() {
        public int act() {
          setMotor(LEFT_MOTOR,
                   7, FORWARD);
          setMotor(RIGHT_MOTOR,
                   7, FORWARD);
          return 5000;
        }
      };
                
    actions[1] = new Action() {
        public int act() {
          setMotor(LEFT_MOTOR,
                   3, FORWARD);
          setMotor(RIGHT_MOTOR,
                   7, FORWARD);
          return 2000;
        }
      };
                
    actions[2] = new Action() {
        public int act() {
          setMotor(LEFT_MOTOR,
                   7, BACKWARD);
          setMotor(RIGHT_MOTOR,
                   7, FORWARD);
          return 700;
        }
      };
                
    fsm = new int[3];                
    fsm[0] = 1;
    fsm[1] = 2;
    fsm[2] = 0;
  }
}
プログラムの流れを読むために,次のことを調べよ.
  1. Subsumption1のActionインタフェースの役割は何か.
  2. Subsumption1のTaskクラスのfsmの役割は何か.
  3. Subsumption1のLeftBumper, RightBumper, Wanderの働きは何か.
  4. Subsumption1のsynchronizedメソッドの働きは何か.
  5. Subsumption1によりロボットの行動がどのようなことになるか.


generated through LaTeX2HTML. M.Inaba 平成18年5月7日