/** * Starting point for the applications. Starts the OtaServer and then runs * the robot. * * @throws javax.microedition.midlet.MIDletStateChangeException */ protected final void startApp() throws MIDletStateChangeException { boolean errorOnExit = false; Watchdog.getInstance().setExpiration(0.1); Watchdog.getInstance().setEnabled(false); FRCControl.observeUserProgramStarting(); UsageReporting.report(UsageReporting.kResourceType_Language, UsageReporting.kLanguage_Java); writeVersionString(); try { this.startCompetition(); } catch (Throwable t) { t.printStackTrace(); errorOnExit = true; } finally { // startCompetition never returns unless exception occurs.... System.err.println("WARNING: Robots don't quit!"); if (errorOnExit) { System.err.println("---> The startCompetition() method (or methods called by it) should have handled the exception above."); } else { System.err.println("---> Unexpected return from startCompetition() method."); } } }
/** * Starting point for the applications. Starts the OtaServer and then runs * the robot. * @throws javax.microedition.midlet.MIDletStateChangeException */ protected final void startApp() throws MIDletStateChangeException { boolean errorOnExit = false; Watchdog.getInstance().setExpiration(0.1); Watchdog.getInstance().setEnabled(false); FRCControl.observeUserProgramStarting(); UsageReporting.report(UsageReporting.kResourceType_Language, UsageReporting.kLanguage_Java); try { this.startCompetition(); } catch (Throwable t) { t.printStackTrace(); errorOnExit = true; } finally { // startCompetition never returns unless exception occurs.... System.err.println("WARNING: Robots don't quit!"); if (errorOnExit) { System.err.println("---> The startCompetition() method (or methods called by it) should have handled the exception above."); } else { System.err.println("---> Unexpected return from startCompetition() method."); } } }
/** * Called by the other Kinect functions to check for the latest data * This function will update the internal data structures * with the most recent Kinect input */ void updateData() { int retVal; if (m_recentPacketNumber != DriverStation.getInstance().getPacketNumber()){ m_recentPacketNumber = DriverStation.getInstance().getPacketNumber(); synchronized (m_headerDataSemaphore) { retVal = FRCControl.getDynamicControlData(kHeaderBlockID, tempHeaderData, tempHeaderData.size(), 5); if (retVal == 0) { tempHeaderData.copy(m_headerData); m_headerValid = true; }else { m_headerValid = false; } } synchronized (m_skeletonExtraDataSemaphore) { retVal = FRCControl.getDynamicControlData(kSkeletonExtraBlockID, tempSkeletonExtraData, tempSkeletonExtraData.size(), 5); if (retVal == 0) { tempSkeletonExtraData.copy(m_skeletonExtraData); m_skeletonExtraValid = true; }else { m_skeletonExtraValid = false; } } synchronized (m_skeletonDataSemaphore) { retVal = FRCControl.getDynamicControlData(kSkeletonBlockID, tempSkeletonData, tempSkeletonData.size(), 5); if (retVal == 0) { tempSkeletonData.copy(m_skeletonData); m_skeletonValid = true; }else { m_skeletonValid = false; } } } }
/** * DriverStationLCD constructor. * * This is only called once the first time GetInstance() is called */ private DriverStationLCD() { m_textBuffer = new byte[FRCControl.USER_DS_LCD_DATA_SIZE]; for (int i = 0; i < FRCControl.USER_DS_LCD_DATA_SIZE; i++) { m_textBuffer[i] = ' '; } m_textBuffer[0] = (byte) (kFullDisplayTextCommand >> 8); m_textBuffer[1] = (byte) kFullDisplayTextCommand; UsageReporting.report(UsageReporting.kResourceType_DriverStationLCD, 0); }
/** * Update the data in this class with the latest data from the * Driver Station. */ private void getData() { if (m_recentPacketNumber != DriverStation.getInstance().getPacketNumber()){ m_recentPacketNumber = DriverStation.getInstance().getPacketNumber(); int retVal = FRCControl.getDynamicControlData(kJoystickDataID, tempOutputData, tempOutputData.size(), 5); if (retVal != 0) { System.err.println("Bad retval: " + retVal); } } }
/** * DriverStationLCD constructor. * * This is only called once the first time GetInstance() is called */ private DriverStationLCD() { final char[] blank_bytes = new char[LINE_LENGTH]; Arrays.fill(blank_bytes, ' '); EMPTY_STRING = new String(blank_bytes); textBuffer = new byte[NUM_LINES][FRCControl.USER_DS_LCD_DATA_SIZE]; clear(); }
/** * Called by the DriverStation class when data is available. * This function will set any modified configuration / output, * then read the input and configuration from the IO. */ void updateData() { int retVal; synchronized (m_outputDataSemaphore) { if (m_outputValid || m_configChanged || m_requestEnhancedEnable) { m_outputData.flags = kStatusValid; if (m_requestEnhancedEnable) { // Someone called one of the get config APIs, but we are not in enhanced mode. m_outputData.flags |= kForceEnhancedMode; } if (m_configChanged) { if (!m_outputValid) { // Someone called one of the set config APIs, but we are not in enhanced mode. m_outputData.flags |= kForceEnhancedMode; } m_outputData.flags |= kStatusConfigChanged; } FRCControl.overrideIOConfig(m_outputData, 5); } retVal = FRCControl.getDynamicControlData(kOutputBlockID, tempOutputData, tempOutputData.size(), 5); if (retVal == 0) { if (m_outputValid) { if (m_configChanged) { // If our config change made the round trip then clear the flag. if (isConfigEqual(tempOutputData, m_outputData)) { m_configChanged = false; } } else { // TODO: This won't work until artf1128 is fixed //if (tempOutputData.flags & kStatusConfigChanged) { // Configuration was updated on the DS, so update our local cache. mergeConfigIntoOutput(tempOutputData, m_outputData); } } } else { // Initialize the local cache. mergeConfigIntoOutput(tempOutputData, m_outputData); } m_requestEnhancedEnable = false; m_outputValid = true; } else { m_outputValid = false; m_inputValid = false; } } synchronized (m_inputDataSemaphore) { retVal = FRCControl.getDynamicControlData(kInputBlockID, tempInputData, tempInputData.size(), 5); if (retVal == 0 && tempInputData.data.api_version == kSupportedAPIVersion) { tempInputData.copy(m_inputData); m_inputValid = true; } else { m_outputValid = false; m_inputValid = false; } } }
/** * Send the text data to the Driver Station. */ public synchronized void updateLCD() { FRCControl.setUserDsLcdData(m_textBuffer, FRCControl.USER_DS_LCD_DATA_SIZE, kSyncTimeout_ms); }
/** * Send the text data to the Driver Station. */ private void updateLCD() { synchronized (textBuffer) { FRCControl.setUserDsLcdData(flattenTextBuffer(textBuffer), FRCControl.USER_DS_LCD_DATA_SIZE, TIMEOUT_MS); } }
/** * Flushes this output stream and forces any buffered output bytes * to be written out. The general contract of <code>flush</code> is * that calling it is an indication that, if any bytes previously * written have been buffered by the implementation of the output * stream, such bytes should immediately be written to their * intended destination. * <p> * The <code>flush</code> method of <code>OutputStream</code> does nothing. * * @exception IOException if an I/O error occurs. */ public synchronized void flush() throws IOException { if (errorBuffer == null) { throw new IllegalStateException("DSErrorOutputStream is closed"); } if (index > 0) { FRCControl.setErrorData(errorBuffer, index, 100); index = 0; } }