Voltage, Current Awareness, and Safe Test OpModes
Avoid damaging robot hardware while testing code.
Avoid damaging robot hardware while testing code.
In this lesson, you will:
Battery voltage changes robot behavior. A drivetrain that feels gentle at low voltage may be aggressive on a fresh battery, and a mechanism near a hard stop can draw damaging current.
Safe test code assumes something might be wrong. It uses low power, short timeouts, telemetry, and an easy stop path so students can learn without turning every bug into a repair job.
Add voltage telemetry to tests, start with low motor power, clamp outputs, and use timeouts. For mechanisms, begin away from hard stops and verify direction before full travel.
SafeMotorTest.javaJava
double voltage = hardwareMap.voltageSensor.iterator().next().getVoltage();
runtime.reset();
while (opModeIsActive() && runtime.seconds() < 1.0) {
motor.setPower(0.2);
telemetry.addData("voltage", voltage);
telemetry.update();
}
motor.setPower(0);If a motor stalls, stop and inspect the mechanism before increasing power. If voltage is low, do not tune final constants. If a test has no timeout, add one before running it on the floor.
Write a motor test that runs at 20 percent power for one second, reports voltage, then stops regardless of sensor state.
Check your understanding before moving on.
0 of 2 answered