you use the command waitUntil which is could only assume “waits until the potentiometer angle is less than 36 degrees” to move onto the next step. The easiest way to fix this would be to make a function that uses an if statement to determine whether or not the angle of the potentiometer is less than your specified degrees.
Assuming your potentiometer is attached to the same axle as your backlift (and if it’s not, simply apply the gear ratio between the two to the following):
void autonomous(void) {
double motorToPotentiometerGearRatio = 1.0; // Or whatever the case is
double initialPotentiometerReading = Potentiometer.angle(degrees);
double desiredEndPotentiometer = 36;
// Calculate how much you want the motor to rotate
double desiredBackLiftDeployment = motorToPotentiometerGearRatio * ( desiredEndPotentiometer - initialPotentiometerReading );
double backliftDeploymentSpeed = 100;
// The last parameter here is set to false so the motor will spin without waiting for its movement to complete. This is the way to use the non-blocking feature
backlift.spinFor(reverse, desiredBackLiftDeployment , degrees, 100, percent, false);
Drivetrain.driveFor(reverse, 62, inches);
// Do similar to lift the mobile goal
}
Thank you very much for the detailed code and clever suggestion. This is essentially similar to use the motor encode to rotate to the desired angle and set waitforcompletion to false.
The reason I want to use the potentiometer instead of the motor encoder is that the staring point of back lift may not always the same and use absolute position/angle of potentiometer is more accurate.
I will definitely try this. However, I wonder if there is other way with potentiometer only.
You can do this with threads. You can have a thread running the waitUntil so that the motor will still stop with the potentiometer. This way, you can move on to other things while that runs in the background.
I think you are partly on the right track, but not fully there. Your idea to use the potentiometer is good, because it can retain its state through the robot turning off/on, etc. It should tolerate if you set up the backlift at slightly different angles each match. This is fantastic and well-thought out.
However, you seem fixated on exclusively using the potentiometer to solve the problem you’ve identified. The sensor tells you where you are, and you know where you want to go. Telling the motor to move that amount should be functionally equivalent to waiting for the sensor to reach a value.
As @xTigr mentions, there are other ways to solve this problem, such as using threads. IMO, this introduces unnecessary complexity, and may make debugging and tuning more difficult.