use of com.qualcomm.robotcore.hardware.HardwareMap in project robotcode by OutoftheBoxFTC.
the class FtcEventLoop method init.
// ------------------------------------------------------------------------------------------------
// Core Event Loop
// ------------------------------------------------------------------------------------------------
/**
* Init method
* <p>
* This code will run when the robot first starts up. Place any initialization code in this
* method.
* <p>
* It is important to save a copy of the event loop manager from this method, as that is how
* you'll get access to the gamepad.
* <p>
* If an Exception is thrown then the event loop manager will not start the robot.
* <p>
* Caller synchronizes: called on RobotSetupRunnable.run() thread
*/
@Override
public void init(EventLoopManager eventLoopManager) throws RobotCoreException, InterruptedException {
RobotLog.ii(TAG, "======= INIT START =======");
super.init(eventLoopManager);
opModeManager.init(eventLoopManager);
registeredOpModes.registerAllOpModes(userOpmodeRegister);
sendUIState();
ftcEventLoopHandler.init(eventLoopManager);
HardwareMap hardwareMap = ftcEventLoopHandler.getHardwareMap();
opModeManager.setHardwareMap(hardwareMap);
hardwareMap.logDevices();
RobotLog.ii(TAG, "======= INIT FINISH =======");
}
use of com.qualcomm.robotcore.hardware.HardwareMap in project robotcode by OutoftheBoxFTC.
the class FtcEventLoopHandler method getExtantLynxDeviceImpls.
public List<LynxUsbDeviceImpl> getExtantLynxDeviceImpls() {
synchronized (hardwareFactory) {
List<LynxUsbDeviceImpl> result = new ArrayList<LynxUsbDeviceImpl>();
HardwareMap map = hardwareMap;
if (map != null) {
for (LynxUsbDevice lynxUsbDevice : map.getAll(LynxUsbDevice.class)) {
if (lynxUsbDevice.getArmingState() == RobotArmingStateNotifier.ARMINGSTATE.ARMED) {
result.add(lynxUsbDevice.getDelegationTarget());
}
}
}
return result;
}
}
use of com.qualcomm.robotcore.hardware.HardwareMap 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;
}
}
use of com.qualcomm.robotcore.hardware.HardwareMap in project robotcode by OutoftheBoxFTC.
the class HardwareFactory method mapUserI2cDevice.
private void mapUserI2cDevice(HardwareMap map, DeviceManager deviceMgr, I2cController i2cController, DeviceConfiguration devConf) {
if (!devConf.isEnabled()) {
return;
}
UserI2cSensorType userType = (UserI2cSensorType) devConf.getConfigurationType();
HardwareDevice hardwareDevice = deviceMgr.createUserI2cDevice(i2cController, devConf.getI2cChannel(), userType, devConf.getName());
if (hardwareDevice != null) {
// Put the device in the overall map
map.put(devConf.getName(), hardwareDevice);
// which it belongs, but don't overwrite any user-named sensor that might be there.
for (HardwareMap.DeviceMapping mapping : map.allDeviceMappings) {
if (mapping.getDeviceTypeClass().isInstance(hardwareDevice)) {
maybeAddToMapping(mapping, devConf.getName(), mapping.cast(hardwareDevice));
}
}
}
}
use of com.qualcomm.robotcore.hardware.HardwareMap in project robotcode by OutoftheBoxFTC.
the class Westcoast method init.
/**
* Identify hardware and then set it up with different objects. Other initialization properties are
* mset to ensure that everything is in the default position or correct mode for the robot.
*/
@Override
public void init() {
// Initialize or nullify all hardware
HardwareMap map = opMode.hardwareMap;
this.jewelSensor = getOrNull(map.colorSensor, "jewelSensor");
this.jewelDistance = map.get(DistanceSensor.class, "jewelSensor");
this.spring = getOrNull(map.servo, "spring");
this.intakeServo = getOrNull(map.servo, "intakeServo");
this.intakeLift = getOrNull(map.dcMotor, "vertical");
this.driveBackLeft = getOrNull(map.dcMotor, "driveBackLeft");
this.driveFrontLeft = getOrNull(map.dcMotor, "driveFrontLeft");
this.driveBackRight = getOrNull(map.dcMotor, "driveBackRight");
this.driveFrontRight = getOrNull(map.dcMotor, "driveFrontRight");
this.intakeBottomLeft = getOrNull(map.crservo, "intakeBLeft");
this.intakeBottomRight = getOrNull(map.crservo, "intakeBRight");
this.intakeTopLeft = getOrNull(map.crservo, "intakeTLeft");
this.intakeTopRight = getOrNull(map.crservo, "intakeTRight");
this.intakeServo = getOrNull(map.servo, "intakeServo");
this.intakeTop = getOrNull(map.dcMotor, "intakeT");
this.intakeBottom = getOrNull(map.dcMotor, "intakeB");
this.jewelVertical = getOrNull(map.servo, "jewelVertical");
this.jewelHorizontal = getOrNull(map.servo, "jewelHorizontal");
this.relicSpool = getOrNull(map.dcMotor, "spooler");
this.relicWrist = getOrNull(map.servo, "relicArm");
this.relicFinger = getOrNull(map.servo, "relicClaw");
this.bottomIntakeSwitch = getOrNull(map.analogInput, "bottomIntakeSwitch");
this.intakePusher = getOrNull(map.servo, "intakeKicker");
// Set the default direction for all the hardware and also initialize default positions
if (driveFrontLeft != null)
driveFrontLeft.setDirection(DcMotorSimple.Direction.REVERSE);
if (driveFrontRight != null)
driveFrontRight.setDirection(DcMotorSimple.Direction.REVERSE);
if (jewelSensor != null) {
redOffset = jewelSensor.red();
blueOffset = jewelSensor.blue();
} else {
redOffset = 0;
blueOffset = 0;
}
if (intakeTopRight != null)
intakeTopRight.setDirection(DcMotorSimple.Direction.REVERSE);
if (intakeBottomRight != null)
intakeBottomRight.setDirection(DcMotorSimple.Direction.REVERSE);
resetMotors(relicSpool, intakeLift);
}
Aggregations