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


Java DcMotor.RunMode方法代码示例

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


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

示例1: MotorMode

import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
private void MotorMode(DcMotor.RunMode mode)
{
    leftMotorBack.setMode(mode);
    leftMotorFront.setMode(mode);
    rightMotorBack.setMode(mode);
    rightMotorFront.setMode(mode);
}
 
开发者ID:nomelif,项目名称:ControlCodesRepo,代码行数:8,代码来源:OPMode.java

示例2: reportMotor

import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
void reportMotor(String caption, DcMotor motor)
{
if (motor != null)
    {
    int position = motor.getCurrentPosition();
    DcMotor.RunMode mode = motor.getMode();

    telemetry.addLine(caption)
        .addData("pos", "%d", position)
        .addData("mode", "%s", mode.toString());

    RobotLog.i("%s pos=%d mode=%s", caption, position, mode.toString());
    }
}
 
开发者ID:forgod01,项目名称:5094-2016-2017,代码行数:15,代码来源:TestMotorControllerFlavors.java

示例3: dcMotorInit

import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
/**
 * Initialize a dcMotor by setting parameters and checking that they were set properly
 *
 * @param dcMotor  the motor to initialize
 * @param reversed whether or not the motor direction should be reversed
 * @param brake    whether to brake or float when stopping
 * @param runMode  what mode to start the motor in
 */
private static void dcMotorInit(DcMotor dcMotor, boolean reversed, boolean brake, DcMotor.RunMode runMode) {
    //reset the encoder position to zero
    do {
        dcMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
    } while (dcMotor.getMode() != DcMotor.RunMode.STOP_AND_RESET_ENCODER);

    //determine the motor's direction as a Direction object
    DcMotor.Direction direction;
    if (reversed) {
        direction = DcMotorSimple.Direction.REVERSE;
    } else {
        direction = DcMotorSimple.Direction.FORWARD;
    }

    //set the motor's direction
    do {
        dcMotor.setDirection(direction);
    } while (dcMotor.getDirection() != direction);

    //set the motor's mode
    do {
        dcMotor.setMode(runMode);
    } while (dcMotor.getMode() != runMode);

    //determine the ZeroPowerBehavior
    DcMotor.ZeroPowerBehavior zeroPowerBehavior;
    if (brake) {
        zeroPowerBehavior = DcMotor.ZeroPowerBehavior.BRAKE;
    } else {
        zeroPowerBehavior = DcMotor.ZeroPowerBehavior.FLOAT;
    }

    //set the motor's ZeroPowerBehavior
    do {
        dcMotor.setZeroPowerBehavior(zeroPowerBehavior);
    } while (dcMotor.getZeroPowerBehavior() != zeroPowerBehavior);
}
 
开发者ID:FTC7393,项目名称:EVLib,代码行数:46,代码来源:Motors.java

示例4: motorModeToDcMotorRunMode

import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
/**
 * Convert a Motor.MotorMode to a DcMotor.RunMode
 *
 * @param mode the mode to convert
 * @return the corresponding DcMotor.RunMode
 */
public static DcMotor.RunMode motorModeToDcMotorRunMode(Motor.Mode mode) {
    switch (mode) {
        case POWER:
            return DcMotor.RunMode.RUN_WITHOUT_ENCODER;
        case SPEED:
            return DcMotor.RunMode.RUN_USING_ENCODER;
        case POSITION:
            return DcMotor.RunMode.RUN_TO_POSITION;
        default:
            return null;
    }
}
 
开发者ID:FTC7393,项目名称:EVLib,代码行数:19,代码来源:Motors.java

示例5: dcMotorRunModeToMotorMode

import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
/**
 * Convert a DcMotor.RunMode to a Motor.Mode
 *
 * @param runMode the mode to convert
 * @return the corresponding Motor.Mode
 */
public static Motor.Mode dcMotorRunModeToMotorMode(DcMotor.RunMode runMode) {
    switch (runMode) {
        case RUN_WITHOUT_ENCODER:
            return Motor.Mode.POWER;
        case RUN_USING_ENCODER:
            return Motor.Mode.SPEED;
        case RUN_TO_POSITION:
            return Motor.Mode.POSITION;
        default:
            return null;
    }
}
 
开发者ID:FTC7393,项目名称:EVLib,代码行数:19,代码来源:Motors.java

示例6: setDriveMotorMode

import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
public void setDriveMotorMode(DcMotor.RunMode mode) {
    for (DcMotor motor : driveMotors) {
        motor.setMode(mode);
    }
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:6,代码来源:Robot.java

示例7: setModes

import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
void setModes(DcMotor.RunMode mode)
{
if (legacyMotor != null) legacyMotor.setMode(mode);
if (v15Motor != null)    v15Motor.setMode(mode);
if (v2Motor != null)     v2Motor.setMode(mode);
}
 
开发者ID:forgod01,项目名称:5094-2016-2017,代码行数:7,代码来源:TestMotorControllerFlavors.java

示例8: runOpMode

import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
public void runOpMode() throws InterruptedException
{
motor = hardwareMap.dcMotor.get("v1.5 motor");

DcMotor.RunMode[] modes = new DcMotor.RunMode[]
    {
    DcMotor.RunMode.RUN_WITHOUT_ENCODER,        // 1
    DcMotor.RunMode.RUN_USING_ENCODER,          // 2
    DcMotor.RunMode.STOP_AND_RESET_ENCODER,     // 3

    DcMotor.RunMode.RUN_WITHOUT_ENCODER,        // 1
    DcMotor.RunMode.STOP_AND_RESET_ENCODER,     // 3
    DcMotor.RunMode.RUN_USING_ENCODER,          // 2

    DcMotor.RunMode.RUN_USING_ENCODER,          // 2
    DcMotor.RunMode.RUN_WITHOUT_ENCODER,        // 1
    DcMotor.RunMode.STOP_AND_RESET_ENCODER,     // 3

    DcMotor.RunMode.RUN_USING_ENCODER,          // 2
    DcMotor.RunMode.STOP_AND_RESET_ENCODER,     // 3
    DcMotor.RunMode.RUN_WITHOUT_ENCODER,        // 1

    DcMotor.RunMode.STOP_AND_RESET_ENCODER,     // 3
    DcMotor.RunMode.RUN_WITHOUT_ENCODER,        // 1
    DcMotor.RunMode.RUN_USING_ENCODER,          // 2

    DcMotor.RunMode.STOP_AND_RESET_ENCODER,     // 3
    DcMotor.RunMode.RUN_USING_ENCODER,          // 2
    DcMotor.RunMode.RUN_WITHOUT_ENCODER,        // 1
    };

waitForStart();

int count = 0;
while (opModeIsActive())
    {
    DcMotor.RunMode mode = modes[count % modes.length];

    motor.setMode(mode);
    telemetry.addData("count", "%d", count++);
    telemetry.addData("mode", "%s", motor.getMode());
    telemetry.update();
    idle();
    }
}
 
开发者ID:forgod01,项目名称:5094-2016-2017,代码行数:46,代码来源:TestMotorModeSwitch.java

示例9: runOpMode

import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
@Override
public void runOpMode() throws InterruptedException
    {
    // Initialize our hardware variables. Note that the strings used here as parameters
    // to 'get' must correspond to the names you assigned during the robot configuration
    // step you did in the FTC Robot Controller app on the phone.
    this.motorLeft = this.hardwareMap.dcMotor.get("motorLeft");
    this.motorRight = this.hardwareMap.dcMotor.get("motorRight");

    // Configure the knobs of the hardware according to how you've wired your robot.
    DcMotor.RunMode mode = DcMotor.RunMode.RUN_USING_ENCODER;
    this.motorLeft.setMode(mode);
    this.motorRight.setMode(mode);

    // One of the two motors (here, the left) should be set to reversed direction
    // so that it can take the same power level values as the other motor.
    this.motorLeft.setDirection(DcMotor.Direction.REVERSE);

    // Wait until we've been given the ok to go
    this.waitForStart();

    // Drive in a line at various speeds
    for (int degreesPerSecond = 300; degreesPerSecond <= 1000; degreesPerSecond += 100)
        {
        int ticksPerSecond = ticksPerSecFromDegsPerSec(degreesPerSecond);
        this.motorLeft.setMaxSpeed(ticksPerSecond);
        this.motorRight.setMaxSpeed(ticksPerSecond);

        telemetry.addData("deg/s", degreesPerSecond);
        telemetry.addData("ticks/s", ticksPerSecond);
        updateTelemetry(telemetry);

        // Drive for a while, then stop
        this.motorLeft.setPower(1);
        this.motorRight.setPower(1);

        long msDeadline = System.currentTimeMillis() + 3000;
        while (System.currentTimeMillis() < msDeadline)
            {
            Thread.yield();
            telemetry.addData("deg/s",   degreesPerSecond);
            telemetry.addData("ticks/s", ticksPerSecond);
            telemetry.addData("left",    motorLeft.getCurrentPosition());
            telemetry.addData("right",   motorRight.getCurrentPosition());
            updateTelemetry(telemetry);
            }

        this.motorRight.setPower(0);
        this.motorLeft.setPower(0);

        Thread.sleep(3000);
        }
    }
 
开发者ID:forgod01,项目名称:5094-2016-2017,代码行数:54,代码来源:TestMaxSpeed.java

示例10: setWheelsToRunMode

import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
public final void setWheelsToRunMode(DcMotor.RunMode runMode) {
    Preconditions.checkState(isWheelsStopped(), "Should not change run mode without stopping wheels first");
    for (DcMotor motor : getWheels()) {
        motor.setMode(runMode);
    }
}
 
开发者ID:FTC7729,项目名称:2016-FTC,代码行数:7,代码来源:Dutchess.java


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