PID Questions

This is the first year that our team will be using a PID. In the past we’ve simply used dead reckoning to move around during autonomous mode and had few problems. However, with the game this year, we’re going to use sensors and that means that I need to learn a new skill. I’ve been looking at various information, examples, and sample code for a few days now and I must say, I’m somewhat confused. I’m going to try to explain what I’m doing and hopefully I’ll be able to get a bit of help :slight_smile:

Alright, our team is using the kit Gyro and 2 Grayhill 63R encoders. I’m also using Kevin Watson’s new code as the base for our teams robot code. I’ve managed (without too much trouble) to get the gyro and encoders wired up and running.

My problem comes with the actual writing of the PID code since even after reading much of the available information, I’m still quite confused. As I understand it, I see us needing velocity (to determine speed) and positional (to determine direction) PID’s for both hybrid mode and teleoperated mode. When I look at some of the PID code snippets that I’ve found here at CD, I’m getting the feeling that I could make it work but I feel like I’m not understanding how the code works.

I hope that this hasn’t come out too much like a stream of consciousness however, it’s getting late and I’ve been trying to figure this out for quite a while now. If anything that I have said is completely wrong (I have my doubts on the definitions of velocity and positional PID’s) please correct me. I truly thank anyone who can help me out here.

EDIT: I knew that I forgot something. Due to strong influence from the robot operator. I somehow also have to try to program the control to two stick tank type i.e. left-stick y-axis controls left side speed and right-stick y-axis controls right side speed. He’s gotten pretty good at that over the years so, I can’t really just change it for his last year operating the robot.

We are a six wheel bot. We are using PID in the autonomous mode but not the driver mode. Unless done right it will fight the drivers. Drivers have PID built into their brain.

PID is more of an art than science. First you must understand the science about it and then use the art to tune it.

You don’t use at all times all the letters of PID.

For going straight using encoders we are now just using the P part. That is simply subtracting one encoder from the other that will be the P. Then we just add that to a basepower of each wheel, one wheel we add another wheel we subtract. Basepower is the power it takes to adjust the speed you want to go.

BTW I do not do speed PID. It gets really complicated to have a speed and a straight PID at same time. I am not the best at PID and I know some can do it, but I don’t want to mess with it. This year we are on a flat surface, so a set basepower will allow you to go about the same speed each time, especially sense the batteries are fresh for that 15 seconds.

Now remember each wheel encoder will be off because each wheel is not exactly thee same, on our test bot they are 5% off from each other so we adjust that.

How this would look in code:

propostional = (LeftEncoder-RightEncoder)*Pfactor

Pfactor you have to experiment with, we are using 1.

Leftpower = basepower + proportional
Rightpower = basepower - proportional

That will get you going very straight if your encoders in 10 ft will give you the same readings.

For the turn we did something similiar. Don’t have time forr that right now, maybe later see if this makes sense and works, you can tell me you are ready for a turn later.

BTW we might use the I integral to even fine tune the straight even more.

Thank you for that advice. Now that I’ve actually had some sleep and food, I realize that it doesn’t look quite as daunting as it did before. Also, I realize that I don’t really need the velocity based PID in autonomous mode. Having the PID’s in teleoperated mode is the idea of one our teams engineers however, like I said in my OP, our driver (my younger brother) has been learning how to operate the robot with our current control scheme since I was a sophomore in HS (the 2001 season I think), and he’s been the teams driver for the last 3 years. So, I think we can convince our dear engineer that the PID in teleoperated mode isn’t necessary. Today at our shop I’ll try out the Proportional code and see what I can do. Thank you again for your help.

We have put driver assist in the past, but usually it gets ignored by the drivers. But where it makes sense then it is helpful, and we are doing some driver assist this year.

Tonight we are working on putting the PID in the drive straight using encoders. We had the P but not the ID and it worked well, but when we went 40 ft it was slightly off. I think adding in the whole PID to that will clean that up. Problem with doing the whole PID is that each of the letters will fight with one another to get that balance, so tuning it is critical.

So that is why I suggest doing the P first and then adding the rest. I will post what the results were.

Remember to make sure that your two encoders are putting out the same values for the same distance. We did this by pushing the robot by hand for 10 feet following a straight line and writing down the readings. We did this five times in a row and averaged the readings. We found the right was 5% higher than the left. So once the encoders were read we multiplied the left by 1.05 to make sure they were equal.