Search in sources :

Example 1 with RobotCoreException

use of com.qualcomm.robotcore.exception.RobotCoreException in project robotcode by OutoftheBoxFTC.

the class FtcEventLoopBase method handleCommandRequestParticularConfiguration.

/*
     * The driver station wants the contents of the configuration file.
     */
protected void handleCommandRequestParticularConfiguration(String data) {
    RobotConfigFile file = robotCfgFileMgr.getConfigFromString(data);
    ReadXMLFileHandler parser = new ReadXMLFileHandler();
    if (file.isNoConfig()) {
        // don't try to parse if there's no file
        return;
    }
    try {
        WriteXMLFileHandler writeXMLFileHandler = new WriteXMLFileHandler(activityContext);
        ArrayList<ControllerConfiguration> deviceList = (ArrayList<ControllerConfiguration>) parser.parse(file.getXml());
        String xmlData = writeXMLFileHandler.toXml(deviceList);
        RobotLog.vv(FtcConfigurationActivity.TAG, "FtcEventLoop: handleCommandRequestParticularConfigFile, data: " + xmlData);
        networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_PARTICULAR_CONFIGURATION_RESP, xmlData));
    } catch (RobotCoreException e) {
        e.printStackTrace();
    }
}
Also used : ReadXMLFileHandler(com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler) RobotConfigFile(com.qualcomm.ftccommon.configuration.RobotConfigFile) Command(com.qualcomm.robotcore.robocol.Command) ArrayList(java.util.ArrayList) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) WriteXMLFileHandler(com.qualcomm.robotcore.hardware.configuration.WriteXMLFileHandler)

Example 2 with RobotCoreException

use of com.qualcomm.robotcore.exception.RobotCoreException in project robotcode by OutoftheBoxFTC.

the class FtcEventLoopBase method handleCommandSaveConfiguration.

protected void handleCommandSaveConfiguration(String fileInfo) {
    String[] fileInfoArray = fileInfo.split(RobotConfigFileManager.FILE_LIST_COMMAND_DELIMITER);
    try {
        RobotConfigFile cfgFile = robotCfgFileMgr.getConfigFromString(fileInfoArray[0]);
        robotCfgFileMgr.writeToFile(cfgFile, false, fileInfoArray[1]);
        robotCfgFileMgr.setActiveConfigAndUpdateUI(false, cfgFile);
    } catch (RobotCoreException | IOException e) {
        e.printStackTrace();
    }
}
Also used : RobotConfigFile(com.qualcomm.ftccommon.configuration.RobotConfigFile) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) IOException(java.io.IOException)

Example 3 with RobotCoreException

use of com.qualcomm.robotcore.exception.RobotCoreException in project robotcode by OutoftheBoxFTC.

the class FtcEventLoopBase method getLynxUsbDeviceForFirmwareUpdate.

protected LynxUsbDeviceContainer getLynxUsbDeviceForFirmwareUpdate(SerialNumber serialNumber) {
    // Is is it something that's already open?
    for (LynxUsbDeviceImpl lynxUsbDevice : ftcEventLoopHandler.getExtantLynxDeviceImpls()) {
        if (lynxUsbDevice.getSerialNumber().equals(serialNumber)) {
            return new LynxUsbDeviceContainer(lynxUsbDevice);
        }
    }
    // No, then open it
    try {
        RobotUsbManager robotUsbManager = HardwareDeviceManager.createUsbManager(AppUtil.getDefContext());
        RobotUsbDevice robotUsbDevice = LynxUsbUtil.openUsbDevice(robotUsbManager, serialNumber);
        return new LynxUsbDeviceContainer(robotUsbDevice);
    } catch (RobotCoreException e) {
    // ignored;
    }
    return null;
}
Also used : RobotUsbManager(com.qualcomm.robotcore.hardware.usb.RobotUsbManager) LynxUsbDeviceImpl(com.qualcomm.hardware.lynx.LynxUsbDeviceImpl) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) RobotUsbDevice(com.qualcomm.robotcore.hardware.usb.RobotUsbDevice)

Example 4 with RobotCoreException

use of com.qualcomm.robotcore.exception.RobotCoreException in project robotcode by OutoftheBoxFTC.

the class ConfigureFromTemplateActivity method configureFromTemplate.

void configureFromTemplate(RobotConfigFile templateMeta, XmlPullParser xmlPullParser) {
    try {
        RobotConfigMap robotConfigMap = instantiateTemplate(templateMeta, xmlPullParser);
        awaitScannedDevices();
        // 
        Class clazz = FtcConfigurationActivity.class;
        EditParameters parameters = new EditParameters(this);
        parameters.setRobotConfigMap(robotConfigMap);
        parameters.setExtantRobotConfigurations(configurationList);
        parameters.setScannedDevices(scannedDevices);
        Intent intent = new Intent(context, clazz);
        parameters.putIntent(intent);
        // 
        // Start with an unnamed config, but don't update the header here as that's just distracting
        // as it just shows briefly before FtcConfigurationActivity takes over.
        robotConfigFileManager.setActiveConfig(RobotConfigFile.noConfig(robotConfigFileManager));
        startActivityForResult(intent, FtcConfigurationActivity.requestCode.value);
    } catch (RobotCoreException e) {
    }
}
Also used : RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) Intent(android.content.Intent)

Example 5 with RobotCoreException

use of com.qualcomm.robotcore.exception.RobotCoreException in project robotcode by OutoftheBoxFTC.

the class ModernRoboticsUsbUtil method openUsbDevice.

// ----------------------------------------------------------------------------------------------
// Device management
// ----------------------------------------------------------------------------------------------
/**
 * Note: when doScan is false, several openUsbDevice() calls (for different serial numbers) can execute concurrently.
 */
public static RobotUsbDevice openUsbDevice(boolean doScan, RobotUsbManager robotUsbManager, SerialNumber serialNumber) throws RobotCoreException {
    String description = "";
    boolean found = false;
    int deviceCount = doScan ? robotUsbManager.scanForDevices() : robotUsbManager.getScanCount();
    for (int index = 0; index < deviceCount; ++index) {
        if (serialNumber.equals(robotUsbManager.getDeviceSerialNumberByIndex(index))) {
            found = true;
            description = robotUsbManager.getDeviceDescriptionByIndex(index) + " [" + serialNumber.toString() + "]";
            break;
        }
    }
    if (!found) {
        RobotLog.logAndThrow("Unable to find USB device with serial number " + serialNumber.toString());
    }
    RobotUsbDevice robotUsbDevice = null;
    try {
        robotUsbDevice = robotUsbManager.openBySerialNumber(serialNumber);
    } catch (Exception e) {
        throw RobotCoreException.createChained(e, "Unable to open USB device " + serialNumber + " - " + description + ": " + e.getMessage());
    }
    try {
        robotUsbDevice.setBaudRate(ModernRoboticsConstants.USB_BAUD_RATE);
        robotUsbDevice.setDataCharacteristics((byte) 8, (byte) 0, (byte) 0);
        robotUsbDevice.setLatencyTimer(ModernRoboticsConstants.LATENCY_TIMER);
    } catch (Exception e) {
        robotUsbDevice.close();
        throw RobotCoreException.createChained(e, "Unable to parameterize USB device " + serialNumber + " - " + description + ": " + e.getMessage());
    }
    try {
        /**
         * TODO: This timeout of 400ms can almost assuredly be reduced with some further analysis.
         *
         * "From: Berling, Jonathan
         * Sent: Tuesday, January 3, 2017
         *
         * [...] When we were developing that code, if we tried to open too many USB devices too
         * quickly they would sometimes fail. We never looked into the cause. It could have been
         * anything from the USB devices themselves, to Android, to the type of hub we were using,
         * etc. (This was long before MR was even considering making a USB hub.)"
         */
        Thread.sleep(400L);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    return robotUsbDevice;
}
Also used : RobotUsbException(org.firstinspires.ftc.robotcore.internal.usb.exception.RobotUsbException) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) RobotUsbDevice(com.qualcomm.robotcore.hardware.usb.RobotUsbDevice)

Aggregations

RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)32 RobotUsbDevice (com.qualcomm.robotcore.hardware.usb.RobotUsbDevice)10 ModernRoboticsUsbDevice (com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice)5 IOException (java.io.IOException)5 CallbackResult (org.firstinspires.ftc.robotcore.internal.network.CallbackResult)4 DuplicateNameException (com.qualcomm.robotcore.exception.DuplicateNameException)3 ControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)3 ByteBuffer (java.nio.ByteBuffer)3 Map (java.util.Map)3 RobotUsbException (org.firstinspires.ftc.robotcore.internal.usb.exception.RobotUsbException)3 RobotConfigFile (com.qualcomm.ftccommon.configuration.RobotConfigFile)2 LegacyModuleControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration)2 MotorControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration)2 ReadXMLFileHandler (com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler)2 ServoControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration)2 Command (com.qualcomm.robotcore.robocol.Command)2 SerialNumber (com.qualcomm.robotcore.util.SerialNumber)2 ArrayList (java.util.ArrayList)2 CancellationException (java.util.concurrent.CancellationException)2 AlertDialog (android.app.AlertDialog)1