public void execute(BaseActivity activity) throws InterruptedException {
    YADroneApplication app = (YADroneApplication) activity.getApplication();
    ARDrone drone = app.getARDrone();

    final CommandManager cm = drone.getCommandManager();
    final NavDataManager nm = drone.getNavDataManager();

    if (mSound.length() > 0) {
      int resId = activity.getResources().getIdentifier(mSound, "raw", activity.getPackageName());
      if (resId != 0) {
        activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
        activity.soundPlayer.loadAndPlaySound(resId);
      }
    }
    int repetitions = mRepetitions > 0 ? mRepetitions : 1;
    for (int i = 0; i < repetitions; i++) {
      Log.d("FlyRoute", mCommand.toString());

      nm.setStateListener(
          new StateListener() {
            private boolean done = false;

            @Override
            public synchronized void stateChanged(DroneState state) {
              if (!done && state.isEmergency()) {
                cm.emergency();
              }
              nm.setStateListener(null);
              done = true;
            }

            @Override
            public void controlStateChanged(ControlState state) {
              // ignore
            }
          });

      cm.setCommand(mCommand);
      Thread.sleep(mDuration / repetitions);
    }
  }
Exemple #2
0
  public CCPanel(final ARDrone ardrone) {
    super(new GridBagLayout());

    setBackground(Color.BLUE);
    video = new VideoPanel(ardrone);
    battery = new BatteryPanel();
    state = new StatePanel();
    attitude = new AttitudePanel();

    add(
        video,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.7,
            1,
            GridBagConstraints.FIRST_LINE_START,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    add(
        new JScrollPane(state),
        new GridBagConstraints(
            1,
            0,
            1,
            2,
            0.3,
            1,
            GridBagConstraints.FIRST_LINE_START,
            GridBagConstraints.VERTICAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    add(
        attitude.getPane(),
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1,
            1,
            GridBagConstraints.FIRST_LINE_START,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    // add(battery, new GridBagConstraints(0, 1, 1, 1, 1, 1,
    // GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new
    // Insets(0,0,0,0), 0, 0));

    // CommandManager handles (keyboard) input and dispatches events to the
    // drone
    System.out.println("CCPanel.KeyEventDispatcher: grab the whole keyboard input from now on ...");
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(
        new KeyEventDispatcher() {

          private KeyboardCommandManager cmdManager = new KeyboardCommandManager(ardrone, 45);

          public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED) {
              cmdManager.keyPressed(e);
            } else if (e.getID() == KeyEvent.KEY_RELEASED) {
              cmdManager.keyReleased(e);
            }
            return true;
          }
        });

    VideoManager vm = ardrone.getVideoManager();
    vm.setImageListener(this);
    NavDataManager m = ardrone.getNavDataManager();
    m.setStateListener(this);
    m.setAttitudeListener(this);
    m.setBatteryListener(this);
  }