本文整理汇总了Java中com.qualcomm.robotcore.util.Range类的典型用法代码示例。如果您正苦于以下问题:Java Range类的具体用法?Java Range怎么用?Java Range使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Range类属于com.qualcomm.robotcore.util包,在下文中一共展示了Range类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import com.qualcomm.robotcore.util.Range; //导入依赖的package包/类
@Override
public void handle() {
Vector inputVector = new Vector(robot.gamepad1.left_stick_x, -robot.gamepad1.left_stick_y); //gamepads are weird, -1 is at the top of the y axis
Vector motionVector = inputVector.rotate(-Math.PI / 4);
if (robot.gamepad1.left_bumper && motionVector.isZeroVector()) {
motor1.setPower(-1);
motor2.setPower(1);
motor3.setPower(1);
motor4.setPower(-1);
}
else if (robot.gamepad1.right_bumper && motionVector.isZeroVector()) {
motor1.setPower(1);
motor2.setPower(-1);
motor3.setPower(-1);
motor4.setPower(1);
} else {
double offset = (robot.gamepad1.left_trigger - robot.gamepad1.right_trigger) / 4;
motor1.setPower(Range.clip(motionVector.x - offset, -1, 1));
motor2.setPower(Range.clip(motionVector.y + offset, -1, 1));
motor3.setPower(Range.clip(motionVector.y - offset, -1, 1));
motor4.setPower(Range.clip(motionVector.x + offset, -1, 1));
}
}
示例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);
}
}
示例3: 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;
}
示例4: drive
import com.qualcomm.robotcore.util.Range; //导入依赖的package包/类
@Override
public void drive(double x, double y, double rotPower) {
//double transLength = Math.hypot(x, y);
double adjY = y;
double adjX = x;
double frontLeft = adjY + adjX + rotPower;
double frontRight = adjY - adjX - rotPower;
double backRight = adjY + adjX - rotPower;
double backLeft = adjY - adjX + rotPower;
frontLeft = Range.clip(frontLeft, -1, 1);
frontRight = Range.clip(frontRight, -1, 1);
backLeft = Range.clip(backLeft, -1, 1);
backRight = Range.clip(backRight, -1, 1);
frontLeft *= hwInterface.disableMap[0];
frontRight *= hwInterface.disableMap[1];
backLeft *= hwInterface.disableMap[2];
backRight *= hwInterface.disableMap[3];
hwInterface.leftFront.setPower(frontLeft);
hwInterface.rightFront.setPower(frontRight);
hwInterface.leftRear.setPower(backLeft);
hwInterface.rightRear.setPower(backRight);
}
示例5: 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);
}
}
示例6: 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);
}
}
示例7: loop
import com.qualcomm.robotcore.util.Range; //导入依赖的package包/类
@Override
public void loop() {
double rightDriveMotorsSpeed = -gamepad1.right_stick_y;
double leftDriveMotorsSpeed = -gamepad1.left_stick_y;
rightDriveMotorsSpeed = Range.clip(rightDriveMotorsSpeed, -1, 1);
leftDriveMotorsSpeed = Range.clip(leftDriveMotorsSpeed, -1, 1);
rightDriveMotorsSpeed = scaleInput(rightDriveMotorsSpeed);
leftDriveMotorsSpeed = scaleInput(leftDriveMotorsSpeed);
driveRightFront.setPower(rightDriveMotorsSpeed);
driveRightBack.setPower(rightDriveMotorsSpeed);
driveLeftFront.setPower(leftDriveMotorsSpeed);
driveLeftBack.setPower(leftDriveMotorsSpeed);
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
示例11: 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);
}
示例12: 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);
}
示例13: loop
import com.qualcomm.robotcore.util.Range; //导入依赖的package包/类
@Override
public void loop(){
double x = gamepad1.left_stick_x;
double y = gamepad1.left_stick_y;
double c = gamepad1.left_trigger-gamepad1.right_trigger;
motor1.setPower(Range.clip(y-x+c, -1, 1));
motor2.setPower(Range.clip(y+x-c, -1, 1));
motor3.setPower(Range.clip(y+x+c, -1, 1));
motor4.setPower(Range.clip(y-x-c, -1, 1));
if(gamepad1.right_bumper){
if(gamepad1.x){
motor5.setPower(1);
motor6.setPower(1);
}else {
motor5.setPower(0.7);
motor6.setPower(0.65);
}
leftcr.setPosition(1);
rightcr.setPosition(1);
}else if(gamepad1.left_bumper) {
motor5.setPower(-1);
motor6.setPower(-1);
leftcr.setPosition(-1);
rightcr.setPosition(-1);
}else{
motor5.setPower(0);
motor6.setPower(0);
leftcr.setPosition(0);
rightcr.setPosition(0);
}
}
示例14: 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);
}
示例15: 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();
}
}