Potentiometer

I don’t know why my potentiometer won’t reset. I say SensorValue[potentiometer] = 0 and it doesn’t work.

I do not believe you reset potentiometer values - instead, you are getting the reading from the potentiometer’s current position (computed from its resistance and normalized to the range).

To build on what @lacsap said, potentiometers report their absolute position and, ignoring noise, always give the exact same value every time it is at a certain angle. This is in contrast to encoders, which tell you how much they have turned relative to when you turn on the robot (or when you reset it). This is helpful for mechanisms that may not always start in the exact same position or to calibrate unreliable sensors (such as IMEs) should they fail, but it also means that you cannot reset them to zero. I can’t think of a scenario in which you would want to reset them, but assuming you have a valid reason (which I’m sure you do), one workaround would be to use a variable to store the position of the potentiometer and then report the difference between the variable and current positions. Take a look at the following code:


int potPos = 0;
void resetPot() {
    potPos = SensorValue[potentiometer];
}

task main() {
    while (true) {
        doSomethingWithPot(SensorValue[potentiometer] - potPos);
    }
}


potPos

is a variable that stores where the potentiometer was when you reset it. The


resetPot()

function simple stores the current potentiometer position in this varaiable. To access the potentiometer later, instead of referencing


SensorValue[potentiometer]

like normal, you should subtract


potPos

, which effectively factors in where you reset it.

This implementation also has the benefit of not erasing the potentiometer’s position data, so if you ever need to get the non-reset value, you can still use


SensorValue[potentiometer]

like normal.