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
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
is there anything else wrong with the code
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
what are the turn constants again?
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.
if i delte this then what would i use for the turnMotorPower values?
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
from what i see, you have it set up right except
which should be turnError = desiredValue - turnDifference
and i beleave that 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)
Doesn’t this not work since I am multiplying values by them resulting in the motor power to be zero
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
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