Search in sources :

Example 1 with ModernRoboticsUsbDcMotorController

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;
}
Also used : ModernRoboticsUsbDevice(com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) ModernRoboticsUsbDcMotorController(com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController) RobotUsbDevice(com.qualcomm.robotcore.hardware.usb.RobotUsbDevice)

Example 2 with ModernRoboticsUsbDcMotorController

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);
}
Also used : LynxVoltageSensor(com.qualcomm.hardware.lynx.LynxVoltageSensor) VoltageSensor(com.qualcomm.robotcore.hardware.VoltageSensor) ModernRoboticsUsbDcMotorController(com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController) MotorConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)

Aggregations

ModernRoboticsUsbDcMotorController (com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController)2 LynxVoltageSensor (com.qualcomm.hardware.lynx.LynxVoltageSensor)1 ModernRoboticsUsbDevice (com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice)1 RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)1 VoltageSensor (com.qualcomm.robotcore.hardware.VoltageSensor)1 MotorConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)1 RobotUsbDevice (com.qualcomm.robotcore.hardware.usb.RobotUsbDevice)1