Search in sources :

Example 1 with MatrixControllerConfiguration

use of com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration 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 2 with MatrixControllerConfiguration

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

DeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)2 MatrixControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration)2 HiTechnicNxtDcMotorController (com.qualcomm.hardware.hitechnic.HiTechnicNxtDcMotorController)1 LynxDcMotorController (com.qualcomm.hardware.lynx.LynxDcMotorController)1 LynxServoController (com.qualcomm.hardware.lynx.LynxServoController)1 MatrixDcMotorController (com.qualcomm.hardware.matrix.MatrixDcMotorController)1 MatrixMasterController (com.qualcomm.hardware.matrix.MatrixMasterController)1 MatrixServoController (com.qualcomm.hardware.matrix.MatrixServoController)1 ModernRoboticsUsbDcMotorController (com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController)1 DcMotorController (com.qualcomm.robotcore.hardware.DcMotorController)1 ServoController (com.qualcomm.robotcore.hardware.ServoController)1 BuiltInConfigurationType (com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType)1 ConfigurationType (com.qualcomm.robotcore.hardware.configuration.ConfigurationType)1 ControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)1 LynxI2cDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration)1 LynxUsbDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration)1 MotorConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)1 MotorControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration)1 ServoConfiguration (com.qualcomm.robotcore.hardware.configuration.ServoConfiguration)1 ServoControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration)1