Search in sources :

Example 1 with DcMotor

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

the class HardwareFactory method mapMotor.

private void mapMotor(HardwareMap map, DeviceManager deviceMgr, MotorConfiguration motorConf, DcMotorController dcMotorController) {
    if (!motorConf.isEnabled()) {
        return;
    }
    DcMotor dcMotor = deviceMgr.createDcMotor(dcMotorController, motorConf.getPort(), motorConf.getMotorType(), motorConf.getName());
    map.dcMotor.put(motorConf.getName(), dcMotor);
}
Also used : DcMotor(com.qualcomm.robotcore.hardware.DcMotor)

Example 2 with DcMotor

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

the class Hardware method resetMotors.

/**
 * Waits for all the motors to have zero position and if it is not zero tell it to reset
 *
 * @param motors all the motors to reset
 */
public static void resetMotors(@NonNull DcMotor... motors) {
    boolean notReset = true;
    while (notReset) {
        boolean allReset = true;
        for (DcMotor motor : motors) {
            if (motor.getCurrentPosition() == 0) {
                continue;
            }
            allReset = false;
            motor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
        }
        notReset = !allReset;
    }
    for (DcMotor motor : motors) motor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
}
Also used : DcMotor(com.qualcomm.robotcore.hardware.DcMotor)

Example 3 with DcMotor

use of com.qualcomm.robotcore.hardware.DcMotor 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 4 with DcMotor

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

the class MatrixDcMotorController method setMotorPower.

/**
 * Sets the power for a group of motors.
 *
 * @param motors This provides an optimization specific to the Matrix controller
 *               by using the controller's pending bit to tell all of the motors
 *               to start at the same time.
 * @param power  The motor power to apply to all motors in the set.
 */
public synchronized void setMotorPower(Set<DcMotor> motors, double power) {
    pendMotorPowerChanges = true;
    try {
        for (DcMotor motor : motors) {
            motor.setPower(power);
        }
        /*
             * Write the start flag to start the motors.
             */
        MatrixI2cTransaction transaction = new MatrixI2cTransaction((byte) 0, MatrixI2cTransaction.I2cTransactionProperty.PROPERTY_START, 0x01);
        master.queueTransaction(transaction);
    } finally {
        pendMotorPowerChanges = false;
    }
}
Also used : DcMotor(com.qualcomm.robotcore.hardware.DcMotor)

Aggregations

DcMotor (com.qualcomm.robotcore.hardware.DcMotor)4 LynxAnalogInputController (com.qualcomm.hardware.lynx.LynxAnalogInputController)1 LynxDcMotorController (com.qualcomm.hardware.lynx.LynxDcMotorController)1 LynxDigitalChannelController (com.qualcomm.hardware.lynx.LynxDigitalChannelController)1 LynxModule (com.qualcomm.hardware.lynx.LynxModule)1 LynxPwmOutputController (com.qualcomm.hardware.lynx.LynxPwmOutputController)1 LynxServoController (com.qualcomm.hardware.lynx.LynxServoController)1 LynxVoltageSensor (com.qualcomm.hardware.lynx.LynxVoltageSensor)1 DeviceConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)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 MotorConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)1