本文整理汇总了Java中com.qualcomm.robotcore.hardware.DcMotor.setMode方法的典型用法代码示例。如果您正苦于以下问题:Java DcMotor.setMode方法的具体用法?Java DcMotor.setMode怎么用?Java DcMotor.setMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.qualcomm.robotcore.hardware.DcMotor
的用法示例。
在下文中一共展示了DcMotor.setMode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initTeleOp
import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
/**
* Initializes all drive and ball motors in NO ENCODERS mode
* @param hwMap
*/
public void initTeleOp(HardwareMap hwMap) {
this.hwMap = hwMap;
initDrive();
initBall();
// initCap();
// initServos();
for(DcMotor driveMotor : driveMotors) {
driveMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
driveMotor.setDirection(DcMotorSimple.Direction.FORWARD);
driveMotor.setPower(0);
}
for(DcMotor ballMotor : ballMotors) {
ballMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
ballMotor.setDirection(DcMotorSimple.Direction.FORWARD);
ballMotor.setPower(0);
}
// cap.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// cap.setDirection(DcMotorSimple.Direction.FORWARD);
// cap.setPower(0);
}
示例2: DriveTrain
import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
public DriveTrain(ExtensibleGamepad controlGamepad, DcMotor leftFront, DcMotor rightFront, DcMotor leftRear, DcMotor rightRear) {
this.leftFront = leftFront;
this.rightFront = rightFront;
this.leftRear = leftRear;
this.rightRear = rightRear;
rightFront.setDirection(DcMotorSimple.Direction.REVERSE);
rightRear.setDirection(DcMotorSimple.Direction.REVERSE);
leftFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
rightFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
leftFront.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
rightFront.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
this.controlGamepad = controlGamepad;
//this.drive = drive;
disableMap = new double[4];
for (int i = 0; i < disableMap.length; i++) {
disableMap[i] = 1;
}
}
示例3: initAutoOp
import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
/**
* Initializes all drive and ball motors in USING ENCODERS mode
* @param hwMap
*/
public void initAutoOp(LinearOpMode opMode, HardwareMap hwMap) {
this.hwMap = hwMap;
initDrive();
initBall();
// initCap();
// initServos();
// initSensors();
for(DcMotor driveMotor : driveMotors) {
driveMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
opMode.idle();
driveMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
driveMotor.setDirection(DcMotorSimple.Direction.FORWARD);
driveMotor.setPower(0);
}
for(DcMotor ballMotor : ballMotors) {
ballMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
opMode.idle();
ballMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
ballMotor.setDirection(DcMotorSimple.Direction.FORWARD);
ballMotor.setPower(0);
}
// cap.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// cap.setDirection(DcMotorSimple.Direction.FORWARD);
// cap.setPower(0);
}
示例4: runOpMode
import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的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: 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);
}
示例6: setDriveMotorMode
import com.qualcomm.robotcore.hardware.DcMotor; //导入方法依赖的package包/类
public void setDriveMotorMode(DcMotor.RunMode mode) {
for (DcMotor motor : driveMotors) {
motor.setMode(mode);
}
}
示例7: 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);
}
}