Using a Voltage Sensor

How can i implement a internal voltage sensor in the rev control hub into my program so I can use it to multiply or divide other values? ex. (PIDF values) / (voltage reading) for autonomous or
(set motor power controlled via joysticks) x (voltage reading) in TeleOp
I’ve seen people talk about voltagesensor.iterator but don’t really understand it due to the lack of an example/explanation.

In your Java OpMode, add these 3 lines,each at its relevant place:

import com.qualcomm.robotcore.hardware.VoltageSensor;
private VoltageSensor myControlHubVoltageSensor;
myControlHubVoltageSensor = hardwareMap.get(VoltageSensor.class, "Control Hub");

To store or read the voltage value:

double presentVoltage;
presentVoltage = myControlHubVoltageSensor.getVoltage();

In FTC Blocks, this is all done automatically, with the only Block under Sensors/VoltageSensor.

Please let us know how it went!