Пример #1
0
  /* Initialize standard Hardware interfaces */
  public void init(HardwareMap ahwMap) {

    // Initialize base Motor and Servo objects
    super.init(ahwMap);

    /*
     * Matrix controllers are special.
     *
     * A Matrix controller is one controller with both motors and servos
     * but software wants to treat it as two distinct controllers, one
     * DcMotorController, and one ServoController.
     *
     * We accomplish this by initializing Motor and Servo controller with the same name
     * given in the configuration.  In the example below the name of the controller is
     * "MatrixController"
     *
     * Normally we don't need to access the controllers themselves, we deal directly with
     * the Motor and Servo objects, but the Matrix interface is different.
     *
     * In order to activate the servos, they need to be enabled on the controller with
     * a call to pwmEnable() and disabled with a call to pwmDisable()
     *
     * Also, the Matrix Motor controller interface provides a call that enables all motors to
     * updated simultaneously (with the same value).
     */

    // Initialize Matrix Motor and Servo objects
    matrixMotorController =
        (MatrixDcMotorController) ahwMap.dcMotorController.get("matrix controller");
    matrixServoController = ahwMap.servoController.get("matrix controller");

    // Enable Servos
    matrixServoController.pwmEnable(); // Don't forget to enable Matrix Output
  }
Пример #2
0
  public void init() {
    motorRight = hardwareMap.dcMotor.get("motor_2");
    motorLeft = hardwareMap.dcMotor.get("motor_1");

    motorLeft.setDirection(DcMotor.Direction.REVERSE);

    gyro = hardwareMap.gyroSensor.get("gyro");
    gyro.calibrate();
    while (gyro.isCalibrating()) {
      try {
        wait(20);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    drive = new ArcadeDrive(motorRight, motorLeft, gyro);
    components.add(drive);

    servoController = hardwareMap.servoController.get("Servo Controller 1");
    servoController.pwmEnable();

    servo = new NormalServo(servoController, 1);
    components.add(servo);
  }
  @Override
  public void init() {
    motor1 = hardwareMap.dcMotor.get("motor_1");
    motor2 = hardwareMap.dcMotor.get("motor_2");
    motor3 = hardwareMap.dcMotor.get("motor_3");
    motor4 = hardwareMap.dcMotor.get("motor_4");

    /*
     * A set of motors to use with the Matrix motor controller's
     * pending feature.  See example below.  Note that this is
     * completely optional.
     */
    motorSet.add(motor1);
    motorSet.add(motor2);
    motorSet.add(motor3);
    motorSet.add(motor4);

    servo1 = hardwareMap.servo.get("servo_1");
    servo2 = hardwareMap.servo.get("servo_2");
    servo3 = hardwareMap.servo.get("servo_3");
    servo4 = hardwareMap.servo.get("servo_4");

    /*
     * Matrix controllers are special.
     *
     * A Matrix controller is one controller with both motors and servos
     * but software wants to treat it as two distinct controllers, one
     * DcMotorController, and one ServoController.
     *
     * We accomplish this by appending Motor and Servo to the name
     * given in the configuration.  In the example below the name
     * of the controller is "MatrixController" so the motor controller
     * instance is "MatrixControllerMotor" and the servo controller
     * instance is "MatrixControllerServo".
     */
    mc = (MatrixDcMotorController) hardwareMap.dcMotorController.get("MatrixController");
    motor1.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
    motor2.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
    motor3.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
    motor4.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);

    /*
     * Servos are not enabled by default.  Software must call pwmEnable()
     * for servos to function.
     */
    sc = hardwareMap.servoController.get("MatrixController");
    sc.pwmEnable();
  }