Hi, I am trying to write some basic position PID for our autonomous. We have two NEO’s on each side and they are controlled by Spark MAXs. I wrote a simple PID command (based off of what I have written for previous years on my old team) and it works on the cart, and stops and exits the command as expected. HPIDDriveInches.java (3.1 KB) owever, when we put the robot on the ground and run the command, the robot veers off course quickly as it jumps to a start. I will provide my code below for anyone to look at.
On my old robot, we used TalonSRXs which had a method to set the Motion Magic acceleration values and it would gradually increase our speed during PID motion so it didn’t fly off course right at the beginning.
Additionally, if you don’t think that the acceleration is the problem, what else could it be? Thanks in advance and please reply if you have any questions.
I think you’re on the right track – the issue is that you’re commanding the robot to go all the way to its final position immediately, not allowing time for it to accelerate, travel at some max velocity, nor decelerate. If it’s far from that position, left and right PID controllers are going to command the motors to go all the way to 100% Vbus, and unless they behave identically, one is going to get ahead. The two PID controllers are both saturated, and thus aren’t closing the feedback loop while the robot is driving forward, only at the end. The issue is, once the drivetrain sides get out-of-sync with each other, the robot could end up in a very different place from where you intended, even if both sets of wheels made the correct number of turns.
As usbcd36 says, you’re saturating the controllers, and there’s no expectation that they will be able to proceed at the same rate, and hence avoid turning. I encourage you to look at all the support WPILIB has, but if you want to program something simple for yourself, you could look at this “drive straight” tutorial. (If you’re just going to skim that page for the code examples, then you should start from the bottom, because it’s that sort of tutorial.)