Search in sources :

Example 11 with DeviceConfiguration

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

the class HardwareFactory method mapLynxModuleComponents.

private void mapLynxModuleComponents(HardwareMap map, DeviceManager deviceMgr, LynxUsbDeviceConfiguration lynxUsbDeviceConfiguration, LynxUsbDevice lynxUsbDevice, Map<Integer, LynxModule> connectedModules) throws LynxNackException, RobotCoreException, InterruptedException {
    // Hook up the pieces to each module
    for (DeviceConfiguration moduleConfiguration : lynxUsbDeviceConfiguration.getModules()) {
        LynxModule module = connectedModules.get(moduleConfiguration.getPort());
        // Ignore modules that ultimately didn't connect
        if (module == null) {
            continue;
        }
        LynxModuleConfiguration lynxModuleConfiguration = (LynxModuleConfiguration) moduleConfiguration;
        // For each module, hook up motor controller and motors
        LynxDcMotorController mc = new LynxDcMotorController(context, module);
        map.dcMotorController.put(moduleConfiguration.getName(), mc);
        for (MotorConfiguration motorConf : lynxModuleConfiguration.getMotors()) {
            if (motorConf.isEnabled()) {
                DcMotor m = deviceMgr.createDcMotorEx(mc, motorConf.getPort(), motorConf.getMotorType(), motorConf.getName());
                map.dcMotor.put(motorConf.getName(), m);
            }
        }
        // And hook up servo controller and servos
        LynxServoController sc = new LynxServoController(context, module);
        map.servoController.put(moduleConfiguration.getName(), sc);
        for (DeviceConfiguration servoConf : lynxModuleConfiguration.getServos()) {
            mapServoEx(map, deviceMgr, servoConf, sc);
        }
        // And a voltage sensor
        LynxVoltageSensor voltageSensor = new LynxVoltageSensor(context, module);
        map.voltageSensor.put(moduleConfiguration.getName(), voltageSensor);
        // Also a PWM Output Controller
        LynxPwmOutputController pwmOutputController = new LynxPwmOutputController(context, module);
        map.put(moduleConfiguration.getName(), pwmOutputController);
        buildLynxDevices(lynxModuleConfiguration.getPwmOutputs(), map, deviceMgr, pwmOutputController);
        // Also an AnalogInputController
        LynxAnalogInputController analogInputController = new LynxAnalogInputController(context, module);
        map.put(moduleConfiguration.getName(), analogInputController);
        buildLynxDevices(lynxModuleConfiguration.getAnalogInputs(), map, deviceMgr, analogInputController);
        // And a digital channel controller
        LynxDigitalChannelController digitalChannelController = new LynxDigitalChannelController(context, module);
        map.put(moduleConfiguration.getName(), digitalChannelController);
        buildLynxDevices(lynxModuleConfiguration.getDigitalDevices(), map, deviceMgr, digitalChannelController);
        // And I2c devices
        buildLynxI2cDevices(lynxModuleConfiguration.getI2cDevices(), map, deviceMgr, module);
    }
}
Also used : LynxModule(com.qualcomm.hardware.lynx.LynxModule) LynxServoController(com.qualcomm.hardware.lynx.LynxServoController) LynxDcMotorController(com.qualcomm.hardware.lynx.LynxDcMotorController) LynxAnalogInputController(com.qualcomm.hardware.lynx.LynxAnalogInputController) LynxDigitalChannelController(com.qualcomm.hardware.lynx.LynxDigitalChannelController) LynxPwmOutputController(com.qualcomm.hardware.lynx.LynxPwmOutputController) MotorConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorConfiguration) LynxVoltageSensor(com.qualcomm.hardware.lynx.LynxVoltageSensor) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) LynxI2cDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration) LynxModuleConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxModuleConfiguration) DcMotor(com.qualcomm.robotcore.hardware.DcMotor)

Example 12 with DeviceConfiguration

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

the class HardwareFactory method mapUsbLegacyModule.

private void mapUsbLegacyModule(HardwareMap map, DeviceManager deviceMgr, LegacyModuleControllerConfiguration ctrlConf) throws RobotCoreException, InterruptedException {
    if (!ctrlConf.isEnabled()) {
        return;
    }
    LegacyModule legacyModule = deviceMgr.createUsbLegacyModule(ctrlConf.getSerialNumber(), ctrlConf.getName());
    map.legacyModule.put(ctrlConf.getName(), legacyModule);
    for (DeviceConfiguration devConf : ctrlConf.getDevices()) {
        ConfigurationType devType = devConf.getConfigurationType();
        if (devType == BuiltInConfigurationType.GYRO) {
            mapNxtGyroSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.COMPASS) {
            mapNxtCompassSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.IR_SEEKER) {
            mapNxtIrSeekerSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.LIGHT_SENSOR) {
            mapNxtLightSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.ACCELEROMETER) {
            mapNxtAccelerationSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.MOTOR_CONTROLLER) {
            mapNxtDcMotorController(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.SERVO_CONTROLLER) {
            mapNxtServoController(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.TOUCH_SENSOR) {
            mapNxtTouchSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.TOUCH_SENSOR_MULTIPLEXER) {
            mapNxtTouchSensorMultiplexer(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.ULTRASONIC_SENSOR) {
            mapSonarSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.COLOR_SENSOR) {
            mapNxtColorSensor(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.MATRIX_CONTROLLER) {
            mapMatrixController(map, deviceMgr, legacyModule, devConf);
        } else if (devType == BuiltInConfigurationType.NOTHING) {
        // nothing to do
        } else {
            RobotLog.w("Unexpected device type connected to Legacy Module while parsing XML: " + devType.toString());
        }
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) UserConfigurationType(com.qualcomm.robotcore.hardware.configuration.UserConfigurationType) LegacyModule(com.qualcomm.robotcore.hardware.LegacyModule) ModernRoboticsUsbLegacyModule(com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbLegacyModule) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) LynxI2cDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

Example 13 with DeviceConfiguration

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

the class HardwareFactory method mapMatrixController.

private void mapMatrixController(HardwareMap map, DeviceManager deviceMgr, LegacyModule legacyModule, DeviceConfiguration devConf) {
    if (!devConf.isEnabled()) {
        return;
    }
    MatrixMasterController master = new MatrixMasterController((ModernRoboticsUsbLegacyModule) legacyModule, devConf.getPort());
    DcMotorController mc = new MatrixDcMotorController(master);
    map.dcMotorController.put(devConf.getName() + "Motor", mc);
    map.dcMotorController.put(devConf.getName(), mc);
    for (DeviceConfiguration motorConf : ((MatrixControllerConfiguration) devConf).getMotors()) {
        mapMotor(map, deviceMgr, (MotorConfiguration) motorConf, mc);
    }
    ServoController sc = new MatrixServoController(master);
    map.servoController.put(devConf.getName() + "Servo", sc);
    map.servoController.put(devConf.getName(), sc);
    for (DeviceConfiguration servoConf : ((MatrixControllerConfiguration) devConf).getServos()) {
        mapServo(map, deviceMgr, servoConf, sc);
    }
}
Also used : MatrixControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration) MatrixMasterController(com.qualcomm.hardware.matrix.MatrixMasterController) MatrixServoController(com.qualcomm.hardware.matrix.MatrixServoController) MatrixDcMotorController(com.qualcomm.hardware.matrix.MatrixDcMotorController) MatrixDcMotorController(com.qualcomm.hardware.matrix.MatrixDcMotorController) ModernRoboticsUsbDcMotorController(com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController) HiTechnicNxtDcMotorController(com.qualcomm.hardware.hitechnic.HiTechnicNxtDcMotorController) DcMotorController(com.qualcomm.robotcore.hardware.DcMotorController) LynxDcMotorController(com.qualcomm.hardware.lynx.LynxDcMotorController) LynxUsbDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration) LynxI2cDeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration) LynxServoController(com.qualcomm.hardware.lynx.LynxServoController) MatrixServoController(com.qualcomm.hardware.matrix.MatrixServoController) ServoController(com.qualcomm.robotcore.hardware.ServoController)

Example 14 with DeviceConfiguration

use of com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration 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)

Example 15 with DeviceConfiguration

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

the class EditLegacyModuleControllerActivity method editController_portALL.

/**
 * When the drop-down item is a Controller, this button appears. Clicking it launches the
 * appropriate activity
 *
 * @param v - the button that got pressed
 */
public void editController_portALL(View v) {
    // view is Button
    // view.getParent is RelativeLayout
    // view.getparent.getparent is the LinearLayout around the whole module zone
    LinearLayout layout = (LinearLayout) v.getParent().getParent();
    TextView portNumber = (TextView) layout.findViewById(R.id.portNumber);
    int port = Integer.parseInt(portNumber.getText().toString());
    DeviceConfiguration currentModule = devices.get(port);
    if (!isController(currentModule)) {
        Spinner choiceSpinner = (Spinner) layout.findViewById(R.id.choiceSpinner);
        ConfigurationTypeAndDisplayName pair = (ConfigurationTypeAndDisplayName) choiceSpinner.getSelectedItem();
        createController(port, pair.configurationType);
    }
    editController_general(currentModule);
}
Also used : Spinner(android.widget.Spinner) TextView(android.widget.TextView) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration) LinearLayout(android.widget.LinearLayout)

Aggregations

DeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)21 EditText (android.widget.EditText)8 LynxI2cDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration)8 LynxUsbDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration)8 TextView (android.widget.TextView)7 View (android.view.View)4 CheckBox (android.widget.CheckBox)4 LynxServoController (com.qualcomm.hardware.lynx.LynxServoController)4 MatrixServoController (com.qualcomm.hardware.matrix.MatrixServoController)3 ServoController (com.qualcomm.robotcore.hardware.ServoController)3 BuiltInConfigurationType (com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType)3 ConfigurationType (com.qualcomm.robotcore.hardware.configuration.ConfigurationType)3 LynxDcMotorController (com.qualcomm.hardware.lynx.LynxDcMotorController)2 LynxModule (com.qualcomm.hardware.lynx.LynxModule)2 LynxModuleConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxModuleConfiguration)2 MatrixControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration)2 MotorConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)2 ServoControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration)2 ArrayList (java.util.ArrayList)2 LinearLayout (android.widget.LinearLayout)1