Go to Post We try to do cool stuff (note: I didn't say it always works). - marshall [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-02-2011, 21:52
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
Fighting PID

I have yet to try this, but I'm curious...

I want to control the facing direction of the robot with a gyro and PID AND I want to control the travel direction of the robot with an accelerometer and PID.

Will these two PIDs fight each other? If so, how would I program around that? Also, what's a good way to program it, considering I can only use one pidWrite() function per class?
  #2   Spotlight this post!  
Unread 20-02-2011, 22:01
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: Fighting PID

One solution:
Write a PID loop from scratch; it is a win win situation. You solve that problem, and you learn how to make a PID Loop and how it functions.
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
  #3   Spotlight this post!  
Unread 20-02-2011, 22:04
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
Re: Fighting PID

I'm actually in the process of doing that, and just found a strange problem...

I found this in the PIDController class in WPILibJ:
Code:
if (((m_totalError + m_error) * m_I < m_maximumOutput)
                        && ((m_totalError + m_error) * m_I > m_minimumOutput))
{
       m_totalError += m_error;
}

m_result = (m_P * m_error + m_I * m_totalError + m_D * (m_error - m_prevError));
m_prevError = m_error;
By the looks of it, it's saying that it won't add the error to the total error if the result would be outside the maximum and minimum output. Does that seem wrong to anyone else? Shouldn't it add the error no matter what, and then clip off the result to fit in the max and min output?
  #4   Spotlight this post!  
Unread 20-02-2011, 22:17
Patrickwhite's Avatar
Patrickwhite Patrickwhite is offline
May the North be with you
FRC #0610 (The Coyotes)
Team Role: Programmer
 
Join Date: Dec 2008
Rookie Year: 2008
Location: Toronto
Posts: 88
Patrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of light
Re: Fighting PID

Quote:
Originally Posted by Geek 2.0 View Post
I'm actually in the process of doing that, and just found a strange problem...

I found this in the PIDController class in WPILibJ:
Code:
if (((m_totalError + m_error) * m_I < m_maximumOutput)
                        && ((m_totalError + m_error) * m_I > m_minimumOutput))
{
       m_totalError += m_error;
}

m_result = (m_P * m_error + m_I * m_totalError + m_D * (m_error - m_prevError));
m_prevError = m_error;
By the looks of it, it's saying that it won't add the error to the total error if the result would be outside the maximum and minimum output. Does that seem wrong to anyone else? Shouldn't it add the error no matter what, and then clip off the result to fit in the max and min output?
That is usually how it's done. There are a few things in WPI's implementation that don't make sense, but overall it's fairly useful.

In terms of your original question, even if you used WPI's implementation, your output doesn't have to feed straight into a motor. If you have them as separate outputs, then decide yourself how to feed them into the speed controllers, there shouldn't be any problem.
__________________
while(!going.isTough());
tough.exit();

What will we do tonight, Warfa?
The same thing we do every night, Patrick. Sit and wait for Electrical.
  #5   Spotlight this post!  
Unread 20-02-2011, 22:31
kgzak's Avatar
kgzak kgzak is offline
Registered User
AKA: Kris
FRC #4392 (Decievers) FRC #2075 (Enigma)
Team Role: College Student
 
Join Date: Dec 2008
Rookie Year: 2008
Location: Grand Rapids, Michigan
Posts: 418
kgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to behold
Re: Fighting PID

We've always written our own PID loops. I have never used the PIDs given to us, I find that if you make you're own you can customize it to what you need. It's not that difficult, I use Labview though.
  #6   Spotlight this post!  
Unread 20-02-2011, 22:42
Deetman Deetman is offline
Registered User
AKA: Kevin Dieterle
no team
 
Join Date: Apr 2004
Rookie Year: 2004
Location: Philadelphia, PA
Posts: 203
Deetman has a reputation beyond reputeDeetman has a reputation beyond reputeDeetman has a reputation beyond reputeDeetman has a reputation beyond reputeDeetman has a reputation beyond reputeDeetman has a reputation beyond reputeDeetman has a reputation beyond reputeDeetman has a reputation beyond reputeDeetman has a reputation beyond reputeDeetman has a reputation beyond reputeDeetman has a reputation beyond repute
Re: Fighting PID

Quote:
Originally Posted by Geek 2.0 View Post
I have yet to try this, but I'm curious...

I want to control the facing direction of the robot with a gyro and PID AND I want to control the travel direction of the robot with an accelerometer and PID.

Will these two PIDs fight each other? If so, how would I program around that? Also, what's a good way to program it, considering I can only use one pidWrite() function per class?
I guess I'm a bit confused as to what you are using your sensors for. Using a PID with a gyroscope as feedback to control what direction your robot is definitely possible. As far as the accelerometer as a feedback sensor into a PID control loop, what exactly are you trying to control, direction of travel? Accelerometers pose an interesting control problem due to their sensitivity to noise including noise from vibrations in which a first robot has many. This can of course be overcome but I guess I'm confused as to what the accel will be helping control... Not saying you are wrong or that it won't work but to help you more I could use a bit more info.
__________________

FIRST Mid-Atlantic Volunteer (2012-present)
Team 1014 Alumni (2004-2005)
Team 1712 Mentor (2011-2015)
  #7   Spotlight this post!  
Unread 20-02-2011, 22:47
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
Re: Fighting PID

I must say, I'm having a bit of trouble understanding what WPILibJ is doing. I'm trying to use it as a reference, but it's contradicting itself. Another example of something that doesn't make much sense:
Code:
if (m_continuous)
{
      if (Math.abs(m_error) > (m_maximumInput - m_minimumInput) / 2)
      {
             if (m_error > 0)
             {
                    m_error = m_error - m_maximumInput + m_minimumInput;
             }
             else
             {
                    m_error = m_error 	+ m_maximumInput - m_minimumInput;
              }
       }
}
Continuous means that we don't use maximum and minimum input values. but apparently if we're continuous, we're referencing maximum and minimum inputs values!!! What's going on now??

Maybe I shouldn't use this as a reference...
  #8   Spotlight this post!  
Unread 20-02-2011, 23:28
Alexander Meyer Alexander Meyer is offline
Registered User
FRC #2358 (Bearbotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Lake Zurich, Illinois
Posts: 36
Alexander Meyer is on a distinguished road
Re: Fighting PID

Continuous mode still uses the min and max values, but not as limits--instead, it assumes that the shortest route to the setpoint can be achieved by going past the max back to the min and vice/versa. At least, if the comment on the SetContinuous method is to be believed..
  #9   Spotlight this post!  
Unread 20-02-2011, 23:42
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
Re: Fighting PID

Wow, just wrote a lot of code (with no testing in between... this'll end poorly).

Thanks, that makes sense. Since I don't have that, I'm not supporting that feature. It all works out now.
  #10   Spotlight this post!  
Unread 20-02-2011, 23:49
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Fighting PID

Quote:
Originally Posted by Geek 2.0 View Post
By the looks of it, it's saying that it won't add the error to the total error if the result would be outside the maximum and minimum output. Does that seem wrong to anyone else?
Seems right to me.


Quote:
Shouldn't it add the error no matter what, and then clip off the result to fit in the max and min output?
No. You don't want the integrator error to continue winding up once it's large enough to produce the maximum output.


Closed Thread


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:33.

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