Search in sources :

Example 1 with HardwareMap

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 =======");
}
Also used : HardwareMap(com.qualcomm.robotcore.hardware.HardwareMap)

Example 2 with HardwareMap

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;
    }
}
Also used : HardwareMap(com.qualcomm.robotcore.hardware.HardwareMap) LynxUsbDevice(com.qualcomm.hardware.lynx.LynxUsbDevice) LynxUsbDeviceImpl(com.qualcomm.hardware.lynx.LynxUsbDeviceImpl) ArrayList(java.util.ArrayList)

Example 3 with HardwareMap

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;
    }
}
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 4 with HardwareMap

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));
            }
        }
    }
}
Also used : HardwareMap(com.qualcomm.robotcore.hardware.HardwareMap) HardwareDevice(com.qualcomm.robotcore.hardware.HardwareDevice) UserI2cSensorType(com.qualcomm.robotcore.hardware.configuration.UserI2cSensorType)

Example 5 with HardwareMap

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);
}
Also used : HardwareMap(com.qualcomm.robotcore.hardware.HardwareMap) DistanceSensor(com.qualcomm.robotcore.hardware.DistanceSensor)

Aggregations

HardwareMap (com.qualcomm.robotcore.hardware.HardwareMap)6 LynxUsbDevice (com.qualcomm.hardware.lynx.LynxUsbDevice)2 ArrayList (java.util.ArrayList)2 LynxModule (com.qualcomm.hardware.lynx.LynxModule)1 LynxNackException (com.qualcomm.hardware.lynx.LynxNackException)1 LynxUsbDeviceImpl (com.qualcomm.hardware.lynx.LynxUsbDeviceImpl)1 RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)1 DeviceManager (com.qualcomm.robotcore.hardware.DeviceManager)1 DistanceSensor (com.qualcomm.robotcore.hardware.DistanceSensor)1 HardwareDevice (com.qualcomm.robotcore.hardware.HardwareDevice)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 DeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)1 DeviceInterfaceModuleConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceInterfaceModuleConfiguration)1 LegacyModuleControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration)1 LynxI2cDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxI2cDeviceConfiguration)1 LynxModuleConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxModuleConfiguration)1 LynxUsbDeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.LynxUsbDeviceConfiguration)1 MatrixControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration)1