当前位置: 首页>>代码示例>>Java>>正文


Java Range.scale方法代码示例

本文整理汇总了Java中com.qualcomm.robotcore.util.Range.scale方法的典型用法代码示例。如果您正苦于以下问题:Java Range.scale方法的具体用法?Java Range.scale怎么用?Java Range.scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.qualcomm.robotcore.util.Range的用法示例。


在下文中一共展示了Range.scale方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: normalize

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
private void normalize() {
    // temp things
    int low = Math.min(Math.min(rawRed.raw, rawGreen.raw), rawBlue.raw);
    int high = Math.max(Math.max(rawRed.raw, rawGreen.raw), rawBlue.raw);

    if (low - high != 0) {
        int nRed = 0;
        if (rawRed.low != rawRed.high) {
            nRed = (int) Range.scale(rawRed.raw, rawRed.low, rawRed.high, low, high);
        }

        int nGreen = 0;
        if (rawGreen.low != rawGreen.high) {
            nGreen = (int) Range.scale(rawGreen.raw, rawGreen.low, rawGreen.high, low, high);
        }

        int nBlue = 0;
        if (rawBlue.low != rawBlue.high) {
            nBlue = (int) Range.scale(rawBlue.raw, rawBlue.low, rawBlue.high, low, high);
        }

        rawRed.normal = (int) Range.scale(nRed, low, high, 0, 255);
        rawGreen.normal = (int) Range.scale(nGreen, low, high, 0, 255);
        rawBlue.normal = (int) Range.scale(nBlue, low, high, 0, 255);
    }
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:27,代码来源:AdafruitSensorWrapper.java

示例2: setMotorPower

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public synchronized void setMotorPower(int motor, double power) {
    this.validateMotor(motor);

    // Unlike the (beta) robot controller library, we saturate the motor
    // power rather than making clients worry about doing that.
    power = Range.clip(power, POWER_MIN, POWER_MAX);

    // The legacy values are -100 to 100
    byte bPower = (byte) Range.scale(power, POWER_MIN, POWER_MAX, RAW_POWER_MIN, RAW_POWER_MAX);

    // Write it on out
    this.write8(mpMotorRegMotorPower[motor], bPower);
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:TeamClutch2016,代码行数:15,代码来源:HiTechnicDcMotorController.java

示例3: getMotorPower

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public synchronized double getMotorPower(int motor) {
    this.validateMotor(motor);
    byte bPower = this.i2cDeviceClient.read8(mpMotorRegMotorMode[motor]);

    // Float counts as zero power
    if (bPower == RAW_POWER_FLOAT)
        return 0.0;

    // Other values are just linear scaling. The clipping is just paranoia about
    // numerical precision; it probably isn't necessary
    double power = Range.scale(bPower, RAW_POWER_MIN, RAW_POWER_MAX, POWER_MIN, POWER_MAX);
    return Range.clip(power, POWER_MIN, POWER_MAX);
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:TeamClutch2016,代码行数:15,代码来源:HiTechnicDcMotorController.java

示例4: setMotorPower

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public synchronized void setMotorPower(int motor, double power) {
    this.validateMotor(motor);

    // Unlike the (beta) robot controller library, we saturate the motor
    // power rather than making clients worry about doing that.
    power = Range.clip(power, powerMin, powerMax);

    // The legacy values are -100 to 100
    byte bPower = (byte) Range.scale(power, powerMin, powerMax, bPowerMin, bPowerMax);

    // Write it on out
    this.write8(mpMotorRegMotorPower[motor], bPower);
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:TeamClutch2016,代码行数:15,代码来源:EasyLegacyMotorController.java

示例5: getMotorPower

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public synchronized double getMotorPower(int motor) {
    this.validateMotor(motor);
    byte bPower = this.i2cDeviceClient.read8(mpMotorRegMotorMode[motor]);

    // Float counts as zero power
    if (bPower == bPowerFloat)
        return 0.0;

    // Other values are just linear scaling. The clipping is just paranoia about
    // numerical precision; it probably isn't necessary
    double power = Range.scale(bPower, bPowerMin, bPowerMax, powerMin, powerMax);
    return Range.clip(power, powerMin, powerMax);
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:TeamClutch2016,代码行数:15,代码来源:EasyLegacyMotorController.java

示例6: runOpMode

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public void runOpMode() throws InterruptedException {
  motorLeft = hardwareMap.dcMotor.get("motor_1");
  motorRight = hardwareMap.dcMotor.get("motor_2");
  neck = hardwareMap.servo.get("servo_1");
  jaw = hardwareMap.servo.get("servo_6");

  motorLeft.setDirection(DcMotor.Direction.REVERSE);

  // set the starting position of the wrist and neck
  neckPosition = 0.5;

  waitForStart();

  while (opModeIsActive()) {
    // throttle:  left_stick_y ranges from -1 to 1, where -1 is full up,  and 1 is full down
    // direction: left_stick_x ranges from -1 to 1, where -1 is full left and 1 is full right
    float throttle  = -gamepad1.left_stick_y;
    float direction =  gamepad1.left_stick_x;
    float right = throttle - direction;
    float left  = throttle + direction;

    // clip the right/left values so that the values never exceed +/- 1
    right = Range.clip(right, -1, 1);
    left  = Range.clip(left,  -1, 1);

    // write the values to the motors
    motorRight.setPower(right);
    motorLeft.setPower(left);

    // update the position of the neck
    if (gamepad1.y) {
      neckPosition -= neckDelta;
    }

    if (gamepad1.a) {
      neckPosition += neckDelta;
    }

    // clip the position values so that they never exceed 0..1
    neckPosition = Range.clip(neckPosition, 0, 1);

    // set jaw position
    jawPosition = 1 - Range.scale(gamepad1.right_trigger, 0.0, 1.0, 0.3, 1.0);

    // write position values to the wrist and neck servo
    neck.setPosition(neckPosition);
    jaw.setPosition(jawPosition);

    telemetry.addData("Text", "K9TeleOp");
    telemetry.addData(" left motor", motorLeft.getPower());
    telemetry.addData("right motor", motorRight.getPower());
    telemetry.addData("neck", neck.getPosition());
    telemetry.addData("jaw", jaw.getPosition());

    waitOneFullHardwareCycle();
  }
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:FTC-Simple,代码行数:59,代码来源:LinearK9TeleOp.java

示例7: runOpMode

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public void runOpMode() throws InterruptedException {
    motorLeft = hardwareMap.dcMotor.get("motor_1");
    motorRight = hardwareMap.dcMotor.get("motor_2");
    neck = hardwareMap.servo.get("servo_1");
    jaw = hardwareMap.servo.get("servo_6");

    motorLeft.setDirection(DcMotor.Direction.REVERSE);

    // set the starting position of the wrist and neck
    neckPosition = 0.5;

    waitForStart();

    while (opModeIsActive()) {
        // throttle:  left_stick_y ranges from -1 to 1, where -1 is full up,  and 1 is full down
        // direction: left_stick_x ranges from -1 to 1, where -1 is full left and 1 is full right
        float throttle = -gamepad1.left_stick_y;
        float direction = gamepad1.left_stick_x;
        float right = throttle - direction;
        float left = throttle + direction;

        // clip the right/left values so that the values never exceed +/- 1
        right = Range.clip(right, -1, 1);
        left = Range.clip(left, -1, 1);

        // write the values to the motors
        motorRight.setPower(right);
        motorLeft.setPower(left);

        // update the position of the neck
        if (gamepad1.y) {
            neckPosition -= neckDelta;
        }

        if (gamepad1.a) {
            neckPosition += neckDelta;
        }

        // clip the position values so that they never exceed 0..1
        neckPosition = Range.clip(neckPosition, 0, 1);

        // set jaw position
        jawPosition = 1 - Range.scale(gamepad1.right_trigger, 0.0, 1.0, 0.3, 1.0);

        // write position values to the wrist and neck servo
        neck.setPosition(neckPosition);
        jaw.setPosition(jawPosition);

        telemetry.addData("Text", "K9TeleOp");
        telemetry.addData(" left motor", motorLeft.getPower());
        telemetry.addData("right motor", motorRight.getPower());
        telemetry.addData("neck", neck.getPosition());
        telemetry.addData("jaw", jaw.getPosition());

        waitOneFullHardwareCycle();
    }
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:TeamClutch2016,代码行数:59,代码来源:LinearK9TeleOp.java


注:本文中的com.qualcomm.robotcore.util.Range.scale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。