VEXcode Pro V5 PID not going straight

Hi, my PID code does not allow my robot to drive straight, it only turns. Is there a reason for this? Everything above the autonomous function is global. My code is below

1 Like

I know this might be something you have already checked, but I have to make sure, are the motors in the correct port?

yes, all the motors are in the right ports

1 Like

is there anything else wrong with the code

1 Like

have you tried running it with no turn constants?

i would suggest resetting sensors before the task starts as well, it just makes it more accurate.

also, this looks wrong
image

1 Like

what are the turn constants again?

1 Like

image

1 Like

also, im not sure if you have more after resetting, but if this is the end, I would suggest setting the desired positions to 0, so that it doesn’t run a second time.
image

1 Like

if i delte this then what would i use for the turnMotorPower values?

1 Like

just temporarily set them to 0 for right now, so you know that you are only using the forwards PD loop

okay, thank you that works. On a side note, how would i make it turn using this PID

1 Like

from what i see, you have it set up right except
image which should be turnError = desiredValue - turnDifference
and i beleave that image should be turnDerivative = turnPrevError - turnError, atleast that is how i have it

also your constants were probably not calibrated, to do this, set all to 0 except for the KP, then adjust this until the robot goes back and forth over where it should be. when it looks good, then adjust KD until it stops at the right place, repeat for the turn PID (do the same with KI if you ever use the integral part)

2 Likes

Doesn’t this not work since I am multiplying values by them resulting in the motor power to be zero

image
because you add the different parts of the PID together, setting one value to zero will just remove the effect of that part, not the whole PID

edit: if you start calibrating the PID, and it doesn’t move it is likely due to the KP being too low

1 Like

when i did this, the robot would not move.

i know i added this a bit late, so you probably didnt see it, but this might be your problem

if you didn’t fix this, it might not move as well

when i try to make my driving stop, it does not stop. Is there a reason why?

what part doesn’t stop?

it just keeps going forward and does not stop