本文整理汇总了Java中com.qualcomm.robotcore.hardware.DcMotorController.RunMode方法的典型用法代码示例。如果您正苦于以下问题:Java DcMotorController.RunMode方法的具体用法?Java DcMotorController.RunMode怎么用?Java DcMotorController.RunMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.qualcomm.robotcore.hardware.DcMotorController
的用法示例。
在下文中一共展示了DcMotorController.RunMode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modeToByte
import com.qualcomm.robotcore.hardware.DcMotorController; //导入方法依赖的package包/类
public static byte modeToByte(DcMotorController.RunMode mode) {
switch (mode) {
default:
case RUN_WITHOUT_ENCODERS:
return 0;
case RUN_USING_ENCODERS:
return 1;
case RUN_TO_POSITION:
return 2;
case RESET_ENCODERS:
return 3;
}
}
示例2: modeFromByte
import com.qualcomm.robotcore.hardware.DcMotorController; //导入方法依赖的package包/类
public static DcMotorController.RunMode modeFromByte(byte b) {
switch (b & 3) {
default:
case 0:
return DcMotorController.RunMode.RUN_WITHOUT_ENCODERS;
case 1:
return DcMotorController.RunMode.RUN_USING_ENCODERS;
case 2:
return DcMotorController.RunMode.RUN_TO_POSITION;
case 3:
return DcMotorController.RunMode.RESET_ENCODERS;
}
}
示例3: setMotorChannelMode
import com.qualcomm.robotcore.hardware.DcMotorController; //导入方法依赖的package包/类
@Override
public synchronized void setMotorChannelMode(int motor, DcMotorController.RunMode mode) {
this.validateMotor(motor);
byte bNewMode = modeToByte(mode);
// We write the whole byte, but only the lower five bits are actually writable
// and we only ever use the lowest two as non zero.
this.write8(mpMotorRegMotorMode[motor], bNewMode);
// If the mode is 'reset encoders', we don't want to return until the encoders have actually reset
// http://ftcforum.usfirst.org/showthread.php?4924-Use-of-RUN_TO_POSITION-in-LineraOpMode&highlight=reset+encoders
// http://ftcforum.usfirst.org/showthread.php?4567-Using-and-resetting-encoders-in-MIT-AI&p=19303&viewfull=1#post19303
// For us, here, we believe we'll always *immediately* have that be true, as our writes
// to the I2C device actually happen when we issue them.
//
// Or, at least, insofar as anything is actually *observable*: the write will be issued
// ahead of any subsequent reads or writes. Thus, the assertTrue here would never fire,
// since the getMotorCurrentPosition() would follow the write and see its effect. However,
// having the assert does unnecessarily slow things down. We'll keep it for a while, then
// probably comment it out.
//
if (mode == RunMode.RUN_TO_POSITION) {
// Enforce that in RUN_TO_POSITION, we always need *positive* power. DCMotor will
// take care of that if we set power *after* we set the mode, but not the other way
// around. So we handle that here.
//
// Unclear that this is needed. The motor controller might take the absolute value automatically
double power = getMotorPower(motor);
if (power < 0)
setMotorPower(motor, Math.abs(power));
}
}
示例4: getMotorChannelMode
import com.qualcomm.robotcore.hardware.DcMotorController; //导入方法依赖的package包/类
@Override
public synchronized DcMotorController.RunMode getMotorChannelMode(int motor) {
this.validateMotor(motor);
byte b = this.i2cDeviceClient.read8(mpMotorRegMotorMode[motor]);
return modeFromByte(b);
}
示例5: setMotorChannelMode
import com.qualcomm.robotcore.hardware.DcMotorController; //导入方法依赖的package包/类
@Override
public synchronized void setMotorChannelMode(int motor, DcMotorController.RunMode mode) {
this.validateMotor(motor);
byte bNewMode = modeToByte(mode);
// We write the whole byte, but only the lower five bits are actually writable
// and we only ever use the lowest two as non zero.
this.write8(mpMotorRegMotorMode[motor], bNewMode);
// The mode switch doesn't happen instantaneously. Wait for it,
// so that the programmer's model is that he just needs to set the
// mode and be done.
for (; ; ) {
byte bCurrentMode = this.i2cDeviceClient.read8(mpMotorRegMotorMode[motor]);
if (bCurrentMode == bNewMode)
break;
Thread.yield();
}
// If the mode is 'reset encoders', we don't want to return until the encoders have actually reset
// http://ftcforum.usfirst.org/showthread.php?4924-Use-of-RUN_TO_POSITION-in-LineraOpMode&highlight=reset+encoders
// http://ftcforum.usfirst.org/showthread.php?4567-Using-and-resetting-encoders-in-MIT-AI&p=19303&viewfull=1#post19303
// For us, here, we believe we'll always *immediately* have that be true, as our writes
// to the I2C device actually happen when we issue them.
//
// Or, at least, insofar as anything is actually *observable*: the write will be issued
// ahead of any subsequent reads or writes. Thus, the assertTrue here would never fire,
// since the getMotorCurrentPosition() would follow the write and see its effect. However,
// having the assert does unnecessarily slow things down. We'll keep it for a while, then
// probably comment it out.
//
if (mode == RunMode.RESET_ENCODERS) {
// Unclear if this is needed
while (this.getMotorTargetPosition(motor) != 0) {
Thread.yield();
}
} else if (mode == RunMode.RUN_TO_POSITION) {
// Enforce that in RUN_TO_POSITION, we always need *positive* power. DCMotor will
// take care of that if we set power *after* we set the mode, but not the other way
// around. So we handle that here.
//
// Unclear that this is needed. The motor controller might take the absolute value automatically
double power = getMotorPower(motor);
if (power < 0)
setMotorPower(motor, Math.abs(power));
}
}