Search in sources :

Example 1 with MotorControllerConfiguration

use of com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration in project robotcode by OutoftheBoxFTC.

the class HardwareFactory method mapNxtDcMotorController.

private void mapNxtDcMotorController(HardwareMap map, DeviceManager deviceMgr, LegacyModule legacyModule, DeviceConfiguration ctrlConf) {
    if (!ctrlConf.isEnabled()) {
        return;
    }
    HiTechnicNxtDcMotorController dcMotorController = (HiTechnicNxtDcMotorController) deviceMgr.createHTDcMotorController(legacyModule, ctrlConf.getPort(), ctrlConf.getName());
    map.dcMotorController.put(ctrlConf.getName(), dcMotorController);
    for (MotorConfiguration motorConf : ((MotorControllerConfiguration) ctrlConf).getMotors()) {
        mapMotor(map, deviceMgr, motorConf, dcMotorController);
    }
    VoltageSensor voltageSensor = dcMotorController;
    map.voltageSensor.put(ctrlConf.getName(), voltageSensor);
}
Also used : MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) LynxVoltageSensor(com.qualcomm.hardware.lynx.LynxVoltageSensor) VoltageSensor(com.qualcomm.robotcore.hardware.VoltageSensor) HiTechnicNxtDcMotorController(com.qualcomm.hardware.hitechnic.HiTechnicNxtDcMotorController) MotorConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)

Example 2 with MotorControllerConfiguration

use of com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration in project robotcode by OutoftheBoxFTC.

the class HardwareFactory method createHardwareMap.

// ------------------------------------------------------------------------------------------------
// Hardware management
// ------------------------------------------------------------------------------------------------
/**
 * Create a hardware map
 *
 * @return HardwareMap
 */
public HardwareMap createHardwareMap(EventLoopManager manager) throws RobotCoreException, InterruptedException {
    // We synchronize with scanning so that there's only one thread trying to open *new* FTDI devices at a time
    synchronized (HardwareDeviceManager.scanDevicesLock) {
        RobotLog.vv(TAG, "createHardwareMap()");
        // Clear notion of embedded lynx module that we currently have. We'll discovery a new one,
        // if he's there, when we go through the below.
        WifiDirectInviteDialogMonitor.clearUILynxModule();
        HardwareMap map = new HardwareMap(context);
        if (xmlPullParser != null) {
            DeviceManager deviceMgr = new HardwareDeviceManager(context, manager);
            ReadXMLFileHandler readXmlFileHandler = new ReadXMLFileHandler();
            List<ControllerConfiguration> ctrlConfList = readXmlFileHandler.parse(xmlPullParser);
            for (ControllerConfiguration ctrlConf : ctrlConfList) {
                ConfigurationType type = ctrlConf.getConfigurationType();
                if (type == BuiltInConfigurationType.MOTOR_CONTROLLER) {
                    mapUsbMotorController(map, deviceMgr, (MotorControllerConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.SERVO_CONTROLLER) {
                    mapUsbServoController(map, deviceMgr, (ServoControllerConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.LEGACY_MODULE_CONTROLLER) {
                    mapUsbLegacyModule(map, deviceMgr, (LegacyModuleControllerConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.DEVICE_INTERFACE_MODULE) {
                    mapCoreInterfaceDeviceModule(map, deviceMgr, (DeviceInterfaceModuleConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.LYNX_USB_DEVICE) {
                    mapLynxUsbDevice(map, deviceMgr, (LynxUsbDeviceConfiguration) ctrlConf);
                } else {
                    RobotLog.ee(TAG, "Unexpected controller type while parsing XML: " + type.toString());
                }
            }
        } else {
            // no XML to parse, just return empty map
            RobotLog.vv(TAG, "no xml to parse: using empty map");
        }
        return map;
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) UserConfigurationType(com.qualcomm.robotcore.hardware.configuration.UserConfigurationType) HardwareMap(com.qualcomm.robotcore.hardware.HardwareMap) ReadXMLFileHandler(com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler) DeviceInterfaceModuleConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceInterfaceModuleConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) DeviceManager(com.qualcomm.robotcore.hardware.DeviceManager) LegacyModuleControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) MatrixControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration)

Example 3 with MotorControllerConfiguration

use of com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration in project robotcode by OutoftheBoxFTC.

the class FtcConfigurationActivity method populateList.

/**
 * Populates the list with the relevant controllers from the deviceControllers variable.
 * That variable is either from scanned devices, or read in from an xml file.
 */
private void populateList() {
    ListView controllerListView = (ListView) findViewById(R.id.controllersList);
    // Before we launch, we want the scan to have completed
    try {
        scannedDevices = usbScanManager.awaitScannedDevices();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    // Make sure we'll report serial numbers correctly as attached or not
    tellControllersAboutAttachment();
    DeviceInfoAdapter adapter = new DeviceInfoAdapter(this, android.R.layout.simple_list_item_2, new LinkedList<ControllerConfiguration>(getRobotConfigMap().controllerConfigurations()));
    controllerListView.setAdapter(adapter);
    controllerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View v, int pos, long arg3) {
            ControllerConfiguration controllerConfiguration = (ControllerConfiguration) adapterView.getItemAtPosition(pos);
            ConfigurationType itemType = controllerConfiguration.getConfigurationType();
            if (itemType == BuiltInConfigurationType.MOTOR_CONTROLLER) {
                EditParameters parameters = initParameters(ModernRoboticsConstants.INITIAL_MOTOR_PORT, MotorConfiguration.class, controllerConfiguration, ((MotorControllerConfiguration) controllerConfiguration).getMotors());
                parameters.setConfigurationTypes(MotorConfiguration.getAllMotorConfigurationTypes());
                handleLaunchEdit(EditMotorControllerActivity.requestCode, EditMotorControllerActivity.class, parameters);
            } else if (itemType == BuiltInConfigurationType.SERVO_CONTROLLER) {
                EditParameters parameters = initParameters(ModernRoboticsConstants.INITIAL_SERVO_PORT, ServoConfiguration.class, controllerConfiguration, ((ServoControllerConfiguration) controllerConfiguration).getServos());
                handleLaunchEdit(EditServoControllerActivity.requestCode, EditServoControllerActivity.class, parameters);
            } else if (itemType == BuiltInConfigurationType.LEGACY_MODULE_CONTROLLER) {
                EditParameters parameters = initParameters(0, DeviceConfiguration.class, controllerConfiguration, ((LegacyModuleControllerConfiguration) controllerConfiguration).getDevices());
                handleLaunchEdit(EditLegacyModuleControllerActivity.requestCode, EditLegacyModuleControllerActivity.class, parameters);
            } else if (itemType == BuiltInConfigurationType.DEVICE_INTERFACE_MODULE) {
                EditParameters parameters = initParameters(0, DeviceConfiguration.class, controllerConfiguration, ((DeviceInterfaceModuleConfiguration) controllerConfiguration).getDevices());
                handleLaunchEdit(EditDeviceInterfaceModuleActivity.requestCode, EditDeviceInterfaceModuleActivity.class, parameters);
            } else if (itemType == BuiltInConfigurationType.LYNX_USB_DEVICE) {
                EditParameters parameters = initParameters(0, LynxModuleConfiguration.class, controllerConfiguration, ((LynxUsbDeviceConfiguration) controllerConfiguration).getDevices());
                handleLaunchEdit(EditLynxUsbDeviceActivity.requestCode, EditLynxUsbDeviceActivity.class, parameters);
            }
        }
    });
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) LegacyModuleControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) AdapterView(android.widget.AdapterView) MotorConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorConfiguration) LegacyModuleControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration) LynxModuleConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxModuleConfiguration)

Example 4 with MotorControllerConfiguration

use of com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration in project robotcode by OutoftheBoxFTC.

the class EditLegacyModuleControllerActivity method createController.

/**
 * If the drop-down spinner-selected item is a Controller (Motor- or Servo-), we need to create
 * an empty Controller with the proper number of motors/servos.
 *
 * @param port    - the port where this controller got added
 * @param newType - the type of controller we're creating
 */
private void createController(int port, ConfigurationType newType) {
    DeviceConfiguration currentModule = devices.get(port);
    String name = currentModule.getName();
    SerialNumber serialNumber = new SerialNumber();
    ConfigurationType currentType = currentModule.getConfigurationType();
    if (!(currentType == newType)) {
        // only update the controller if it's a new choice.
        ControllerConfiguration newModule;
        if (newType == BuiltInConfigurationType.MOTOR_CONTROLLER) {
            ArrayList<MotorConfiguration> motors = new ArrayList<MotorConfiguration>();
            for (int motorPortNumber = ModernRoboticsConstants.INITIAL_MOTOR_PORT; motorPortNumber <= ModernRoboticsConstants.NUMBER_OF_MOTORS; motorPortNumber++) {
                motors.add(new MotorConfiguration(motorPortNumber));
            }
            newModule = new MotorControllerConfiguration(name, motors, serialNumber);
            newModule.setPort(port);
        } else if (newType == BuiltInConfigurationType.SERVO_CONTROLLER) {
            ArrayList<ServoConfiguration> servos = new ArrayList<ServoConfiguration>();
            for (int servoPortNumber = ModernRoboticsConstants.INITIAL_SERVO_PORT; servoPortNumber <= ModernRoboticsConstants.NUMBER_OF_SERVOS; servoPortNumber++) {
                servos.add(new ServoConfiguration(servoPortNumber));
            }
            newModule = new ServoControllerConfiguration(name, servos, serialNumber);
            newModule.setPort(port);
        } else if (newType == BuiltInConfigurationType.MATRIX_CONTROLLER) {
            ArrayList<MotorConfiguration> motors = new ArrayList<MotorConfiguration>();
            for (int motorPortNumber = MatrixConstants.INITIAL_MOTOR_PORT; motorPortNumber <= MatrixConstants.NUMBER_OF_MOTORS; motorPortNumber++) {
                motors.add(new MotorConfiguration(motorPortNumber));
            }
            ArrayList<ServoConfiguration> servos = new ArrayList<ServoConfiguration>();
            for (int servoPortNumber = MatrixConstants.INITIAL_SERVO_PORT; servoPortNumber <= MatrixConstants.NUMBER_OF_SERVOS; servoPortNumber++) {
                servos.add(new ServoConfiguration(servoPortNumber));
            }
            newModule = new MatrixControllerConfiguration(name, motors, servos, serialNumber);
            newModule.setPort(port);
        } else {
            newModule = null;
        }
        if (newModule != null) {
            newModule.setEnabled(true);
            setModule(newModule);
        }
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) ArrayList(java.util.ArrayList) MatrixControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration) SerialNumber(com.qualcomm.robotcore.util.SerialNumber) ServoConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) MatrixControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration) MotorConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

Aggregations

MotorControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration)4 BuiltInConfigurationType (com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType)3 ConfigurationType (com.qualcomm.robotcore.hardware.configuration.ConfigurationType)3 ControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)3 MotorConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)3 ServoControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration)3 DeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)2 LegacyModuleControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration)2 MatrixControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration)2 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 HiTechnicNxtDcMotorController (com.qualcomm.hardware.hitechnic.HiTechnicNxtDcMotorController)1 LynxVoltageSensor (com.qualcomm.hardware.lynx.LynxVoltageSensor)1 DeviceManager (com.qualcomm.robotcore.hardware.DeviceManager)1 HardwareMap (com.qualcomm.robotcore.hardware.HardwareMap)1 VoltageSensor (com.qualcomm.robotcore.hardware.VoltageSensor)1 DeviceInterfaceModuleConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceInterfaceModuleConfiguration)1 LynxModuleConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxModuleConfiguration)1