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


Java Servo类代码示例

本文整理汇总了Java中com.qualcomm.robotcore.hardware.Servo的典型用法代码示例。如果您正苦于以下问题:Java Servo类的具体用法?Java Servo怎么用?Java Servo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: init

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的package包/类
public void init(HardwareMap ahwMap) {
    // save reference to HW Map
    hwMap = ahwMap;

    // Define and Initialize Motors
    leftDrive  = hwMap.get(DcMotor.class, "left_drive");
    rightDrive = hwMap.get(DcMotor.class, "right_drive");
    leftDrive.setDirection(DcMotor.Direction.REVERSE);

    // Set all motors to zero power
    leftDrive.setPower(0);
    rightDrive.setPower(0);

    // Set all motors to run without encoders.
    // May want to use RUN_USING_ENCODERS if encoders are installed.
    leftDrive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
    rightDrive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);

    // Define and initialize ALL installed servos.
    arm  = hwMap.get(Servo.class, "arm");
    claw = hwMap.get(Servo.class, "claw");
    arm.setPosition(ARM_HOME);
    claw.setPosition(CLAW_HOME);
}
 
开发者ID:trc492,项目名称:Ftc2018RelicRecovery,代码行数:25,代码来源:HardwareK9bot.java

示例2: init

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的package包/类
@Override
public void init(){
    motor1 = hardwareMap.dcMotor.get("motor1");
    motor1.setDirection(DcMotor.Direction.REVERSE);
    motor2 = hardwareMap.dcMotor.get("motor2");
    motor2.setDirection(DcMotor.Direction.FORWARD);

    motor3 = hardwareMap.dcMotor.get("motor3");
    motor3.setDirection(DcMotor.Direction.REVERSE);
    motor4 = hardwareMap.dcMotor.get("motor4");
    motor4.setDirection(DcMotor.Direction.FORWARD);

    motor5 = hardwareMap.dcMotor.get("motor5");
    motor5.setDirection(DcMotor.Direction.REVERSE);
    motor6 = hardwareMap.dcMotor.get("motor6");
    motor6.setDirection(DcMotor.Direction.FORWARD);

    leftcr = hardwareMap.servo.get("leftcr");
    rightcr = hardwareMap.servo.get("rightcr");

    leftcr.setDirection(Servo.Direction.REVERSE);
    rightcr.setDirection(Servo.Direction.FORWARD);
}
 
开发者ID:SCHS-Robotics,项目名称:Team9261-2017-2018,代码行数:24,代码来源:MecanumDrive.java

示例3: m_hand_position

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的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,项目名称:FTC-Simple,代码行数:29,代码来源:PushBotHardware.java

示例4: open_hand

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的package包/类
/**
 * Open the hand to its fullest.
 */
void open_hand ()

{
    //
    // 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 (Servo.MAX_POSITION);
    }
    if (v_servo_right_hand != null)
    {
        v_servo_right_hand.setPosition (Servo.MIN_POSITION);
    }

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

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

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

示例7: createServoMap

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的package包/类
/**
 * create a map that links ServoName to ServoControl
 *
 * @param hardwareMap         retrieves the servos from here
 * @param servoStartPresetMap the map that assigns a start preset to each ServoName
 * @return the created servoMap
 */
public static Map<ServoName, ServoControl> createServoMap(HardwareMap hardwareMap, Map<ServoName, Enum> servoStartPresetMap) {
    Map<ServoName, ServoControl> servoMap = new HashMap<>(); //create the map

    //loop through the start preset map
    for (Map.Entry<ServoName, Enum> entry : servoStartPresetMap.entrySet()) {
        ServoName servoName = entry.getKey();
        Enum preset = entry.getValue();

        //get the servo from the hardwareMap
        Servo servo = hardwareMap.servo.get(servoName.getHardwareName());

        //create a ServoControl from that servo
        ServoControl servoControl = new ServoControl(servo, servoName, preset);
        servoMap.put(servoName, servoControl); //add it to the map
    }

    return servoMap; //return the map
}
 
开发者ID:FTC7393,项目名称:EVLib,代码行数:26,代码来源:ServoCfg.java

示例8: m_hand_position

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的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

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

示例10: setInverted

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的package包/类
/**
 * This methods inverts the servo motor direction.
 *
 * @param inverted specifies true if the servo direction is inverted, false otherwise.
 */
@Override
public void setInverted(boolean inverted)
{
    final String funcName = "setInverted";

    if (debugEnabled)
    {
        dbgTrace.traceEnter(funcName, TrcDbgTrace.TraceLevel.API, "inverted=%s", Boolean.toString(inverted));
        dbgTrace.traceExit(funcName, TrcDbgTrace.TraceLevel.API);
    }

    servo.setDirection(inverted? Servo.Direction.REVERSE: Servo.Direction.FORWARD);
}
 
开发者ID:trc492,项目名称:Ftc2018RelicRecovery,代码行数:19,代码来源:FtcServo.java

示例11: getInverted

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的package包/类
/**
 * This method returns true if the servo direction is inverted.
 *
 * @return true if the servo direction is inverted, false otherwise.
 */
@Override
public boolean getInverted()
{
    final String funcName = "getInverted";
    boolean isInverted = servo.getDirection() == Servo.Direction.REVERSE;;

    if (debugEnabled)
    {
        dbgTrace.traceEnter(funcName, TrcDbgTrace.TraceLevel.API);
        dbgTrace.traceExit(funcName, TrcDbgTrace.TraceLevel.API, "=%s", isInverted);
    }

    return isInverted;
}
 
开发者ID:trc492,项目名称:Ftc2018RelicRecovery,代码行数:20,代码来源:FtcServo.java

示例12: init

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的package包/类
public void init(HardwareMap ahwMap) {
    // Save reference to Hardware map
    hwMap = ahwMap;

    // Define and Initialize Motors
    leftDrive  = hwMap.get(DcMotor.class, "left_drive");
    rightDrive = hwMap.get(DcMotor.class, "right_drive");
    leftArm    = hwMap.get(DcMotor.class, "left_arm");
    leftDrive.setDirection(DcMotor.Direction.FORWARD); // Set to REVERSE if using AndyMark motors
    rightDrive.setDirection(DcMotor.Direction.REVERSE);// Set to FORWARD if using AndyMark motors

    // Set all motors to zero power
    leftDrive.setPower(0);
    rightDrive.setPower(0);
    leftArm.setPower(0);

    // Set all motors to run without encoders.
    // May want to use RUN_USING_ENCODERS if encoders are installed.
    leftDrive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
    rightDrive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
    leftArm.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);

    // Define and initialize ALL installed servos.
    leftClaw  = hwMap.get(Servo.class, "left_hand");
    rightClaw = hwMap.get(Servo.class, "right_hand");
    leftClaw.setPosition(MID_SERVO);
    rightClaw.setPosition(MID_SERVO);
}
 
开发者ID:trc492,项目名称:Ftc2018RelicRecovery,代码行数:29,代码来源:HardwarePushbot.java

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

示例14: createDeviceMaps

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的package包/类
/**
 * Move the propriety {@link HardwareMap.DeviceMapping} to our {@link DeviceMap} for our
 * internal use
 */
private void createDeviceMaps() {
    fullMap.checkedPut(DcMotorController.class, new DeviceMap<>(basicMap.dcMotorController));
    fullMap.checkedPut(DcMotor.class, new DeviceMap<>(basicMap.dcMotor));
    fullMap.checkedPut(ServoController.class, new DeviceMap<>(basicMap.servoController));
    fullMap.checkedPut(Servo.class, new DeviceMap<>(basicMap.servo));
    fullMap.checkedPut(LegacyModule.class, new DeviceMap<>(basicMap.legacyModule));
    fullMap.checkedPut(TouchSensorMultiplexer.class, new DeviceMap<>(basicMap.touchSensorMultiplexer));
    fullMap.checkedPut(DeviceInterfaceModule.class, new DeviceMap<>(basicMap.deviceInterfaceModule));
    fullMap.checkedPut(AnalogInput.class, new DeviceMap<>(basicMap.analogInput));
    fullMap.checkedPut(DigitalChannel.class, new DeviceMap<>(basicMap.digitalChannel));
    fullMap.checkedPut(OpticalDistanceSensor.class, new DeviceMap<>(basicMap.opticalDistanceSensor));
    fullMap.checkedPut(TouchSensor.class, new DeviceMap<>(basicMap.touchSensor));
    fullMap.checkedPut(PWMOutput.class, new DeviceMap<>(basicMap.pwmOutput));
    fullMap.checkedPut(I2cDevice.class, new DeviceMap<>(basicMap.i2cDevice));
    fullMap.checkedPut(AnalogOutput.class, new DeviceMap<>(basicMap.analogOutput));
    fullMap.checkedPut(ColorSensor.class, new DeviceMap<>(basicMap.colorSensor));
    fullMap.checkedPut(LED.class, new DeviceMap<>(basicMap.led));
    fullMap.checkedPut(AccelerationSensor.class, new DeviceMap<>(basicMap.accelerationSensor));
    fullMap.checkedPut(CompassSensor.class, new DeviceMap<>(basicMap.compassSensor));
    fullMap.checkedPut(GyroSensor.class, new DeviceMap<>(basicMap.gyroSensor));
    fullMap.checkedPut(IrSeekerSensor.class, new DeviceMap<>(basicMap.irSeekerSensor));
    fullMap.checkedPut(LightSensor.class, new DeviceMap<>(basicMap.lightSensor));
    fullMap.checkedPut(UltrasonicSensor.class, new DeviceMap<>(basicMap.ultrasonicSensor));
    fullMap.checkedPut(VoltageSensor.class, new DeviceMap<>(basicMap.voltageSensor));

    LinkedHashMultimap<DcMotorController, DcMotor> multimap = LinkedHashMultimap.create();
    for (DcMotor motor : dcMotors()) {
        multimap.put(motor.getController(), motor);
    }
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:35,代码来源:ExtensibleHardwareMap.java

示例15: open_hand

import com.qualcomm.robotcore.hardware.Servo; //导入依赖的package包/类
/**
 * Open the hand to its fullest.
 */
void open_hand() {
    //
    // 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(Servo.MAX_POSITION);
    }
    if (v_servo_right_hand != null) {
        v_servo_right_hand.setPosition(Servo.MIN_POSITION);
    }

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


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