Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Using PID in autonomous to keep straight (http://www.chiefdelphi.com/forums/showthread.php?t=147655)

Dpurry23 23-04-2016 21:40

Using PID in autonomous to keep straight
 
Need help figuring out how to use PID to go over an obstacle turn to a certain point. (ex. The position that the robot calibrates at)

This is the code I have so far.
Code:

myRobot.SetSafetyEnabled(false);

myRobot.Drive(-.5,0.0);
Wait(1.5);
myRobot.Drive(0.0, 0.0);
turnController->SetSetpoint(0.0f);
Wait(2.0); // Have to wait till the bot turns

Language is C++

Poseidon5817 24-04-2016 01:18

Re: Using PID in autonomous to keep straight
 
Quote:

Originally Posted by Dpurry23 (Post 1578009)
Need help figuring out how to use PID to go over an obstacle turn to a certain point. (ex. The position that the robot calibrates at)

This is the code I have so far.
Code:

myRobot.SetSafetyEnabled(false);

myRobot.Drive(-.5,0.0);
Wait(1.5);
myRobot.Drive(0.0, 0.0);
turnController->SetSetpoint(0.0f);
Wait(2.0); // Have to wait till the bot turns

Language is C++

You can't use a PID loop without a feedback source, e.g. a gyro or encoders. Do you have a gyro or encoders on your drive?

Dpurry23 24-04-2016 01:44

Re: Using PID in autonomous to keep straight
 
Sorry for not explaining, we are using a gyro as a source with the output being our drivetrain.

Poseidon5817 24-04-2016 01:54

Re: Using PID in autonomous to keep straight
 
Quote:

Originally Posted by Dpurry23 (Post 1578071)
Sorry for not explaining, we are using a gyro as a source with the output being our drivetrain.

Ok thanks. At its simplest, you could do something like this:

Code:

double angle = robot.getAngle();
double angleError = AngleYouWantToBe - angle;
double output = constant * angleError;
myRobot.drive(output, 0);
Wait(2.0);
myRobot.drive(0, 0);

This is a simple P loop. It takes the angle error, multiplies it by a constant you specify, and applies that as the output for your drive. As you get closer, your output gets smaller because the error gets smaller, and it coasts to a stop. Note that due to the fact that a drive train needs a certain percentage to actually drive (e.g. 10%), it will never actually make it the whole way to where you want it to go with just a P loop, although you could make it where it gets pretty close, depending on how you tune your constant.

If you want to get more complex than that, you could use a PI loop, but that's another story.

rich2202 24-04-2016 06:53

Re: Using PID in autonomous to keep straight
 
Here is the problem:

PID presumes continuous measurements. If you are crossing the low bar with no jerky movements, then PID works ok for driving straight (our robot drives like a slightly drunken sailor).

Over the other Defenses, the jerkiness throws off PID. You will eventually head in the right direction (gyro), but you may be off track to the left/right.

euhlmann 24-04-2016 16:24

Re: Using PID in autonomous to keep straight
 
Quote:

Originally Posted by rich2202 (Post 1578083)
Here is the problem:

PID presumes continuous measurements. If you are crossing the low bar with no jerky movements, then PID works ok for driving straight (our robot drives like a slightly drunken sailor).

Over the other Defenses, the jerkiness throws off PID. You will eventually head in the right direction (gyro), but you may be off track to the left/right.

You'd only be off by a few inches. That shouldn't be a problem.

We used proportional control to drive straight in auto, and we didn't have any problems.

SamcFuchs 24-04-2016 18:06

Re: Using PID in autonomous to keep straight
 
Quote:

Originally Posted by euhlmann (Post 1578208)
You'd only be off by a few inches. That shouldn't be a problem.

We used proportional control to drive straight in auto, and we didn't have any problems.

Yeah but the issue is its unpredictability. For example, the ramparts tend to send robots in any direction, and there's no good way to predict that. Also, a couple inches can be a big deal, particularly when trying to shoot without a vision system. Earlier in the season, we calculated that the margin of error when shooting the high goal in auto (if you go straight through the low bar and spin) to be ~1.5 degrees and 2-3 inches IIRC.

xjschwen 24-04-2016 19:02

Re: Using PID in autonomous to keep straight
 
We did not use a PID just the Proportional part of it... and it is good enough to cross the ramparts in auto, then spin 180 and cross them again during lab work. We never had any issues staying straight on any of the defenses.

There are some items that we will be cleaning up in the off season but it did work.

As a matter of fact auto was better then telle-op.

https://github.com/WhitmoreLakeTroBo.../CMDdrive.java

https://github.com/WhitmoreLakeTroBo...tCaluator.java

Dpurry23 24-04-2016 21:26

Re: Using PID in autonomous to keep straight
 
Here is a link to our entire code https://github.com/Dpurry23/FRC-Team.../src/Robot.cpp


All times are GMT -5. The time now is 05:03.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi