Go to Post Spread inspiration; Don't destroy it. - IntensifiedAmp [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-01-2017, 12:31
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 212
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
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
Reply With Quote
  #2   Spotlight this post!  
Unread 21-01-2017, 13:15
TylerHarmon's Avatar
TylerHarmon TylerHarmon is offline
Registered User
no team
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Westminster, CO
Posts: 25
TylerHarmon is an unknown quantity at this point
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
Reply With Quote
  #3   Spotlight this post!  
Unread 21-01-2017, 13:27
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 212
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 21-01-2017, 13:38
TylerHarmon's Avatar
TylerHarmon TylerHarmon is offline
Registered User
no team
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Westminster, CO
Posts: 25
TylerHarmon is an unknown quantity at this point
Re: PID loop speeds up as it gets closer to target?

Quote:
Originally Posted by jreneew2 View Post
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?
Reply With Quote
  #5   Spotlight this post!  
Unread 21-01-2017, 13:41
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 212
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
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);
Reply With Quote
  #6   Spotlight this post!  
Unread 21-01-2017, 13:58
TylerHarmon's Avatar
TylerHarmon TylerHarmon is offline
Registered User
no team
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Westminster, CO
Posts: 25
TylerHarmon is an unknown quantity at this point
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.
Reply With Quote
  #7   Spotlight this post!  
Unread 21-01-2017, 15:26
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 212
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
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
Reply With Quote
  #8   Spotlight this post!  
Unread 21-01-2017, 15:36
TylerHarmon's Avatar
TylerHarmon TylerHarmon is offline
Registered User
no team
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Westminster, CO
Posts: 25
TylerHarmon is an unknown quantity at this point
Re: PID loop speeds up as it gets closer to target?

Quote:
Originally Posted by jreneew2 View Post
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
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 23:54.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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