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);
}
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);
}
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);
}
Aggregations