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


Java Range.clip方法代码示例

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


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

示例1: holonomic

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
public static float[] holonomic(float joystick_turn, float joystick_speed, float
        joystick_strafe) {
    // Front Left Wheel: y - x + z (speed - turn + strafe)
    // Front Right Wheel: y + x - z (speed + turn - strafe)
    // Back Left Wheel: y + x + z (speed + turn + strafe)
    // Back Right Wheel: y - x - z (speed - turn - strafe)

    double mag = Math.abs(joystick_turn) + Math.abs(joystick_speed) + Math.abs(joystick_strafe);
    mag = Range.clip(mag, -1, 1);

    float fl, fr, bl, br;
    fl = (float)Range.clip((scaleInput(joystick_speed) - scaleInput(joystick_turn) + scaleInput
                    (joystick_strafe)), -mag, +mag);
    fr = (float)Range.clip((scaleInput(joystick_speed) + scaleInput(joystick_turn) - scaleInput
            (joystick_strafe)), -mag, +mag);
    bl = (float)Range.clip((scaleInput(joystick_speed) + scaleInput(joystick_turn) + scaleInput
            (joystick_strafe)), -mag, +mag);
    br = (float)Range.clip((scaleInput(joystick_speed) - scaleInput(joystick_turn) - scaleInput
            (joystick_strafe)), -mag, +mag);

    float[] motorVals = {fl, fr, bl, br};
    return motorVals;
}
 
开发者ID:FTC10794,项目名称:robolib,代码行数:24,代码来源:MotorFunctions.java

示例2: m_hand_position

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
/**
 * Mutate the hand position.
 */
void m_hand_position (double p_position)
{
    //
    // Ensure the specific value is legal.
    //
    double l_position = Range.clip
        ( p_position
        , Servo.MIN_POSITION
        , Servo.MAX_POSITION
        );

    //
    // Set the value.  The right hand value must be opposite of the left
    // value.
    //
    if (v_servo_left_hand != null)
    {
        v_servo_left_hand.setPosition (l_position);
    }
    if (v_servo_right_hand != null)
    {
        v_servo_right_hand.setPosition (1.0 - l_position);
    }

}
 
开发者ID:ftc8099,项目名称:resQ-2015,代码行数:29,代码来源:PushBotHardware.java

示例3: m_hand_position

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
/**
 * Mutate the hand position.
 */
void m_hand_position(double p_position) {
    //
    // Ensure the specific value is legal.
    //
    double l_position = Range.clip
            (p_position
                    , Servo.MIN_POSITION
                    , Servo.MAX_POSITION
            );

    //
    // Set the value.  The right hand value must be opposite of the left
    // value.
    //
    if (v_servo_left_hand != null) {
        v_servo_left_hand.setPosition(l_position);
    }
    if (v_servo_right_hand != null) {
        v_servo_right_hand.setPosition(1.0 - l_position);
    }

}
 
开发者ID:MHS-FIRSTrobotics,项目名称:TeamClutch2016,代码行数:26,代码来源:PushBotHardware.java

示例4: run

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
public void run()
{
    telemetry.addData("0:", "Running");
    super.init();
    //motorRight.setMode(DcMotorController.RunMode.RESET_ENCODERS);
    //motorLeft.setMode(DcMotorController.RunMode.RESET_ENCODERS);
    motorRight.setMode(DcMotorController.RunMode.RUN_TO_POSITION);
    motorLeft.setMode(DcMotorController.RunMode.RUN_TO_POSITION);
    float powerLeft = speed;
    float powerRight = speed;
    powerLeft = Range.clip(powerLeft, -1, 1);
    powerRight = Range.clip(powerRight, -1, 1);
    motorLeft.setTargetPosition(distance);
    motorLeft.setPower(powerLeft);
    motorRight.setTargetPosition(distance);
    motorRight.setPower(powerRight);

}
 
开发者ID:rollarobotics,项目名称:team4964,代码行数:19,代码来源:ForwardAction.java

示例5: run

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
public void run()
{
    //motorRight.setMode(DcMotorController.RunMode.RESET_ENCODERS);
    //motorLeft.setMode(DcMotorController.RunMode.RESET_ENCODERS);
    motorRight.setMode(DcMotorController.RunMode.RUN_TO_POSITION);
    motorLeft.setMode(DcMotorController.RunMode.RUN_TO_POSITION);
    float powerLeft = 0;
    float powerRight = 0;
    if(direction.equals("left"))
    {
        powerLeft = -speed;
        powerRight = speed;
    }
    if(direction.equals("right"))
    {
        powerLeft = speed;
        powerRight = -speed;
    }
    powerLeft = Range.clip(powerLeft, -1, 1);
    powerRight = Range.clip(powerRight, -1, 1);
    motorLeft.setTargetPosition(distance);
    motorLeft.setPower(powerLeft);
    motorRight.setTargetPosition(distance);
    motorRight.setPower(powerRight);
}
 
开发者ID:rollarobotics,项目名称:team4964,代码行数:26,代码来源:TurnAction.java

示例6: loop

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public void loop() {
    double left;
    double right;

    // Run wheels in tank mode (note: The joystick goes negative when pushed forwards, so negate it)
    left = -gamepad1.left_stick_y;
    right = -gamepad1.right_stick_y;
    robot.leftMotor.setPower(left);
    robot.rightMotor.setPower(right);

    // Use gamepad left & right Bumpers to open and close the claw
    if (gamepad1.right_bumper)
        clawOffset += CLAW_SPEED;
    else if (gamepad1.left_bumper)
        clawOffset -= CLAW_SPEED;

    // Move both servos to new position.  Assume servos are mirror image of each other.
    clawOffset = Range.clip(clawOffset, -0.5, 0.5);
    robot.leftClaw.setPosition(robot.MID_SERVO + clawOffset);
    robot.rightClaw.setPosition(robot.MID_SERVO - clawOffset);

    // Use gamepad buttons to move the arm up (Y) and down (A)
    if (gamepad1.y)
        robot.armMotor.setPower(robot.ARM_UP_POWER);
    else if (gamepad1.a)
        robot.armMotor.setPower(robot.ARM_DOWN_POWER);
    else
        robot.armMotor.setPower(0.0);

    // Send telemetry message to signify robot running;
    telemetry.addData("claw",  "Offset = %.2f", clawOffset);
    telemetry.addData("left",  "%.2f", left);
    telemetry.addData("right", "%.2f", right);
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:36,代码来源:PushbotTeleopTank_Iterative.java

示例7: loop

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public void loop() {
    double left;
    double right;

    // Run wheels in tank mode (note: The joystick goes negative when pushed forwards, so negate it)
    left = -gamepad1.left_stick_y;
    right = -gamepad1.right_stick_y;

    robot.leftDrive.setPower(left);
    robot.rightDrive.setPower(right);

    // Use gamepad left & right Bumpers to open and close the claw
    if (gamepad1.right_bumper)
        clawOffset += CLAW_SPEED;
    else if (gamepad1.left_bumper)
        clawOffset -= CLAW_SPEED;

    // Move both servos to new position.  Assume servos are mirror image of each other.
    clawOffset = Range.clip(clawOffset, -0.5, 0.5);
    robot.leftClaw.setPosition(robot.MID_SERVO + clawOffset);
    robot.rightClaw.setPosition(robot.MID_SERVO - clawOffset);

    // Use gamepad buttons to move the arm up (Y) and down (A)
    if (gamepad1.y)
        robot.leftArm.setPower(robot.ARM_UP_POWER);
    else if (gamepad1.a)
        robot.leftArm.setPower(robot.ARM_DOWN_POWER);
    else
        robot.leftArm.setPower(0.0);

    // Send telemetry message to signify robot running;
    telemetry.addData("claw",  "Offset = %.2f", clawOffset);
    telemetry.addData("left",  "%.2f", left);
    telemetry.addData("right", "%.2f", right);
}
 
开发者ID:trc492,项目名称:Ftc2018RelicRecovery,代码行数:37,代码来源:PushbotTeleopTank_Iterative.java

示例8: loop

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public void loop() {
    // Setup a variable for each drive wheel to save power level for telemetry
    double leftPower;
    double rightPower;

    // Choose to drive using either Tank Mode, or POV Mode
    // Comment out the method that's not used.  The default below is POV.

    // POV Mode uses left stick to go forward, and right stick to turn.
    // - This uses basic math to combine motions and is easier to drive straight.
    double drive = -gamepad1.left_stick_y;
    double turn  =  gamepad1.right_stick_x;
    leftPower    = Range.clip(drive + turn, -1.0, 1.0) ;
    rightPower   = Range.clip(drive - turn, -1.0, 1.0) ;

    // Tank Mode uses one stick to control each wheel.
    // - This requires no math, but it is hard to drive forward slowly and keep straight.
    // leftPower  = -gamepad1.left_stick_y ;
    // rightPower = -gamepad1.right_stick_y ;

    // Send calculated power to wheels
    leftDrive.setPower(leftPower);
    rightDrive.setPower(rightPower);

    // Show the elapsed game time and wheel power.
    telemetry.addData("Status", "Run Time: " + runtime.toString());
    telemetry.addData("Motors", "left (%.2f), right (%.2f)", leftPower, rightPower);
}
 
开发者ID:trc492,项目名称:Ftc2018RelicRecovery,代码行数:30,代码来源:BasicOpMode_Iterative.java

示例9: loop

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public void loop() {
    double left;
    double right;

    // Run wheels in tank mode (note: The joystick goes negative when pushed forwards, so negate it)
    left = -gamepad1.left_stick_y;
    right = -gamepad1.right_stick_y;
    robot.leftMotor.setPower(left);
    robot.rightMotor.setPower(right);

    // Use gamepad left & right Bumpers to open and close the claw
    if (gamepad1.right_bumper)
        clawOffset += CLAW_SPEED;
    else if (gamepad1.left_bumper)
        clawOffset -= CLAW_SPEED;

    // Move both servos to new position.  Assume servos are mirror image of each other.
    clawOffset = Range.clip(clawOffset, -0.5, 0.5);
    robot.leftClaw.setPosition(robot.MID_SERVO + clawOffset);
    robot.rightClaw.setPosition(robot.MID_SERVO - clawOffset);

    // Use gamepad buttons to move the arm up (Y) and down (A)
    if (gamepad1.y)
        robot.armMotor.setPower(robot.ARM_UP_POWER);
    else if (gamepad1.a)
        robot.armMotor.setPower(robot.ARM_DOWN_POWER);
    else
        robot.armMotor.setPower(0.0);

    // Send telemetry message to signify robot running;
    telemetry.addData("claw",  "Offset = %.2f", clawOffset);
    telemetry.addData("left",  "%.2f", left);
    telemetry.addData("right", "%.2f", right);
    updateTelemetry(telemetry);
}
 
开发者ID:forgod01,项目名称:5094-2016-2017,代码行数:37,代码来源:PushbotTeleopTank_Iterative.java

示例10: handleGamePad1

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public void handleGamePad1(Gamepad gamepad) {
    long now = System.currentTimeMillis();
    if (gamepad.x) {
        if (now > lastDpad + 1000) {
            movementController.setWheelPower(1d);
            movementController.strafeLeft(distance);
            lastDpad = now;
        }
    } else if (gamepad.y) {
        if (now > lastDpad + 1000) {
            movementController.setWheelPower(1d);
            movementController.strafeRight(distance);
            lastDpad = now;
        }
    } else if (gamepad.a) {
        movementController.setWheelPower(0.4);
        movementController.turn(90);
    } else if (gamepad.b) {
        movementController.setWheelPower(0.4);
        movementController.turn(-90);
    } else if (gamepad.dpad_up) {
        if (now > lastDpad + 100) {
            distance = Range.clip(distance + 0.05, 0, 3);
            lastDpad = now;
        }
    } else if (gamepad.dpad_down) {
        if (now > lastDpad + 100) {
            distance = Range.clip(distance - 0.05, 0, 3);
            lastDpad = now;
        }
    } else if(gamepad.dpad_left || gamepad.dpad_right)  {
        movementController.stopMoving();
    }
    telemetry.addData("teleop", "distance:%.2f", distance);
}
 
开发者ID:FTC7729,项目名称:2016-FTC,代码行数:37,代码来源:TestMovementControllerTeleOp.java

示例11: runOpMode

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
@Override
public void runOpMode() throws InterruptedException {
    irSeeker = hardwareMap.irSeekerSensor.get("sensor_ir");
    leftMotor = hardwareMap.dcMotor.get("left_drive");
    rightMotor = hardwareMap.dcMotor.get("right_drive");
    rightMotor.setDirection(DcMotor.Direction.REVERSE);

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

    // Continuously track the IR beacon
    while(opModeIsActive()) {
        double angle = irSeeker.getAngle() / 30;  // value between -4...4
        double strength = irSeeker.getStrength();
        if (strength>kMinimumStrength && strength<kMaximumStrength) {
            double leftSpeed = Range.clip(kBaseSpeed + (angle / 8), -1, 1);
            double rightSpeed = Range.clip(kBaseSpeed - (angle / 8), -1, 1);
            leftMotor.setPower(leftSpeed);
            rightMotor.setPower(rightSpeed);
        } else {
            leftMotor.setPower(0);
            rightMotor.setPower(0);
        }
        telemetry.addData("Seeker", irSeeker.toString());
        telemetry.addData("Speed", " Left=" + leftMotor.getPower() + " Right=" + rightMotor.getPower());

        //Wait one hardware cycle to avoid taxing the processor
        waitOneFullHardwareCycle();
    }

}
 
开发者ID:FTCTeam4991,项目名称:FTC2015-2016Game,代码行数:32,代码来源:PushBotIrSeek.java

示例12: 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

示例13: 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

示例14: 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

示例15: scale_motor_power

import com.qualcomm.robotcore.util.Range; //导入方法依赖的package包/类
/**
 * Scale the joystick input using a nonlinear algorithm.
 */
float scale_motor_power(float p_power) {
    //
    // Assume no scaling.
    //
    float l_scale = 0.0f;

    //
    // Ensure the values are legal.
    //
    float l_power = Range.clip(p_power, -1, 1);

    float[] l_array =
            {0.00f, 0.05f, 0.09f, 0.10f, 0.12f
                    , 0.15f, 0.18f, 0.24f, 0.30f, 0.36f
                    , 0.43f, 0.50f, 0.60f, 0.72f, 0.85f
                    , 1.00f, 1.00f
            };

    //
    // Get the corresponding index for the specified argument/parameter.
    //
    int l_index = (int) (l_power * 16.0);
    if (l_index < 0) {
        l_index = -l_index;
    } else if (l_index > 16) {
        l_index = 16;
    }

    if (l_power < 0) {
        l_scale = -l_array[l_index];
    } else {
        l_scale = l_array[l_index];
    }

    return l_scale;

}
 
开发者ID:MHS-FIRSTrobotics,项目名称:TeamClutch2016,代码行数:41,代码来源:PushBotHardware.java


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