本文整理汇总了Java中com.qualcomm.robotcore.hardware.Servo.setPosition方法的典型用法代码示例。如果您正苦于以下问题:Java Servo.setPosition方法的具体用法?Java Servo.setPosition怎么用?Java Servo.setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.qualcomm.robotcore.hardware.Servo
的用法示例。
在下文中一共展示了Servo.setPosition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BasicServoControl
import com.qualcomm.robotcore.hardware.Servo; //导入方法依赖的package包/类
public BasicServoControl(Servo servo, ServoName name, Enum startPreset) {
this.servo = servo;
this.name = name;
OptionsFile optionsFile = new OptionsFile(FileUtil.getFile(ServoCfg.getServoFilename(name)));
presets = new HashMap<>();
for (Enum preset : name.getPresets()) {
double servoPosition = 0.5;
try {
servoPosition = optionsFile.getAsDouble(preset.name(), 0.5);
} catch (NullPointerException e) {
e.printStackTrace();
}
presets.put(preset, servoPosition);
}
targetPosition = presets.get(startPreset);
currentPosition = targetPosition;
servo.setPosition(targetPosition);
speed = MAX_SPEED;
}
示例2: ServoControl
import com.qualcomm.robotcore.hardware.Servo; //导入方法依赖的package包/类
/**
* Create a ServoControl to wrap a Servo
*
* @param servo the servo to control
* @param name the name of the servo (also contains servo info)
* @param startPreset the preset to start at
*/
public ServoControl(Servo servo, ServoName name, Enum startPreset) {
this.servo = servo;
this.name = name;
OptionsFile optionsFile = new OptionsFile(EVConverters.getInstance(), ServoCfg.getServoFile(name));
presets = new HashMap<>();
for (Enum preset : name.getPresets()) {
double servoPosition = optionsFile.get(preset.name(), 0.5);
presets.put(preset, servoPosition);
}
targetPosition = presets.get(startPreset);
currentPosition = targetPosition;
servo.setPosition(targetPosition);
speed = MAX_SPEED;
}
示例3: toggleBeaconPresser
import com.qualcomm.robotcore.hardware.Servo; //导入方法依赖的package包/类
public void toggleBeaconPresser(Servo servo) {
if (servo == robot.leftBeacon) {
if (!leftBeaconPusherExtended) {
while (RobotConstants.leftBeaconPusherPosition != RobotConstants.SERVO_MAX) {
RobotConstants.leftBeaconPusherPosition += RobotConstants.beaconPusherSpeed;
servo.setPosition(RobotConstants.leftBeaconPusherPosition);
}
leftBeaconPusherExtended = true;
} else {
while (RobotConstants.leftBeaconPusherPosition != RobotConstants.SERVO_MIN) {
RobotConstants.leftBeaconPusherPosition -= RobotConstants.beaconPusherSpeed;
servo.setPosition(RobotConstants.leftBeaconPusherPosition);
}
leftBeaconPusherExtended = false;
}
} else if (servo == robot.rightBeacon) {
if (!rightBeaconPusherExtended) {
while (RobotConstants.rightBeaconPusherPosition != RobotConstants.SERVO_MAX + RobotConstants.beaconPusherSpeed) {
RobotConstants.rightBeaconPusherPosition += RobotConstants.beaconPusherSpeed;
servo.setPosition(RobotConstants.rightBeaconPusherPosition);
}
rightBeaconPusherExtended = true;
} else {
while (RobotConstants.rightBeaconPusherPosition != RobotConstants.SERVO_MIN) {
RobotConstants.rightBeaconPusherPosition -= RobotConstants.beaconPusherSpeed;
servo.setPosition(RobotConstants.rightBeaconPusherPosition);
}
rightBeaconPusherExtended = false;
}
}
}
示例4: runOpMode
import com.qualcomm.robotcore.hardware.Servo; //导入方法依赖的package包/类
@Override
public void runOpMode() throws InterruptedException
{
DcMotor motor = this.hardwareMap.dcMotor.get("motorRight");
Servo servo = this.hardwareMap.servo.get("servo");
waitForStart();
double servoPosition = 0;
servo.setPosition(servoPosition);
motor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
ElapsedTime elapsedTime = new ElapsedTime();
int spinCount = 0;
while (this.opModeIsActive())
{
servoPosition += 1. / 256.;
if (servoPosition >= 1)
servoPosition = 0;
servo.setPosition(servoPosition);
motor.setPower(0.15);
spinCount++;
double ms = elapsedTime.milliseconds();
telemetry.addData("position", format(servoPosition));
telemetry.addData("#spin", format(spinCount));
telemetry.addData("ms/spin", format(ms / spinCount));
this.updateTelemetry(telemetry);
}
motor.setPower(0);
}
示例5: moveServo
import com.qualcomm.robotcore.hardware.Servo; //导入方法依赖的package包/类
public void moveServo(Servo servo, double position) {
servo.setPosition(position);
}
示例6: runOpMode
import com.qualcomm.robotcore.hardware.Servo; //导入方法依赖的package包/类
@Override
public void runOpMode() throws InterruptedException {
FrontRight= (DcMotor) hardwareMap.get("FrontRight");
FrontLeft= (DcMotor) hardwareMap.get("FrontLeft");
BackRight= (DcMotor) hardwareMap.get("BackRight");
BackLeft= (DcMotor) hardwareMap.get("BackLeft");
Beacon= (Servo) hardwareMap.get("Beacon");
launcher=(DcMotor) hardwareMap.get("Launcher");
bd= (Servo) hardwareMap.get("BD");
FrontRight.setDirection(DcMotorSimple.Direction.REVERSE);
BackRight.setDirection(DcMotorSimple.Direction.REVERSE);
sleep(1000);
launcher.setPower(1.0);
sleep(1000);
launcher.setPower(0.0);
bd.setPosition(180d);
sleep(1400);
launcher.setPower(1.0);
sleep(1000);
launcher.setPower(0.0);
sleep(100);
FrontRight.setPower(1.0);
FrontLeft.setPower(1.0);
BackRight.setPower(1.0);
BackLeft.setPower(1.0);
sleep(2300);
FrontRight.setPower(0.0);
FrontLeft.setPower(0.0);
BackRight.setPower(0.0);
BackLeft.setPower(0.0);
}
示例7: runOpMode
import com.qualcomm.robotcore.hardware.Servo; //导入方法依赖的package包/类
@Override
public void runOpMode() throws InterruptedException {
FrontRight= (DcMotor) hardwareMap.get("FrontRight");
FrontLeft= (DcMotor) hardwareMap.get("FrontLeft");
BackRight= (DcMotor) hardwareMap.get("BackRight");
BackLeft= (DcMotor) hardwareMap.get("BackLeft");
Beacon= (Servo) hardwareMap.get("Beacon");
launcher=(DcMotor) hardwareMap.get("Launcher");
bd= (Servo) hardwareMap.get("BD");
FrontRight.setDirection(DcMotorSimple.Direction.REVERSE);
BackRight.setDirection(DcMotorSimple.Direction.REVERSE);
sleep(1000);
launcher.setPower(1.0);
sleep(1000);
launcher.setPower(0.0);
bd.setPosition(180d);
sleep(1400);
launcher.setPower(1.0);
sleep(1000);
launcher.setPower(0.0);
sleep(100);
FrontRight.setPower(1.0);
FrontLeft.setPower(1.0);
BackRight.setPower(1.0);
BackLeft.setPower(1.0);
sleep(2300);
FrontRight.setPower(0.0);
FrontLeft.setPower(0.0);
BackRight.setPower(0.0);
BackLeft.setPower(0.0);
}
示例8: runOpMode
import com.qualcomm.robotcore.hardware.Servo; //导入方法依赖的package包/类
@Override
public void runOpMode() throws InterruptedException {
FrontRight= (DcMotor) hardwareMap.get("FrontRight");
FrontLeft= (DcMotor) hardwareMap.get("FrontLeft");
BackRight= (DcMotor) hardwareMap.get("BackRight");
BackLeft= (DcMotor) hardwareMap.get("BackLeft");
Beacon= (Servo) hardwareMap.get("Beacon");
launcher=(DcMotor) hardwareMap.get("Launcher");
bd= (Servo) hardwareMap.get("BD");
FrontRight.setDirection(DcMotorSimple.Direction.REVERSE);
BackRight.setDirection(DcMotorSimple.Direction.REVERSE);
sleep(1000);
launcher.setPower(1.0);
sleep(1000);
launcher.setPower(0.0);
bd.setPosition(180d);
sleep(1400);
launcher.setPower(1.0);
sleep(1000);
launcher.setPower(0.0);
}