Search in sources :

Example 1 with VoltageSensor

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

the class FtcEventLoopHandler method buildRobotBatteryMsg.

/**
 * Build a string which indicates the lowest measured system voltage
 *
 * @return String representing battery voltage
 */
private String buildRobotBatteryMsg() {
    // Don't do anything if we're really early in the construction cycle
    if (this.hardwareMap == null) {
        return null;
    }
    double minBatteryLevel = Double.POSITIVE_INFINITY;
    // 
    for (VoltageSensor sensor : this.hardwareMap.voltageSensor) {
        // Read the voltage, keeping track of how long it takes to do so
        long nanoBefore = System.nanoTime();
        double sensorVoltage = sensor.getVoltage();
        long nanoAfter = System.nanoTime();
        if (sensorVoltage >= 1.0) /* an unreasonable value to ever see in practice */
        {
            // For valid reads, we add the read-duration to our statistics, in ms.
            robotBatteryStatistics.add((nanoAfter - nanoBefore) / (double) ElapsedTime.MILLIS_IN_NANO);
            // Keep track of the minimum valid value we find
            if (sensorVoltage < minBatteryLevel) {
                minBatteryLevel = sensorVoltage;
            }
        }
    }
    String msg;
    if (minBatteryLevel == Double.POSITIVE_INFINITY) {
        msg = NO_VOLTAGE_SENSOR;
    } else {
        // Convert double voltage into string with *two* decimal places (fast), given the
        // above-maintained fact the voltage is at least 1.0.
        msg = Integer.toString((int) (minBatteryLevel * 100));
        msg = new StringBuilder(msg).insert(msg.length() - 2, ".").toString();
    }
    return (msg);
}
Also used : VoltageSensor(com.qualcomm.robotcore.hardware.VoltageSensor)

Example 2 with VoltageSensor

use of com.qualcomm.robotcore.hardware.VoltageSensor 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);
}
Also used : MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) LynxVoltageSensor(com.qualcomm.hardware.lynx.LynxVoltageSensor) VoltageSensor(com.qualcomm.robotcore.hardware.VoltageSensor) HiTechnicNxtDcMotorController(com.qualcomm.hardware.hitechnic.HiTechnicNxtDcMotorController) MotorConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)

Example 3 with VoltageSensor

use of com.qualcomm.robotcore.hardware.VoltageSensor 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);
}
Also used : LynxVoltageSensor(com.qualcomm.hardware.lynx.LynxVoltageSensor) VoltageSensor(com.qualcomm.robotcore.hardware.VoltageSensor) ModernRoboticsUsbDcMotorController(com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController) MotorConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)

Aggregations

VoltageSensor (com.qualcomm.robotcore.hardware.VoltageSensor)3 LynxVoltageSensor (com.qualcomm.hardware.lynx.LynxVoltageSensor)2 MotorConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorConfiguration)2 HiTechnicNxtDcMotorController (com.qualcomm.hardware.hitechnic.HiTechnicNxtDcMotorController)1 ModernRoboticsUsbDcMotorController (com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController)1 MotorControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration)1