Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   PID loop speeds up as it gets closer to target? (http://www.chiefdelphi.com/forums/showthread.php?t=154032)

jreneew2 21-01-2017 12:31

PID loop speeds up as it gets closer to target?
 
Hey I'm programming a mecanum drive base and previously we used a simple function that slowed it down as we got closer to the target. However, we want to make a more complex PID loop so we can strafe and rotate at the same time more smoothly.

I am using a navx and the PIDController class. I based my changes off of the examples that the navx comes with. However, I'd rather not change too much of what we already have. All I want to do is compute the absolute speed that we want.

So the problem I'm having is that the output speed that it is giving me doesn't make sense. It starts slow and gets faster in the middle and slows down at the end. This causes us to rotate much slower than we could before.

Here is a link to my code:
https://github.com/team2053tigertron...e/TigerDrive.h

https://github.com/team2053tigertron...TigerDrive.cpp

Thank you for the help,
Drew

TylerHarmon 21-01-2017 13:15

Re: PID loop speeds up as it gets closer to target?
 
What motor controller are you using?

Verify that your motor controller and sensor are in-phase. In-phase means that if you apply a positive throttle to the motor controller, the sensor moves in a positive direction.

If the motor controller and sensor are not in-phase, then you might want to go to setPoint = 500, but the sensor is reading -250, and when you try to go forward, the sensor shows that you are going backwards, i.e. towards -500. That could cause the PID loop to accelerate towards your setPoint, because as far as the PID loop knows, you are getting further away from the setPoint.

Good luck!

-Tyler

jreneew2 21-01-2017 13:27

Re: PID loop speeds up as it gets closer to target?
 
Im using 4 talon srxs.

But all im doing is calculating absolute speed based on absolute degrees to the angle I am rotating to. It shouldn't matter in this case, unless I am missing something.

TylerHarmon 21-01-2017 13:38

Re: PID loop speeds up as it gets closer to target?
 
Quote:

Originally Posted by jreneew2 (Post 1634457)
Im using 4 talon srxs.

But all im doing is calculating absolute speed based on absolute degrees to the angle I am rotating to. It shouldn't matter in this case, unless I am missing something.

Are you using the PID loops on the Talon SRX, or are you running your own on the roboRIO?

jreneew2 21-01-2017 13:41

Re: PID loop speeds up as it gets closer to target?
 
We are running on the roboRIO. Have you taken a look at my code that i linked in the first post?

Relevant code:
Code:

    rotateToAngleRate = 0.0f;
    turnController = new frc::PIDController(kP, kI, kD, kF, this, this);
    turnController->SetInputRange(0.0f,  180.0f);
    turnController->SetOutputRange(0.2, 1.0);
    turnController->SetAbsoluteTolerance(kToleranceDegrees);
    turnController->SetContinuous(true);

Code:

    turnController->Enable();
    speedWhileRotating = rotateToAngleRate;
    std::cout << "speedWhileRotating: " << speedWhileRotating << std::endl;
    isRotDone = false;
    degreesToAngleAbs = fabs(degreesToAngle);


TylerHarmon 21-01-2017 13:58

Re: PID loop speeds up as it gets closer to target?
 
Yes, I looked over your code, but I am unfamiliar with CPP.

Try printing out your PID error to the console. Knowing where the PID loop thinks it is can be very useful for debugging. If the PID loop is speeding up towards the setpoint, it could be that the PID does not correctly understand where it is, or the PID gain constants could be tuned poorly.

Seeing as you are only using a P term right now, I would suggest looking at the error that your PID loop sees. As I said earlier, the control system still needs to be in-phase. What you are seeing here could very likely be caused by a gyroscope and drive train that are out of phase.

jreneew2 21-01-2017 15:26

Re: PID loop speeds up as it gets closer to target?
 
Thank you for the help! I figured it out. I just changed the input and output range back to full range of the IMU. Then I let the PID loop control the direction we are rotating.

Drew

TylerHarmon 21-01-2017 15:36

Re: PID loop speeds up as it gets closer to target?
 
Quote:

Originally Posted by jreneew2 (Post 1634492)
Thank you for the help! I figured it out. I just changed the input and output range back to full range of the IMU. Then I let the PID loop control the direction we are rotating.

Drew

Great! Glad to hear it :D


All times are GMT -5. The time now is 15:30.

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