@Override
 protected void onNewIntent(Intent intent) {
   super.onNewIntent(intent);
   if (UsbManager.ACTION_USB_ACCESSORY_ATTACHED.equals(intent.getAction())) {
     // a new USB device has been attached
     DbgLog.msg("USB Device attached; app restart may be needed");
   }
 }
 public void run() {
   try {
     DbgLog.msg("Scanning USB bus");
     this.f92a.f93a.scannedDevices = this.f92a.f93a.f100d.scanForUsbDevices();
   } catch (RobotCoreException e) {
     DbgLog.error("Device scan failed");
   }
   this.f92a.f93a.runOnUiThread(new C00321(this));
 }
 public void setRightPosition(int primaryCount) {
   int start0 = rightMotors.get(0).getCurrentPosition();
   int start1 = rightMotors.get(1).getCurrentPosition();
   int target0 = start0 + primaryCount;
   int target1 = start1 + (int) (primaryCount * (1090.0 / 1124.0));
   DbgLog.msg("Setting Rmotor0 to " + target0);
   rightMotors.get(0).setTargetPosition(target0);
   DbgLog.msg("Setting Rmotor1 to " + target1);
   rightMotors.get(1).setTargetPosition(target1);
 }
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   this.f97a = this;
   setContentView(R.layout.activity_autoconfigure);
   this.f103g = new Utility(this);
   this.f98b = (Button) findViewById(R.id.configureLegacy);
   this.f99c = (Button) findViewById(R.id.configureUSB);
   try {
     this.f100d = new HardwareDeviceManager(this.f97a, null);
   } catch (RobotCoreException e) {
     this.f103g.complainToast("Failed to open the Device Manager", this.f97a);
     DbgLog.error("Failed to open deviceManager: " + e.toString());
     DbgLog.logStacktrace(e);
   }
 }
Esempio n. 5
0
 public LinearLift(FTCRobot robot, LinearOpMode curOpMode) {
   this.robot = robot;
   this.curOpMode = curOpMode;
   try {
     this.liftAngleMotor = curOpMode.hardwareMap.dcMotor.get("liftAngleMotor");
     liftAngleMotorAvailable = true;
   } catch (Exception e) {
     DbgLog.error(String.format("%s . Device skipped", e.getMessage()));
   }
   try {
     this.liftArmLengthMotor = curOpMode.hardwareMap.dcMotor.get("liftArmLengthMotor");
     liftArmLengthMotorAvailable = true;
   } catch (Exception e) {
     DbgLog.error(String.format("%s . Device skipped", e.getMessage()));
   }
 }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode == RESULT_CANCELED) {
      return;
    }
    Serializable extra = null;
    if (requestCode == 1) {
      extra = data.getSerializableExtra(EditMotorControllerActivity.EDIT_MOTOR_CONTROLLER_CONFIG);
    } else if (requestCode == 2) {
      extra = data.getSerializableExtra(EditServoControllerActivity.EDIT_SERVO_ACTIVITY);
    } else if (requestCode == 3) {
      extra = data.getSerializableExtra(EditLegacyModuleControllerActivity.EDIT_LEGACY_CONFIG);
    }
    if (extra != null) {
      ControllerConfiguration newC = (ControllerConfiguration) extra;
      scannedDevices.put(newC.getSerialNumber(), newC.configTypeToDeviceType(newC.getType()));
      deviceControllers.put(newC.getSerialNumber(), newC);
      populateList();

      String name = preferredFilename;
      // only update the filename if it hasn't already been updated to have "unsaved" in it
      if (!name.toLowerCase().contains(Utility.UNSAVED.toLowerCase())) {
        name = Utility.UNSAVED + " " + preferredFilename;
        utility.saveToPreferences(name, R.string.pref_hardware_config_filename);
        preferredFilename = name;
      }

    } else {
      DbgLog.error(
          "Received Result with an incorrect request code: " + String.valueOf(requestCode));
    }
  }
 private void m55a(String str) {
   this.f103g.writeXML(this.f101e);
   try {
     this.f103g.writeToFile(str + ".xml");
     this.f103g.saveToPreferences(str, R.string.pref_hardware_config_filename);
     this.f103g.updateHeader(
         str, R.string.pref_hardware_config_filename, R.id.active_filename, R.id.included_header);
     Toast.makeText(this.f97a, "AutoConfigure " + str + " Successful", 0).show();
   } catch (RobotCoreException e) {
     this.f103g.complainToast(e.getMessage(), this.f97a);
     DbgLog.error(e.getMessage());
   } catch (IOException e2) {
     this.f103g.complainToast("Found " + e2.getMessage() + "\n Please fix and re-save", this.f97a);
     DbgLog.error(e2.getMessage());
   }
 }
  public void onServiceBind(FtcRobotControllerService service) {
    DbgLog.msg("Bound to Ftc Controller Service");
    controllerService = service;
    updateUI.setControllerService(controllerService);

    callback.wifiDirectUpdate(controllerService.getWifiDirectStatus());
    callback.robotUpdate(controllerService.getRobotStatus());
    requestRobotSetup();
  }
Esempio n. 9
0
  public void runOpMode() throws InterruptedException {
    this.hardwareMap.logDevices();
    this.sensorRGB = (ColorSensor) this.hardwareMap.colorSensor.get("nxt");
    this.sensorRGB.enableLed(true);
    this.waitOneFullHardwareCycle();
    this.waitForStart();
    final float[] var1 = new float[] {0.0F, 0.0F, 0.0F};
    final View var2 = ((Activity) this.hardwareMap.appContext).findViewById(2131427353);
    boolean var3 = false;

    while (this.opModeIsActive()) {
      boolean var4;
      if (!this.gamepad1.x && !this.gamepad2.x) {
        var4 = false;
      } else {
        var4 = true;
      }

      if (var4 && var4 != var3) {
        DbgLog.msg("MY_DEBUG - x button was pressed!");
        var3 = var4;
        this.sensorRGB.enableLed(true);
      } else if (!var4 && var4 != var3) {
        DbgLog.msg("MY_DEBUG - x button was released!");
        var3 = var4;
        this.sensorRGB.enableLed(false);
      }

      Color.RGBToHSV(this.sensorRGB.red(), this.sensorRGB.green(), this.sensorRGB.blue(), var1);
      this.telemetry.addData("Clear", (float) this.sensorRGB.alpha());
      this.telemetry.addData("Red  ", (float) this.sensorRGB.red());
      this.telemetry.addData("Green", (float) this.sensorRGB.green());
      this.telemetry.addData("Blue ", (float) this.sensorRGB.blue());
      this.telemetry.addData("Hue", var1[0]);
      var2.post(
          new Runnable() {
            public void run() {
              var2.setBackgroundColor(Color.HSVToColor(255, var1));
            }
          });
      this.waitOneFullHardwareCycle();
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ftc_configuration);

    RobotLog.writeLogcatToDisk(this, 1024);
    this.context = this;
    utility = new Utility(this);
    scanButton = (Button) findViewById(R.id.scanButton);
    buildInfoButtons();

    try {
      deviceManager = new ModernRoboticsDeviceManager(context, null);
      // deviceManager = new MockDeviceManager(context, null);
    } catch (RobotCoreException e) {
      utility.complainToast("Failed to open the Device Manager", context);
      DbgLog.error("Failed to open deviceManager: " + e.toString());
      DbgLog.logStacktrace(e);
    }

    preferences = PreferenceManager.getDefaultSharedPreferences(this);
  }
Esempio n. 11
0
  @Override
  public void runOpMode() throws InterruptedException {
    // motorRF = hardwareMap.dcMotor.get("motorRF");//sets DcMotors to type of motor
    // motorLF = hardwareMap.dcMotor.get("motorLF");
    // motorRB = hardwareMap.dcMotor.get("motorRB");
    // motorLB = hardwareMap.dcMotor.get("motorLB");
    // servoPeople = hardwareMap.servo.get("servoPeople");

    // motorLB.setDirection(DcMotor.Direction.REVERSE);//changes left wheels so that they turn
    // correctly
    // motorLF.setDirection(DcMotor.Direction.REVERSE);

    RGB = hardwareMap.colorSensor.get("RGB");
    // servo = hardwareMap.servo.get("servo");
    // touchSensor = hardwareMap.touchSensor.get("sensor_touch");
    // opticalDistanceSensor = hardwareMap.opticalDistanceSensor.get("sensor_distance");

    waitForStart();

    DbgLog.msg("NUMBERS HERE!!!!!");
    DbgLog.msg(RGB.getDeviceName());
    DbgLog.msg(RGB.getConnectionInfo());
    RGB.enableLed(false);
    sleep(1000);

    if (RGB.alpha() >= 1 && RGB.alpha() <= 4) DbgLog.msg("BLUE!!!!!!!!!!!");
    else DbgLog.msg("I DON'T KNOW!");

    sleep(1000);

    if (RGB.alpha() >= 9 && RGB.alpha() <= 11) DbgLog.msg("RED!!!!!!!!!!!");
    else DbgLog.msg("I DON'T KNOW!");

    sleep(1000);

    if (RGB.alpha() >= 13) DbgLog.msg("WHITE!!!!!!!!!!!!");
    else DbgLog.msg("I DON'T KNOW!");

    sleep(1000);
    RGB.enableLed(false);
  }
Esempio n. 12
0
 public RightClimber(
     FTCRobot robot, Servo rightClimber, LinearOpMode curOpMode, boolean allianceIsBlue) {
   this.robot = robot;
   this.curOpMode = curOpMode;
   if (rightClimber != null) {
     rightClimberAvailable = true;
     this.rightClimber = rightClimber;
     this.rightClimber.scaleRange(0.1, 0.47);
     this.rightClimber.setPosition(1.0); // 1.0 == 0.47 because of scaleRange() call above
     DbgLog.msg(String.format("RightClimber Position = %f", this.rightClimber.getPosition()));
     if (allianceIsBlue) {
       this.rightClimber.close();
     }
   }
 }
  /**
   * This method parses the XML of the active configuration file, and calls methods to populate the
   * appropriate data structures to the configuration information can be displayed to the user.
   */
  private void readFile() {
    ReadXMLFileHandler parser = new ReadXMLFileHandler(context);

    if (preferredFilename.equalsIgnoreCase(Utility.NO_FILE)) {
      // don't try to parse if there's no file
      return;
    }

    InputStream inputStream = null;
    try {
      inputStream =
          new FileInputStream(Utility.CONFIG_FILES_DIR + preferredFilename + Utility.FILE_EXT);
    } catch (FileNotFoundException e) {
      DbgLog.error("File was not found: " + preferredFilename);
      DbgLog.logStacktrace(e);
      utility.complainToast("That file was not found: " + preferredFilename, context);
      return;
    }
    ArrayList<ControllerConfiguration> controllerList =
        (ArrayList<ControllerConfiguration>) parser.parse(inputStream);
    buildHashMap(controllerList);
    populateList();
    warnIfNoDevices();
  }
Esempio n. 14
0
 /**
  * Moves right climber servo based on {@code enum rightClimberDirection} value set in {@link
  * DriverStation#getNextClimberCmd()}
  *
  * @param drvrcmd {@link DriverCommand} object with values.
  */
 public void applyDSCmd(DriverCommand drvrcmd) {
   if (!rightClimberAvailable) {
     return;
   }
   double rightClimberPosition = rightClimber.getPosition();
   DbgLog.msg(String.format("RightClimber Position = %f", rightClimberPosition));
   switch (drvrcmd.rightClimberCmd.rightClimberStatus) {
     case -1:
       rightClimber.setPosition(Range.clip(0, 0, 1));
       break;
     case 1:
       rightClimber.setPosition(Range.clip(1, 0, 1));
       break;
     case 0:
       break;
     default:
       break;
   }
 }
Esempio n. 15
0
  public void file_delete_button(View v) {
    String filenameWExt = getFileName(v, true);
    File file = new File(Utility.CONFIG_FILES_DIR + filenameWExt);

    if (file.exists()) {
      file.delete();
    } else {
      utility.complainToast("That file does not exist: " + filenameWExt, context);
      DbgLog.error("Tried to delete a file that does not exist: " + filenameWExt);
    }

    fileList = utility.getXMLFiles();
    utility.saveToPreferences(Utility.NO_FILE, R.string.pref_hardware_config_filename);
    utility.updateHeader(
        Utility.NO_FILE,
        R.string.pref_hardware_config_filename,
        R.id.active_filename,
        R.id.included_header);
    populate();
  }
  private FileInputStream fileSetup() {

    final String filename =
        Utility.CONFIG_FILES_DIR
            + utility.getFilenameFromPrefs(R.string.pref_hardware_config_filename, Utility.NO_FILE)
            + Utility.FILE_EXT;

    FileInputStream fis;
    try {
      fis = new FileInputStream(filename);
    } catch (FileNotFoundException e) {
      String msg = "Cannot open robot configuration file - " + filename;
      utility.complainToast(msg, context);
      DbgLog.msg(msg);
      utility.saveToPreferences(Utility.NO_FILE, R.string.pref_hardware_config_filename);
      fis = null;
    }
    utility.updateHeader(
        Utility.NO_FILE,
        R.string.pref_hardware_config_filename,
        R.id.active_filename,
        R.id.included_header);
    return fis;
  }
  @Override
  public void loop() {
    // get the values from the gamepads
    // note: pushing the stick all the way up returns -1,
    // so we need to reverse the values
    float leftY = -gamepad1.left_stick_y;
    float rightY = -gamepad1.right_stick_y;

    leftY = Range.clip(leftY, -1, 1);
    rightY = Range.clip(rightY, -1, 1);

    // motorLF.setPower(leftY);
    motorLR.setPower(leftY);

    // motorRF.setPower(rightY);
    motorRR.setPower(rightY);

    //   telemetry.addData("left tgt pwr",  "left  pwr: " + String.format("%.2f", left));
    //   telemetry.addData("right tgt pwr", "right pwr: " + String.format("%.2f", right));

    if (leftY < 1 && rightY > 0) {
      DbgLog.msg("leftY, RightY " + leftY + " " + rightY);
    }
  }
Esempio n. 18
0
  /**
   * Perform any actions that are necessary when the OpMode is enabled.
   *
   * <p>The system calls this member once when the OpMode is enabled.
   */
  @Override
  public void init() {

    //
    // Use the hardwareMap to associate class members to hardware ports.
    //
    // Note that the names of the devices (i.e. arguments to the get method)
    // must match the names specified in the configuration file created by
    // the FTC Robot Controller (Settings-->Configure Robot).
    //
    // The variable below is used to provide telemetry data to a class user.
    //
    v_warning_generated = false;
    v_warning_message = "Can't map; ";

    //
    // Connect the drive wheel motors.
    //
    // The direction of the right motor is reversed, so joystick inputs can
    // be more generically applied.
    //
    try {
      v_motor_left_drive = hardwareMap.dcMotor.get("left_drive");
    } catch (Exception p_exeception) {
      m_warning_message("left_drive");
      DbgLog.msg(p_exeception.getLocalizedMessage());

      v_motor_left_drive = null;
    }

    try {
      v_motor_right_drive = hardwareMap.dcMotor.get("right_drive");
      v_motor_right_drive.setDirection(DcMotor.Direction.REVERSE);
    } catch (Exception p_exeception) {
      m_warning_message("right_drive");
      DbgLog.msg(p_exeception.getLocalizedMessage());

      v_motor_right_drive = null;
    }

    //
    // Connect the arm motor.
    //
    try {
      v_motor_left_arm = hardwareMap.dcMotor.get("left_arm");
    } catch (Exception p_exeception) {
      m_warning_message("left_arm");
      DbgLog.msg(p_exeception.getLocalizedMessage());

      v_motor_left_arm = null;
    }

    //
    // Connect the servo motors.
    //
    // Indicate the initial position of both the left and right servos.  The
    // hand should be halfway opened/closed.
    //
    double l_hand_position = 0.5;

    try {
      v_servo_left_hand = hardwareMap.servo.get("left_hand");
      v_servo_left_hand.setPosition(l_hand_position);
    } catch (Exception p_exeception) {
      m_warning_message("left_hand");
      DbgLog.msg(p_exeception.getLocalizedMessage());

      v_servo_left_hand = null;
    }

    try {
      v_servo_right_hand = hardwareMap.servo.get("right_hand");
      v_servo_right_hand.setPosition(l_hand_position);
    } catch (Exception p_exeception) {
      m_warning_message("right_hand");
      DbgLog.msg(p_exeception.getLocalizedMessage());

      v_servo_right_hand = null;
    }
  } // init
Esempio n. 19
0
  @Override
  public void runOpMode() throws InterruptedException {

    // write some device information (connection info, name and type)
    // to the log file.
    hardwareMap.logDevices();

    // get a reference to our ColorSensor object.
    sensorRGB = hardwareMap.colorSensor.get("cs");

    // bEnabled represents the state of the LED.
    boolean bEnabled = true;

    // turn the LED on in the beginning, just so user will know that the sensor is active.
    sensorRGB.enableLed(true);

    // wait one cycle.
    waitOneFullHardwareCycle();

    // wait for the start button to be pressed.
    waitForStart();

    // hsvValues is an array that will hold the hue, saturation, and value information.
    float hsvValues[] = {0F, 0F, 0F};

    // values is a reference to the hsvValues array.
    final float values[] = hsvValues;

    // get a reference to the RelativeLayout so we can change the background
    // color of the Robot Controller app to match the hue detected by the RGB sensor.
    final View relativeLayout =
        ((Activity) hardwareMap.appContext).findViewById(R.id.RelativeLayout);

    // bPrevState and bCurrState represent the previous and current state of the button.
    boolean bPrevState = false;
    boolean bCurrState = false;

    // while the op mode is active, loop and read the RGB data.
    // Note we use opModeIsActive() as our loop condition because it is an interruptible method.
    while (opModeIsActive()) {
      // check the status of the x button on either gamepad.
      bCurrState = gamepad1.x || gamepad2.x;

      // check for button state transitions.
      if (bCurrState == true && bCurrState != bPrevState) {
        // button is transitioning to a pressed state.

        // print a debug statement.
        DbgLog.msg("MY_DEBUG - x button was pressed!");

        // update previous state variable.
        bPrevState = bCurrState;

        // on button press, enable the LED.
        bEnabled = true;

        // turn on the LED.
        sensorRGB.enableLed(bEnabled);
      } else if (bCurrState == false && bCurrState != bPrevState) {
        // button is transitioning to a released state.

        // print a debug statement.
        DbgLog.msg("MY_DEBUG - x button was released!");

        // update previous state variable.
        bPrevState = bCurrState;

        // on button press, enable the LED.
        bEnabled = false;

        // turn off the LED.
        sensorRGB.enableLed(false);
      }

      // convert the RGB values to HSV values.
      Color.RGBToHSV(sensorRGB.red(), sensorRGB.green(), sensorRGB.blue(), hsvValues);

      // send the info back to driver station using telemetry function.
      telemetry.addData("Clear", sensorRGB.alpha());
      telemetry.addData("Red  ", sensorRGB.red());
      telemetry.addData("Green", sensorRGB.green());
      telemetry.addData("Blue ", sensorRGB.blue());
      telemetry.addData("Hue", hsvValues[0]);

      // change the background color to match the color detected by the RGB sensor.
      // pass a reference to the hue, saturation, and value array as an argument
      // to the HSVToColor method.
      relativeLayout.post(
          new Runnable() {
            public void run() {
              relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
            }
          });

      // wait a hardware cycle before iterating.
      waitOneFullHardwareCycle();
    }
  }
Esempio n. 20
0
  @Override
  public void main() throws InterruptedException {

    // write some device information (connection info, name and type)
    // to the log file.
    hardwareMap.logDevices();

    // get a reference to our DeviceInterfaceModule object.
    cdim = hardwareMap.deviceInterfaceModule.get("dim");

    // set the digital channel to output mode.
    // remember, the Adafruit sensor is actually two devices.
    // It's an I2C sensor and it's also an LED that can be turned on or off.
    cdim.setDigitalChannelMode(LED_CHANNEL, DigitalChannelController.Mode.OUTPUT);

    // get a reference to our ColorSensor object.
    sensorRGB = hardwareMap.colorSensor.get("color");

    // bEnabled represents the state of the LED.
    boolean bEnabled = true;

    // turn the LED on in the beginning, just so user will know that the sensor is active.
    cdim.setDigitalChannelState(LED_CHANNEL, bEnabled);

    // Set up our dashboard computations
    composeDashboard();

    // wait for the start button to be pressed.
    waitForStart();

    // hsvValues is an array that will hold the hue, saturation, and value information.
    float hsvValues[] = {0F, 0F, 0F};

    // values is a reference to the hsvValues array.
    final float values[] = hsvValues;

    // get a reference to the RelativeLayout so we can change the background
    // color of the Robot Controller app to match the hue detected by the RGB sensor.
    final View relativeLayout =
        ((Activity) hardwareMap.appContext).findViewById(R.id.RelativeLayout);

    // bPrevState and bCurrState represent the previous and current state of the button.
    boolean bPrevState = false;
    boolean bCurrState = false;

    // while the op mode is active, loop and read the RGB data.
    // Note we use opModeIsActive() as our loop condition because it is an interruptible method.
    while (opModeIsActive()) {
      // check the status of the x button on either gamepad.
      bCurrState = gamepad1.x || gamepad2.x;

      // check for button state transitions.
      if (bCurrState == true && bCurrState != bPrevState) {
        // button is transitioning to a pressed state.

        // print a debug statement.
        DbgLog.msg("MY_DEBUG - x button was pressed!");

        // update previous state variable.
        bPrevState = bCurrState;

        // on button press, enable the LED.
        bEnabled = true;

        // turn on the LED.
        cdim.setDigitalChannelState(LED_CHANNEL, bEnabled);

      } else if (bCurrState == false && bCurrState != bPrevState) {
        // button is transitioning to a released state.

        // print a debug statement.
        DbgLog.msg("MY_DEBUG - x button was released!");

        // update previous state variable.
        bPrevState = bCurrState;

        // on button press, enable the LED.
        bEnabled = false;

        // turn off the LED.
        cdim.setDigitalChannelState(LED_CHANNEL, bEnabled);
      }

      // convert the RGB values to HSV values.
      Color.RGBToHSV(
          (sensorRGB.red() * 255) / 800,
          (sensorRGB.green() * 255) / 800,
          (sensorRGB.blue() * 255) / 800,
          hsvValues);

      this.hue = hsvValues[0];

      // change the background color to match the color detected by the RGB sensor.
      // pass a reference to the hue, saturation, and value array as an argument
      // to the HSVToColor method.
      relativeLayout.post(
          new Runnable() {
            public void run() {
              relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
            }
          });

      this.telemetry.update();
      this.idle();
    }
  }