本文整理汇总了Java中com.qualcomm.robotcore.eventloop.opmode.OpMode类的典型用法代码示例。如果您正苦于以下问题:Java OpMode类的具体用法?Java OpMode怎么用?Java OpMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OpMode类属于com.qualcomm.robotcore.eventloop.opmode包,在下文中一共展示了OpMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOpModeName
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
/**
* This gets the correct name of the OpMode via reflection. This returns the value of the name
* present in the Annation or Simple Name of the class.
*
* @param opMode the OpMode to check
* @return the name to use of defined by the user
*/
private static String getOpModeName(Class<OpMode> opMode) {
String name;
if (opMode.isAnnotationPresent(TeleOpMode.class)) {
name = opMode.getAnnotation(TeleOpMode.class).name();
} else if (opMode.isAnnotationPresent(AutonomousMode.class)) {
name = opMode.getAnnotation(AutonomousMode.class).name();
} else {
name = opMode.getSimpleName();
}
if (name.equals("")) {
name = opMode.getSimpleName();
}
return name;
}
示例2: create
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
public static DcMotorController create(OpMode context, DcMotorController target, DcMotor motor1, DcMotor motor2) {
if (MemberUtil.isLegacyMotorController(target)) {
LegacyModule legacyModule = MemberUtil.legacyModuleOfLegacyMotorController(target);
int port = MemberUtil.portOfLegacyMotorController(target);
int i2cAddr8Bit = MemberUtil.i2cAddrOfLegacyMotorController(target);
// Make a new legacy motor controller
II2cDevice i2cDevice = new I2cDeviceOnI2cDeviceController(legacyModule, port);
I2cDeviceClient i2cDeviceClient = new I2cDeviceClient(context, i2cDevice, i2cAddr8Bit, false);
EasyLegacyMotorController controller = new EasyLegacyMotorController(context, i2cDeviceClient, target);
controller.setMotors(motor1, motor2);
controller.arm();
return controller;
} else {
// The target isn't a legacy motor controller, so we can't swap anything in for him.
// Return the raw target (rather than, e.g., throwing) so that caller doesn't need to check
// what kind of controller he has in hand.
return target;
}
}
示例3: I2cDeviceReplacementHelper
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
public I2cDeviceReplacementHelper(OpMode context, TARGET client, /* may be null */ TARGET target, I2cController controller, int targetPort) {
this.context = context;
this.isArmed = false;
this.client = client;
this.target = target; // may be null
this.controller = controller;
this.targetPort = targetPort;
this.targetName = null;
this.targetDeviceMapping = null;
if (this.target != null)
findTargetNameAndMapping();
if (controller instanceof LegacyModule) {
this.targetCallback = MemberUtil.callbacksOfLegacyModule((LegacyModule) controller)[targetPort];
} else if (controller instanceof DeviceInterfaceModule) {
this.targetCallback = MemberUtil.callbacksOfDeviceInterfaceModule((DeviceInterfaceModule) controller)[targetPort];
} else
throw new IllegalArgumentException(String.format("unknown controller flavor: %s", controller.getClass().getSimpleName()));
}
示例4: AdaFruitBNO055IMU
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
/**
* Instantiate an AdaFruitBNO055IMU on the indicated device whose I2C address is the one
* indicated.
*/
public AdaFruitBNO055IMU(OpMode context, I2cDevice i2cDevice, int i2cAddr8Bit) {
this.context = context;
// We don't have the device auto-close since *we* handle the shutdown logic
this.deviceClient = ClassFactory.createI2cDeviceClient(context, ClassFactory.createI2cDevice(i2cDevice), i2cAddr8Bit, false);
this.deviceClient.setReadWindow(lowerWindow);
this.deviceClient.arm();
this.parameters = null;
this.currentMode = null;
this.accelerationAlgorithm = new NaiveAccelerationIntegrator();
this.accelerationMananger = null;
RobotStateTransitionNotifier.register(context, this);
}
示例5: getOpModeName
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
/**
* This gets the correct name of the OpMode via reflection. This returns the value of the name
* present in the Annation or Simple Name of the class.
*
* @param opMode the OpMode to check
* @return the name to use of defined by the user
*/
private static String getOpModeName(Class<OpMode> opMode) {
String name;
if (opMode.isAnnotationPresent(TeleOp.class)) {
name = opMode.getAnnotation(TeleOp.class).name();
} else if (opMode.isAnnotationPresent(Autonomous.class)) {
name = opMode.getAnnotation(Autonomous.class).name();
} else {
name = opMode.getSimpleName();
}
if (name.equals("")) {
name = opMode.getSimpleName();
}
return name;
}
示例6: Robot
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
public Robot(OpMode opMode)
{
this.opMode = opMode;
telemetry = opMode.telemetry;
hardwareMap = opMode.hardwareMap;
subSystems = new HashMap<String, SubSystem>();
}
示例7: Polaris
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
public Polaris(OpMode opMode){
super(opMode);
putSubSystem("Drive", new Drive(this));
putSubSystem("Belt", new Belt(this));
putSubSystem("Jewel", new Jewel(this));
}
示例8: sortOpModeMap
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
/**
* This sorts the {@link LinkedList<Class>} sorting the OpModes given by a special character
*
* @param opModes the OpMode HashMap
*/
private void sortOpModeMap(HashMap<String, LinkedList<Class<OpMode>>> opModes) {
Comparator<Class> firstComparator =
new OpModeComparator();
for (String key : opModes.keySet()) {
Collections.sort(opModes.get(key), firstComparator);
}
}
示例9: treeMapify
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
/**
* Converts the OpMode HashMap to a TreeMap, using the proper sorting algorithm.
*
* @param opModes the {@code HashMap} containing the properly grouped OpModes
* @return a {@link TreeMap} with a proper sorting
*/
private TreeMap<String, LinkedList<Class<OpMode>>> treeMapify(
HashMap<String, LinkedList<Class<OpMode>>> opModes) {
TreeMap<String, LinkedList<Class<OpMode>>> sortedOpModes = new TreeMap<>();
for (String key : opModes.keySet()) {
Class<OpMode> opMode = opModes.get(key).getFirst();
String name = getOpModeName(opMode);
sortedOpModes.put(name, opModes.get(key));
}
return sortedOpModes;
}
示例10: EasyLegacyMotorController
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
private EasyLegacyMotorController(OpMode context, II2cDeviceClient ii2cDeviceClient, DcMotorController target) {
LegacyModule legacyModule = MemberUtil.legacyModuleOfLegacyMotorController(target);
int targetPort = MemberUtil.portOfLegacyMotorController(target);
this.helper = new I2cDeviceReplacementHelper<>(context, this, target, legacyModule, targetPort);
this.context = context;
this.i2cDeviceClient = ii2cDeviceClient;
this.target = target;
this.motor1 = null;
this.motor2 = null;
RobotStateTransitionNotifier.register(context, this);
// The NXT HiTechnic motor controller will time out if it doesn't receive any I2C communication for
// 2.5 seconds. So we set up a heartbeat request to try to prevent that. We try to use
// heartbeats which are as minimally disruptive as possible. Note as a matter of interest
// that the heartbeat mechanism used by ModernRoboticsNxtDcMotorController is analogous to
// 'rewriteLastWritten'.
II2cDeviceClient.HeartbeatAction heartbeatAction = new II2cDeviceClient.HeartbeatAction();
heartbeatAction.rereadLastRead = true;
heartbeatAction.rewriteLastWritten = true;
heartbeatAction.heartbeatReadWindow = new II2cDeviceClient.ReadWindow(mpMotorRegCurrentEncoderValue[1], 1, II2cDeviceClient.READ_MODE.ONLY_ONCE);
this.i2cDeviceClient.setHeartbeatAction(heartbeatAction);
this.i2cDeviceClient.setHeartbeatInterval(2000);
// Also: set up a read-window. We make it BALANCED to avoid unnecessary ping-ponging
// between read mode and write mode, since motors are read about as much as they are
// written, but we make it relatively large so that least that when we DO go
// into read mode and possibly do more than one read we will use this window
// and won't have to fiddle with the 'switch to read mode' each and every time.
// We include everything from the 'Motor 1 target encoder value' through the battery voltage.
this.i2cDeviceClient.setReadWindow(new II2cDeviceClient.ReadWindow(iRegWindowFirst, iRegWindowMax - iRegWindowFirst, II2cDeviceClient.READ_MODE.BALANCED));
}
示例11: AdaFruitTCS34725ColorSensor
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
private AdaFruitTCS34725ColorSensor(OpMode context, I2cDeviceClient i2cDeviceClient, ColorSensor target, I2cController controller, int targetPort) {
this.helper = new I2cDeviceReplacementHelper<>(context, this, target, controller, targetPort);
this.i2cDeviceClient = i2cDeviceClient;
this.ledIsEnabled = false;
this.ledStateIsKnown = false;
this.i2cDeviceClient.setReadWindow(new II2cDeviceClient.ReadWindow(
IREG_READ_FIRST, IREG_READ_LAST - IREG_READ_FIRST + 1,
II2cDeviceClient.READ_MODE.REPEAT));
RobotStateTransitionNotifier.register(context, this);
}
示例12: create
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
public static ColorSensor create(OpMode context, ColorSensor target) {
I2cController controller;
int port;
int i2cAddr8Bit;
if (target instanceof com.qualcomm.hardware.adafruit.AdafruitI2cColorSensor) {
controller = MemberUtil.deviceInterfaceModuleOfAdaFruitColorSensor(target);
port = MemberUtil.portOfAdaFruitColorSensor(target);
i2cAddr8Bit = ADDRESS_I2C;
} else
throw new IllegalArgumentException(String.format("incorrect color sensor class: %s", target.getClass().getSimpleName()));
return create(context, controller, port, i2cAddr8Bit, target);
}
示例13: I2cDeviceClient
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
/**
* Instantiate an I2cDeviceClient instance in the indicated device with the indicated initial
* window of registers being read.
*
* @param context the OpMode within which the creation is taking place
* @param i2cDevice the device we are to be a client of
* @param i2cAddr8Bit its 8 bit i2cAddress
*/
public I2cDeviceClient(@Nullable OpMode context, II2cDevice i2cDevice, int i2cAddr8Bit, boolean closeOnOpModeStop) {
i2cDevice.setI2cAddr(i2cAddr8Bit);
this.i2cDevice = i2cDevice;
this.isArmed = false;
this.disarming = false;
this.callback = new Callback();
this.callbackThread = null;
this.callbackThreadOriginalPriority = 0; // not known
this.callbackThreadPriorityBoost = 0; // no boost
this.hardwareCycleCount = 0;
this.loggingEnabled = false;
this.loggingTag = String.format("%s:client(%s)", this.getClass().getSimpleName(), i2cDevice.getDeviceName());
this.timeSinceLastHeartbeat = new ElapsedTime();
this.timeSinceLastHeartbeat.reset();
this.msHeartbeatInterval = 0;
this.heartbeatAction = null;
this.heartbeatExecutor = null;
this.readCache = this.i2cDevice.getI2cReadCache();
this.readCacheLock = this.i2cDevice.getI2cReadCacheLock();
this.writeCache = this.i2cDevice.getI2cWriteCache();
this.writeCacheLock = this.i2cDevice.getI2cWriteCacheLock();
this.readWindow = null;
this.readWindowActuallyRead = null;
this.readWindowSentToController = null;
this.readWindowChanged = false;
this.readWindowSentToControllerInitialized = false;
this.nanoTimeReadCacheValid = 0;
this.readCacheStatus = READ_CACHE_STATUS.IDLE;
this.writeCacheStatus = WRITE_CACHE_STATUS.IDLE;
this.modeCacheStatus = MODE_CACHE_STATUS.IDLE;
if (closeOnOpModeStop)
RobotStateTransitionNotifier.register(context, this);
}
示例14: create
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
/**
* Instantiate an AdaFruitBNO055IMU and then initialize it with the indicated set of
* parameters.
*/
public static IBNO055IMU create(OpMode context, I2cDevice i2cDevice, Parameters parameters) {
// Create a sensor which is a client of i2cDevice
IBNO055IMU result = new AdaFruitBNO055IMU(context, i2cDevice, parameters.i2cAddr8Bit.bVal);
// Initialize it with the indicated parameters
result.initialize(parameters);
return result;
}
示例15: Watchdog2
import com.qualcomm.robotcore.eventloop.opmode.OpMode; //导入依赖的package包/类
public Watchdog2(OpMode opModeToWatch) {
this(opModeToWatch, Thread.currentThread());
}