public class FtcEventLoop extends FtcEventLoopBase
Modify this class with your own code, or create your own event loop by implementing EventLoop.
Modifier and Type | Class and Description |
---|---|
class |
FtcEventLoop.DefaultUsbModuleAttachmentHandler |
Modifier and Type | Field and Description |
---|---|
protected java.util.Set<java.lang.String> |
attachedUsbDevices |
protected java.lang.Object |
attachedUsbDevicesLock |
protected java.util.Map<SerialNumber,ControllerConfiguration> |
deviceControllers |
protected OpModeManagerImpl |
opModeManager |
protected java.util.concurrent.atomic.AtomicReference<OpMode> |
opModeStopRequested |
protected OpModeRegister |
register |
protected UsbModuleAttachmentHandler |
usbModuleAttachmentHandler |
protected USBScanManager |
usbScanManager |
protected Utility |
utility |
activityContext, ftcEventLoopHandler, networkConnectionHandler, programmingModeController, robotCfgFileMgr, runningOnDriverStation, TAG
TELEMETRY_DEFAULT_INTERVAL
Constructor and Description |
---|
FtcEventLoop(HardwareFactory hardwareFactory,
OpModeRegister register,
UpdateUI.Callback callback,
Activity activityContext,
ProgrammingModeController programmingModeController) |
Modifier and Type | Method and Description |
---|---|
protected OpModeManagerImpl |
createOpModeManager() |
OpModeManagerImpl |
getOpModeManager()
Returns the OpModeManager associated with this event loop
|
protected java.lang.String |
getSerialNumberOfUsbDevice(UsbDevice usbDevice) |
UsbModuleAttachmentHandler |
getUsbModuleAttachmentHandler() |
protected void |
handleCommandInitOpMode(java.lang.String extra) |
protected void |
handleCommandRequestOpModeList()
The driver station is requesting our opmode list.
|
protected void |
handleCommandRunOpMode(java.lang.String extra) |
protected void |
handleCommandScan(java.lang.String extra) |
void |
handleUsbModuleDetach(RobotUsbModule module)
Process the fact that a usb module has now become detached from the system.
|
void |
init(EventLoopManager eventLoopManager)
Init method
|
void |
loop()
Loop method, this will be called repeatedly while the robot is running.
|
void |
onUsbDeviceAttached(UsbDevice usbDevice)
Deal with the fact that a UsbDevice has recently attached to the system
|
CallbackResult |
processCommand(Command command)
If the driver station sends over a command, it will be routed to this method.
|
void |
processedRecentlyAttachedUsbDevices()
Process any usb devices that might have recently attached.
|
void |
refreshUserTelemetry(TelemetryMessage telemetry,
double sInterval)
Update's the user portion of the driver station screen with the contents of the telemetry object
here provided if a sufficiently long duration has passed since the last update.
|
void |
requestOpModeStop(OpMode opModeToStopIfActive)
Requests that an OpMode be stopped if it's the currently active one
|
void |
setUsbModuleAttachmentHandler(UsbModuleAttachmentHandler handler) |
void |
teardown()
Teardown method
|
handleCommandActivateConfiguration, handleCommandDeleteConfiguration, handleCommandRequestActiveConfiguration, handleCommandRequestConfigurations, handleCommandRequestConfigurationTemplates, handleCommandRequestParticularConfiguration, handleCommandRestartRobot, handleCommandSaveConfiguration, handleCommandStartProgrammingMode, handleCommandStopProgrammingMode
protected Utility utility
protected USBScanManager usbScanManager
protected OpModeManagerImpl opModeManager
protected OpModeRegister register
protected UsbModuleAttachmentHandler usbModuleAttachmentHandler
protected final java.lang.Object attachedUsbDevicesLock
protected java.util.Set<java.lang.String> attachedUsbDevices
protected java.util.concurrent.atomic.AtomicReference<OpMode> opModeStopRequested
protected java.util.Map<SerialNumber,ControllerConfiguration> deviceControllers
public FtcEventLoop(HardwareFactory hardwareFactory, OpModeRegister register, UpdateUI.Callback callback, Activity activityContext, ProgrammingModeController programmingModeController)
protected OpModeManagerImpl createOpModeManager()
public OpModeManagerImpl getOpModeManager()
EventLoop
public UsbModuleAttachmentHandler getUsbModuleAttachmentHandler()
public void setUsbModuleAttachmentHandler(UsbModuleAttachmentHandler handler)
public void init(EventLoopManager eventLoopManager) throws RobotCoreException, java.lang.InterruptedException
This code will run when the robot first starts up. Place any initialization code in this method.
It is important to save a copy of the event loop manager from this method, as that is how you'll get access to the gamepad.
If an Exception is thrown then the event loop manager will not start the robot.
Caller synchronizes: called on RobotSetupRunnable.run() thread
eventLoopManager
- event loop manager that is responsible for this event loopRobotCoreException
- if a RobotCoreException is thrown, it will be handled
by the event loop manager. The manager will report that the robot failed
to start.java.lang.InterruptedException
public void loop() throws RobotCoreException
RobotCoreException
- if a RobotCoreException is thrown, it will be handled
by the event loop manager. The manager may decide to either stop processing
this iteration of the loop, or it may decide to shut down the robot.
Caller synchronizes: called on EventLoopRunnable.run() thread.
public void refreshUserTelemetry(TelemetryMessage telemetry, double sInterval)
EventLoop
telemetry
- the telemetry object to sendsInterval
- the required minimum interval. NaN indicates that a system default interval should be used.public void teardown() throws RobotCoreException
This method will be called when the robot is being shut down. This method should stop the robot. There will be no more changes to write to the hardware after this method is called.
If an exception is thrown, then the event loop manager will attempt to shut down the robot without the benefit of this method.
RobotCoreException
- if a RobotCoreException is thrown, it will be handled by the event
loop manager. The manager will then attempt to shut down the robot without the benefit
of the teardown method.
Caller synchronizes: called on EventLoopRunnable.run() thread.
public CallbackResult processCommand(Command command) throws java.lang.InterruptedException, RobotCoreException
Called on RecvRunnable.run() thread. Method is thread safem, non-interfering
processCommand
in interface EventLoop
processCommand
in class FtcEventLoopBase
command
- command to processjava.lang.InterruptedException
RobotCoreException
protected void handleCommandScan(java.lang.String extra) throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
FtcConfigurationActivity#doUSBScanAndUpdateUI()
protected void handleCommandRequestOpModeList()
protected void handleCommandInitOpMode(java.lang.String extra)
protected void handleCommandRunOpMode(java.lang.String extra)
public void requestOpModeStop(OpMode opModeToStopIfActive)
EventLoop
opModeToStopIfActive
- the OpMode to stop if it's currently activepublic void onUsbDeviceAttached(UsbDevice usbDevice)
usbDevice
- EventLoop.processedRecentlyAttachedUsbDevices()
protected java.lang.String getSerialNumberOfUsbDevice(UsbDevice usbDevice)
public void processedRecentlyAttachedUsbDevices() throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
EventLoop.handleUsbModuleDetach(RobotUsbModule)
,
EventLoop.onUsbDeviceAttached(UsbDevice)
public void handleUsbModuleDetach(RobotUsbModule module) throws RobotCoreException, java.lang.InterruptedException
EventLoop
RobotCoreException
java.lang.InterruptedException
EventLoop.processedRecentlyAttachedUsbDevices()