Esempio n. 1
0
  @Override
  public void handleRobotChangedState(
      Robot robot, RobotChangedStateListener.RobotChangedStateNotificationType type) {
    switch (type) {
      case Online:
        {
          view.setCurrentCondition("Online");
          // If robot uses Bluetooth LE, Developer Mode can be turned on.
          // This turns off DOS protection. This generally isn't required.
          if (robot instanceof RobotLE) {
            ((RobotLE) robot).setDeveloperMode(true);
          }

          // Save the robot as a ConvenienceRobot for additional utility methods
          mRobot = new ConvenienceRobot(robot);
          mRobot.enableCollisions(true); // starts collision detection

          long sensorFlag =
              SensorFlag.VELOCITY.longValue()
                  | SensorFlag.LOCATOR
                      .longValue(); // use OR bitwise operator to enable velocity and position
          mRobot.enableSensors(
              sensorFlag,
              SensorControl.StreamingRate
                  .STREAMING_RATE10); // enable the sensors using the streaming rate

          mRobot.addResponseListener(thread); // add the thread to respond to the options

          thread.setmRobot(mRobot); // give the robot to the thread
          thread.setRunning(true); // start the thread
          thread.start(); // start the AI
          view.repaint(); // update the UI
          break;
        }
      case Connected:
        { // update the view for each condition
          view.setCurrentCondition("Connected");
          view.repaint();
          break;
        }
      case Connecting:
        {
          view.setCurrentCondition("Connecting");
          view.repaint();
          break;
        }
      case Disconnected:
        {
          view.setCurrentCondition("Disconnected");
          view.repaint();
          break;
        }
      case FailedConnect:
        {
          view.setCurrentCondition("Failed Connect");
          view.repaint();
          break;
        }
    }
  }
Esempio n. 2
0
  // Set the robot to a default 'clean' state between running macros
  private void setRobotToDefaultState() {
    if (mRobot == null) return;

    mRobot.sendCommand(new AbortMacroCommand());
    mRobot.setLed(1.0f, 1.0f, 1.0f);
    mRobot.enableStabilization(true);
    mRobot.setBackLedBrightness(0.0f);
    mRobot.stop();
  }
Esempio n. 3
0
  // Flip the robot forward and backwards while changing the LED color
  private void runVibrateMacro() {
    if (mRobot == null) return;

    setRobotToDefaultState();

    MacroObject macro = new MacroObject();

    // Stabilization must be turned off before you can issue motor commands
    macro.addCommand(new Stabilization(false, 0));

    macro.addCommand(new LoopStart(mLoopsSeekBar.getProgress()));
    // Change the LED to red
    macro.addCommand(new RGB(255, 0, 0, 0));
    // Run the robot's motors backwards
    macro.addCommand(
        new RawMotor(RawMotor.DriveMode.REVERSE, 255, RawMotor.DriveMode.REVERSE, 255, 100));
    macro.addCommand(new Delay(100));
    // Change the LED to green
    macro.addCommand(new RGB(0, 255, 0, 0));
    // Run the robot's motors forward
    macro.addCommand(
        new RawMotor(RawMotor.DriveMode.FORWARD, 255, RawMotor.DriveMode.FORWARD, 255, 100));
    macro.addCommand(new Delay(100));
    macro.addCommand(new LoopEnd());

    // Turn stabilization back on
    macro.addCommand(new Stabilization(true, 0));

    // Send the macro to the robot and play
    macro.setMode(MacroObject.MacroObjectMode.Normal);
    macro.setRobot(mRobot.getRobot());
    macro.playMacro();
  }
Esempio n. 4
0
  // Drive the robot in a figure 8 formation
  private void runFigureEightMacro() {
    if (mRobot == null) return;

    setRobotToDefaultState();

    float speed = mSpeedSeekBar.getProgress() * 0.01f;

    MacroObject macro = new MacroObject();

    macro.addCommand(new Roll(speed, 0, 1000));
    macro.addCommand(new LoopStart(mLoopsSeekBar.getProgress()));
    // Pivot
    macro.addCommand(new RotateOverTime(360, mDelaySeekBar.getProgress()));
    macro.addCommand(new Delay(mDelaySeekBar.getProgress()));
    // Pivot
    macro.addCommand(new RotateOverTime(-360, mDelaySeekBar.getProgress()));
    macro.addCommand(new Delay(mDelaySeekBar.getProgress()));
    macro.addCommand(new LoopEnd());
    // Stop
    macro.addCommand(new Roll(0.0f, 0, 255));

    // Send the macro to the robot and play
    macro.setMode(MacroObject.MacroObjectMode.Normal);
    macro.setRobot(mRobot.getRobot());
    macro.playMacro();
  }
Esempio n. 5
0
  // Move the robot in a pattern based on the speed and loop seekbar values
  private void runShapeMacro() {
    // If the looping value is set to null or the robot isn't connected, return
    if (mRobot == null || mLoopsSeekBar.getProgress() == 0) return;

    setRobotToDefaultState();

    MacroObject macro = new MacroObject();
    float speed = mSpeedSeekBar.getProgress() * 0.01f;

    // Set the robot LED color to blue
    macro.addCommand(new RGB(0, 0, 255, 255));

    // Loop through driving in various directions
    for (int i = 0; i < mLoopsSeekBar.getProgress(); i++) {
      macro.addCommand(new Roll(speed, i * (360 / mLoopsSeekBar.getProgress()), 0));
      macro.addCommand(new Delay(mDelaySeekBar.getProgress()));
      macro.addCommand(new Roll(0.0f, i * (260 / mLoopsSeekBar.getProgress()), 255));
    }

    // Stop the robot
    macro.addCommand(new Roll(0.0f, 0, 255));

    // Send the macro to the robot and play
    macro.setMode(MacroObject.MacroObjectMode.Normal);
    macro.setRobot(mRobot.getRobot());
    macro.playMacro();
  }
Esempio n. 6
0
  // Fade the robot LED between three colors in a loop
  private void runColorMacro() {
    if (mRobot == null) return;

    setRobotToDefaultState();

    MacroObject macro = new MacroObject();

    // Loop as many times as the loop seekbar value
    macro.addCommand(new LoopStart(mLoopsSeekBar.getProgress()));

    // Fade to cyan. Duration of the fade is set to the value of the delay seekbar
    macro.addCommand(new Fade(0, 255, 255, mDelaySeekBar.getProgress()));
    // Set a delay so that the next command isn't processed until the previous one is done
    macro.addCommand(new Delay(mDelaySeekBar.getProgress()));

    // Fade to magenta. Duration of the fade is set to the value of the delay seekbar
    macro.addCommand(new Fade(255, 0, 255, mDelaySeekBar.getProgress()));
    // Set a delay so that the next command isn't processed until the previous one is done
    macro.addCommand(new Delay(mDelaySeekBar.getProgress()));

    // Fade to yellow. Duration of the fade is set to the value of the delay seekbar
    macro.addCommand(new Fade(255, 255, 0, mDelaySeekBar.getProgress()));
    // Set a delay so that the next command isn't processed until the previous one is done
    macro.addCommand(new Delay(mDelaySeekBar.getProgress()));

    // End the current loop and go back to LoopStart if more iterations expected
    macro.addCommand(new LoopEnd());

    // Send the macro to the robot and play
    macro.setMode(MacroObject.MacroObjectMode.Normal);
    mRobot.playMacro(macro);
  }
Esempio n. 7
0
  protected void onStop() {
    // If the DiscoveryAgent is in discovery mode, stop it.
    if (DualStackDiscoveryAgent.getInstance().isDiscovering()) {
      DualStackDiscoveryAgent.getInstance().stopDiscovery();
    }

    // If a robot is connected to the device, disconnect it
    if (mRobot != null) {
      mRobot.disconnect();
      mRobot = null;
    }
    super.onStop();
    thread.setRunning(false);
  }
Esempio n. 8
0
  // Move the robot in the shape of a square with each edge being a new color
  private void runSquareMacro() {
    if (mRobot == null) return;

    setRobotToDefaultState();
    float speed = mSpeedSeekBar.getProgress() * 0.01f;

    MacroObject macro = new MacroObject();

    // Set the robot LED to green
    macro.addCommand(new RGB(0, 255, 0, 255));
    // Move the robot forward
    macro.addCommand(new Roll(speed, 0, 0));
    // Wait until the robot should stop moving
    macro.addCommand(new Delay(mDelaySeekBar.getProgress()));
    // Stop
    macro.addCommand(new Roll(0.0f, 0, 255));

    // Set the robot LED to blue
    macro.addCommand(new RGB(0, 0, 255, 255));
    // Move the robot to the right
    macro.addCommand(new Roll(speed, 90, 0));
    // Wait until the robot should stop moving
    macro.addCommand(new Delay(mDelaySeekBar.getProgress()));
    // Stop
    macro.addCommand(new Roll(0.0f, 90, 255));

    // Set the robot LED to yellow
    macro.addCommand(new RGB(255, 255, 0, 255));
    // Move the robot backwards
    macro.addCommand(new Roll(speed, 180, 0));
    // Wait until the robot should stop moving
    macro.addCommand(new Delay(mDelaySeekBar.getProgress()));
    // Stop
    macro.addCommand(new Roll(0.0f, 180, 255));

    // Set the robot LED to red
    macro.addCommand(new RGB(255, 0, 0, 255));
    // Move the robot to the left
    macro.addCommand(new Roll(255, 270, 0));
    // Wait until the robot should stop moving
    macro.addCommand(new Delay(mDelaySeekBar.getProgress()));
    // Stop
    macro.addCommand(new Roll(0.0f, 270, 255));

    // Send the macro to the robot and play
    macro.setMode(MacroObject.MacroObjectMode.Normal);
    macro.setRobot(mRobot.getRobot());
    macro.playMacro();
  }
Esempio n. 9
0
  // Spin the robot in circles
  private void runSpinMacro() {
    setRobotToDefaultState();
    float speed = mSpeedSeekBar.getProgress() * 0.01f;

    MacroObject macro = new MacroObject();

    // Set the back LED to full brightness
    macro.addCommand(new BackLED(255, 0));

    // Loop through rotating the robot
    macro.addCommand(new LoopStart(mLoopsSeekBar.getProgress()));
    macro.addCommand(new RotateOverTime(360, (int) (500 * speed)));
    macro.addCommand(new Delay((int) (500 * speed)));
    macro.addCommand(new LoopEnd());

    // Dim the back LED
    macro.addCommand(new BackLED(0, 0));

    // Send the macro to the robot and play
    macro.setMode(MacroObject.MacroObjectMode.Normal);
    macro.setRobot(mRobot.getRobot());
    macro.playMacro();
  }