PID Assistance

Hi, I’m making this topic looking for help on my PID Loop. I believe my issue has something to do with how the correction is used for setting motor velocities to fix the error but am not sure what is going on. When I set my kP, kI, or kD to any value above 0 the robot just begins to spin in circles and cannot figure out what is wrong. I took inspiration from the Caution Tape P Loop and George Gillard document but there seems to still be something wrong. I’ve explored other topics and done research but no solution I have implemented has worked, can someone with more experience in this topic possibly assist me?
PID.iqblocks (33.2 KB)

For some reason, when I open your file, it’s just a when started block. I think screenshots are more reliable for block code sharing, although it is more cumbersome for larger projects.
Also, why are you coding a PID in blocks?
(This topic also fits better under Technical Support than General Discussion)

It is all there, just not grouped together, you have to go and look for the functions (not that they ever get called). Here is the code I see.

2 Likes

Sorry about that, forgot about the filters. Because I have minimal grasp of script and I was trying to figure it out in blocks before re-coding it all to script as my like personal lesson of how to understand it all.

Were you able to look at it at all?

I could open Vexcode, but it was only a normal new project.
I updated it to 4.07 and it works.

So this is a turn PID? Start with kP as 1 and leave kI and kD as 0 for now. Increase kP by 1 until it hits the target. If it oscillates slightly that’s fine, use kD. Assuming you are tuning for 90,60,45 degree turns and those are all fine, when you turn for 30 you may need kI for an extra boost. If you get that far you might need to restrict the range for which kI will kick in.

It may be that it spins because you have too high kI?

A few more things:

Can you not just set the motor velocities to output? Instead of velocity + output.

It is possible that the robot never reaches the desired heading somehow. I’d print it to the brain. You may also need to take the absolute value of Desired Heading - BrainInertialHeading, depending on how you are doing angle stuff.

Have you used the George Gillard to try and set your kp, ki & kd? You are starting them all at 1. If you start them at 0 you have effectively removed them from your code and you can add them back in 1 at a time.

Also I find it helpful to lift the robot up in the air and see if the wheels are spinning as expected. As jpearman points out, you aren’t calling for their function yet. What are you doing to initiate the actual block?

For drive reverse you may be able to simply input a negative distance in your normal drive myblock instead of developing two separate functions.

This is a drive Straight PID. If I set only kP to 1 it will spin in circles (I don’t know why all the values are 1 in the file I sent that was a mistake). If I set the velocity to output it will not move as the error by default is zero therefore making everything else 0 nullifying the velocity to 0 as well. I will try the abs thing with the heading and print it on the brain to check it out when I get home and update you then. Thank you!

It was a mistake in the file for them all to be 1, also I deleted (don’t remember why) under control F Up it was calling them originally. I know the thing about setting it as a negative distance on the drive forward it just feels more organized in two separate blocks for me. If I set kP to any value above 0 then the robot will just spin in circles for some reason and I think it’s something to do with my math somewhere. Thank you!

You are trying to drive straight. So your wheels should both be spinning forward. In order for the robot to spin, the wheels have to move in opposite directions. This tells us the robot is trying to get to the desired heading (aka turn).

A few things to try:

  • make sure the robot is already on the correct heading, in other words, all it has to do is stay on the line it is already pointing. It sounds like the desired heading and the heading the inertial is reading are way off from one another. The P basically is overshooting the correction and spins out of control.
  • ensure your motors are all switched in the correct direction. One way of testing is to set a very long straight drive and trigger it, pick the robot up in the air so the wheels aren’t touching the ground and slowly rotate the bot so it is approximately on the correct heading. Are the wheels all moving in the forward direction? are they still spinning opposite of each other? If so you probably have a direction wrong in the setup.
  • Drive straight isn’t best for turning, use a separate myblock for a precise turn and then use your straight to drive largely straight. You don’t want a huge error causing a large imbalance between your right side and left side wheel power
1 Like

Whenever I see robots spinning (unintentionally) the first thing I check is the inertial sensor. I realize that this is IQ, so the inertial is built into the brain. Do you have another brain to try the code on? It’s possible for the inertial to be faulty, in which case it will spin because it is looking for an angle but has no input to tell it that it has reached it. This will cause it to spin until it times out. Just something to rule out

If everything else is ruled out, it was probably an internal issue, which cost my team a couple of tournaments. We solved it by re-typing the code in a new file:

I edited the post so the video shows here on the forum, put the link on a line on its own. If we can’t see the video during the approval process we don’t usually have time to go and check they are appropriate.

3 Likes

Thanks a lot! I was wondering why my 100% appropriate posts keep disappearing.

1 Like

You seem to be trying to promote your youtube channel, take a break from posting.

1 Like

Just helping people. I believe nobody else needs it at this moment, so sure.

1 Like