use of com.qualcomm.robotcore.hardware.configuration.MotorConfiguration 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);
}
use of com.qualcomm.robotcore.hardware.configuration.MotorConfiguration 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);
}
}
use of com.qualcomm.robotcore.hardware.configuration.MotorConfiguration 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);
}
use of com.qualcomm.robotcore.hardware.configuration.MotorConfiguration 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);
}
}
}
use of com.qualcomm.robotcore.hardware.configuration.MotorConfiguration in project robotcode by OutoftheBoxFTC.
the class EditLegacyModuleControllerActivity method editController_general.
/**
* Launches the activity for the controller
*
* @param controller - the module we're about to edit
*/
private void editController_general(DeviceConfiguration controller) {
// names already gone
LinearLayout layout = (LinearLayout) findViewByPort(controller.getPort());
EditText nameText = (EditText) layout.findViewById(R.id.editTextResult);
controller.setName(nameText.getText().toString());
if (controller.getConfigurationType() == BuiltInConfigurationType.MOTOR_CONTROLLER) {
EditParameters<MotorConfiguration> parameters = new EditParameters<MotorConfiguration>(this, controller, MotorConfiguration.class, ((MotorControllerConfiguration) controller).getMotors());
parameters.setInitialPortNumber(ModernRoboticsConstants.INITIAL_MOTOR_PORT);
parameters.setConfigurationTypes(MotorConfiguration.getAllMotorConfigurationTypes());
handleLaunchEdit(EditLegacyMotorControllerActivity.requestCode, EditLegacyMotorControllerActivity.class, parameters);
} else if (controller.getConfigurationType() == BuiltInConfigurationType.SERVO_CONTROLLER) {
EditParameters<ServoConfiguration> parameters = new EditParameters<ServoConfiguration>(this, controller, ServoConfiguration.class, ((ServoControllerConfiguration) controller).getServos());
parameters.setInitialPortNumber(ModernRoboticsConstants.INITIAL_SERVO_PORT);
handleLaunchEdit(EditLegacyServoControllerActivity.requestCode, EditLegacyServoControllerActivity.class, parameters);
} else if (controller.getConfigurationType() == BuiltInConfigurationType.MATRIX_CONTROLLER) {
handleLaunchEdit(EditMatrixControllerActivity.requestCode, EditMatrixControllerActivity.class, controller);
}
}
Aggregations