next up previous
Next: 6.5.2 Main.java Up: 6.5 ロボットの行動プログラム Previous: 6.5 ロボットの行動プログラム

6.5.1 subsumption1サンプル

Lejosのexampleプログラムには, サブサンプションアーキテクチャを JavaのThreadを用いた形のプログラムとして実装した プログラムがいくつか提供されている. Subsumption1はその一つの例である. 抽象クラスとしてThreadを拡張したTaskクラスがあり, ユーザは並列に走らせたいタスクを Taskクラスを継承した形で定義してゆく形になっている.

public class Main
    public static void main (String[] arg)

class Subsumption
        implements ButtonListener
    public boolean running;
    public int owner;
    Task tasks[];

    public Subsumption()
    int getPriority(Task t)
    public synchronized void execute(Task requestor)
    public synchronized void setMotor(Task requestor,
             Motor motor, int power, boolean forward)
    public synchronized void release(Task releaser)
    public void buttonPressed(Button b)
    public void buttonReleased(Button b)

interface Action
    public int act();

abstract class Task
               extends Thread
               implements SensorConstants
    public void reset()
    public void run()
    public void release()
    public void execute()
    public boolean running()
    public void setMotor(Motor motor,
                  int power, boolean forward)

class LeftBumber extends Task
                implements SensorListener
    public LeftBumber()
    public void stateChanged(Sensor bumber,
                 int oldValue, int newValue)

class RightBumber extends Task
                implements SensorListener
    public RightBumber()
    public void stateChanged(Sensor bumber,
                int oldValue, int newValue)

class Wander extends Task
    public Wander()


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