use of com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbServoController in project robotcode by OutoftheBoxFTC.
the class HardwareDeviceManager method createUsbServoController.
/* (non-Javadoc)
* @see com.qualcomm.hardware.DeviceManager#createUsbServoController(com.qualcomm.robotcore.util.SerialNumber)
*/
@Override
public ServoController createUsbServoController(final SerialNumber serialNumber, String name) throws RobotCoreException, InterruptedException {
HardwareFactory.noteSerialNumberType(context, serialNumber, context.getString(R.string.moduleDisplayNameServoController));
RobotLog.v("Creating %s", HardwareFactory.getDeviceDisplayName(context, serialNumber));
ModernRoboticsUsbDevice.OpenRobotUsbDevice openRobotUsbDevice = new ModernRoboticsUsbDevice.OpenRobotUsbDevice() {
@Override
public RobotUsbDevice open() throws RobotCoreException, InterruptedException {
RobotUsbDevice dev = null;
try {
dev = ModernRoboticsUsbUtil.openUsbDevice(true, usbManager, serialNumber);
byte[] deviceHeader = getModernRoboticsDeviceHeader(dev);
DeviceType type = getModernRoboticsDeviceType(dev, deviceHeader);
if (type != DeviceType.MODERN_ROBOTICS_USB_SERVO_CONTROLLER) {
closeAndThrowOnFailedDeviceTypeCheck(dev, serialNumber);
}
dev.setFirmwareVersion(getModernRoboticsFirmwareVersion(deviceHeader));
} catch (RobotCoreException e) {
if (dev != null) {
// avoid leakage of open FT_Devices
dev.close();
}
throw e;
} catch (RuntimeException e) {
if (dev != null) {
// avoid leakage of open FT_Devices
dev.close();
}
throw e;
}
return dev;
}
};
ModernRoboticsUsbServoController controller = new ModernRoboticsUsbServoController(context, serialNumber, openRobotUsbDevice, manager);
controller.armOrPretend();
controller.initializeHardware();
return controller;
}
Aggregations