So my question about a simple P-Loop that I’m testing is what are the units that the motor would read from the feedback from the P-Loop. The P-Loop’s output is power which has a unit of watts, however, the motor seems to only take an input of rpm, dps, and pct.
I added an image of my code. I have never made a P-Loop so it would also be helpful if anyone can say if there is anything wrong with it (minus the constant, I haven’t tuned it yet).
This is technically for a robot to move forward so the method would be for autonomous. There is only one motor receiving feedback from the loop however because I am only testing, in case anyone is curious.
Last thing, the question this post is regarding is about the input that the motor would receive from the loop. It is towards the bottom of the code where Motor1 is called.
To answer The question about exiting the loop. Usually you would have a loop that stops when the encoder reaches the right distance and the P loop just helps it get there. Then when the encoder is far enough along the loop will stop.
You couldn’t do the forever loop forever. You’ll need to make a if condition that tests is the target met(has the encoder arrive the target ticks) and break the forever loop. U can break the loop with this code ( im not sure about vcs sytanix)
If (encoder value >= target){
break;
}
Btw put this in ur while loop
edit: also include stoping motors u want to stop before the break
What about the units the motor will receive? Currently it’s in rpm but the p-loop is sending out how much power is needed. Also, is there a limit to the amount of power the motor can receive? On the vex website, it says the max power is 11 watts. I don’t understand how the p-loop will tell the motor what to do if it isn’t in the same units.
Oh alright, I was just confused because most P-loops I have seen label their output as “power” which is not the right input a motor reads. Just to clarify, the Kp is what you tune so that the motor outputs the correct amount? Makes more sense now.
Essentially the video explains how to create a threshold and if the error is within the threshold, it will give a small delay before exiting the loop which is variable depending on how much time you want the robot to oscillate close enough to the target.