P-Loop Question About Power Output (v5)

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). PID%20Test%20Code

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.

Last thing again, would closing the loop just be if the error is 0, set the power to 0 as well? Perhaps set the motor to hold?

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

If u dont include this the motors wont stop

And the thread will be traped in the while loop forever

Tip: btw u only need to do while(1) u dont need while(1==1)

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.

Conceptually the kp value us converting units of encoder ticks to rpm or power. Depending on the actual value of kp. Don’t worry about it.

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.

You can use a timer to stop the loop. Try watching this and this for specifics.

1 Like

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.

I’m not sure how exactly to do this for VCS considering the video is for robotc.