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


Java Servo.setPosition方法代码示例

本文整理汇总了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;
}
 
开发者ID:FTC7393,项目名称:EVLib,代码行数:25,代码来源:BasicServoControl.java

示例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;
}
 
开发者ID:FTC7393,项目名称:EVLib,代码行数:26,代码来源:ServoControl.java

示例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;
        }
    }
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:32,代码来源:RobotUtilities.java

示例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);
    }
 
开发者ID:forgod01,项目名称:5094-2016-2017,代码行数:36,代码来源:TestMotorServoLinear.java

示例5: moveServo

import com.qualcomm.robotcore.hardware.Servo; //导入方法依赖的package包/类
public void moveServo(Servo servo, double position) {
    servo.setPosition(position);
}
 
开发者ID:TinoShockwave,项目名称:Opmodes,代码行数:4,代码来源:AutonomousRed.java

示例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);



















}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:70,代码来源:RedAllianceCapBall.java

示例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);



















}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:71,代码来源:BlueAllianceCapBall.java

示例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);























}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:59,代码来源:BackupCode.java


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