use of com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController in project robotcode by OutoftheBoxFTC.
the class HardwareDeviceManager method createUsbDcMotorController.
/* (non-Javadoc)
* @see com.qualcomm.hardware.DeviceManager#createUsbDcMotorController(com.qualcomm.robotcore.util.SerialNumber)
*/
@Override
public DcMotorController createUsbDcMotorController(final SerialNumber serialNumber, String name) throws RobotCoreException, InterruptedException {
HardwareFactory.noteSerialNumberType(context, serialNumber, context.getString(R.string.moduleDisplayNameMotorController));
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_DC_MOTOR_CONTROLLER) {
closeAndThrowOnFailedDeviceTypeCheck(dev, serialNumber);
}
dev.setFirmwareVersion(getModernRoboticsFirmwareVersion(deviceHeader));
} catch (RobotCoreException | RuntimeException e) {
if (dev != null) {
// avoid leakage of open FT_Devices
dev.close();
}
throw e;
}
return dev;
}
};
ModernRoboticsUsbDcMotorController controller = new ModernRoboticsUsbDcMotorController(context, serialNumber, openRobotUsbDevice, manager);
controller.armOrPretend();
controller.initializeHardware();
return controller;
}
use of com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController in project robotcode by OutoftheBoxFTC.
the class HardwareFactory method mapUsbMotorController.
private void mapUsbMotorController(HardwareMap map, DeviceManager deviceMgr, MotorControllerConfiguration ctrlConf) throws RobotCoreException, InterruptedException {
if (!ctrlConf.isEnabled()) {
return;
}
ModernRoboticsUsbDcMotorController dcMotorController = (ModernRoboticsUsbDcMotorController) deviceMgr.createUsbDcMotorController(ctrlConf.getSerialNumber(), ctrlConf.getName());
map.dcMotorController.put(ctrlConf.getName(), dcMotorController);
for (MotorConfiguration motorConf : ctrlConf.getMotors()) {
mapMotor(map, deviceMgr, motorConf, dcMotorController);
}
VoltageSensor voltageSensor = dcMotorController;
map.voltageSensor.put(ctrlConf.getName(), voltageSensor);
}
Aggregations