Go to Post Amazing how great minds think alike! - Jack Jones [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 01-30-2016, 03:28 PM
Tominator368 Tominator368 is offline
Registered User
AKA: Thomas Schweich
FRC #4500 (Robohounds)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: STL
Posts: 5
Tominator368 is an unknown quantity at this point
Running Two Simultaneous PID Loops

I am having a similar problem to the one found in this http://www.chiefdelphi.com/forums/sh...d.php?t=114061 thread; I want to be able to run multiple different PID loops from the same subsystem. Does anyone know a relatively modular way to create as many PID loops as you want? I'm not sure if it's as straightforward as this:
  1. Create a PIDController object, handing it the proper P,I, and D values, as well as instances of the following two classes:
  2. Create a class extending PIDSource and hand it the value of the controller in PIDget()
  3. Create a class extending PIDOutput and have it change some value inside of PIDWrite()
  4. Use the output of the controllers as needed

I'm struggling to find much documentation or examples regarding these classes and methods, and I'm not sure if that's actually what they do, I'll admit it's basically a guess as to what they are. If anyone could let me know if I'm thinking along the right lines or if I'm misunderstanding these functions that would be great. I may need to implement as many as 3 different PID loops to control the same hardware depending on the scenario, some of them combined with others. Thanks.

EDIT: I ended up just wrapping PIDOutput in a class I called PIDHandler which simply returns the output of the controller in a getValue() method as the "output". I then was able to use those raw outputs in my calculations.

Last edited by Tominator368 : 01-30-2016 at 10:00 PM. Reason: SOLVED
Reply With Quote
  #2   Spotlight this post!  
Unread 01-30-2016, 03:35 PM
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 516
ozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant future
Re: Running Two Simultaneous PID Loops

Can you explain what exactly you're trying to accomplish? There might be a better way then chaining 3 different PIDs.

In that thread the use-case is to have one PID control driving a distance (encoders) and another PID control heading(gyro). They sum nicely by adding/subtracting the heading correction on top of the distance-PID.

How many sensor sources do you have?
Reply With Quote
  #3   Spotlight this post!  
Unread 01-30-2016, 05:06 PM
Tominator368 Tominator368 is offline
Registered User
AKA: Thomas Schweich
FRC #4500 (Robohounds)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: STL
Posts: 5
Tominator368 is an unknown quantity at this point
Re: Running Two Simultaneous PID Loops

Hi ozrien,
To start, I'd like to be able to do pretty much exactly what is described in that thread:
  • I'd like to drive forward to a setpoint using an encoder (the first input).
  • I'd like to simultaneously be able to correct that movement for drift using a gyro reading (the second input).
  • Then, I'd like to be able to stop using that system entirely, and literally switch to using some frontal omni wheels as my output, using a separate encoder on those wheels as my new input (the third possible input).
I apologize for not giving a description of the actual goal in the original post. The biggest thing that I'm interested in knowing is whether or not the way I described in the original post is the actual way PID control with WPILib works. Thanks so much for the help!
Reply With Quote
  #4   Spotlight this post!  
Unread 01-31-2016, 01:39 PM
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,547
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Running Two Simultaneous PID Loops

Quote:
Originally Posted by Tominator368 View Post
I apologize for not giving a description of the actual goal in the original post. The biggest thing that I'm interested in knowing is whether or not the way I described in the original post is the actual way PID control with WPILib works. Thanks so much for the help!
Yes your description is correct. Common sensors such as encoder and gyros implement PIDSource, so you would not need to create your own PIDSource unless you want to monkey with the values from them. Since you described a complex output, you would need to implement your own PIDOutput.
Reply With Quote
  #5   Spotlight this post!  
Unread 02-05-2016, 03:16 AM
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Running Two Simultaneous PID Loops

Quote:
Originally Posted by Tominator368 View Post
Hi ozrien,
To start, I'd like to be able to do pretty much exactly what is described in that thread:
  • I'd like to drive forward to a setpoint using an encoder (the first input).
  • I'd like to simultaneously be able to correct that movement for drift using a gyro reading (the second input).
  • Then, I'd like to be able to stop using that system entirely, and literally switch to using some frontal omni wheels as my output, using a separate encoder on those wheels as my new input (the third possible input).
I apologize for not giving a description of the actual goal in the original post. The biggest thing that I'm interested in knowing is whether or not the way I described in the original post is the actual way PID control with WPILib works. Thanks so much for the help!
Our library does that for years. We combined multiple PID controllers. The goal was to do PID control on a subsystem level, not on a motor level. For example, we have a driveBase.setTarget method that can specify the X, Y, and Turn targets. So on a mecanum drive base, autonomous can set an X, Y position as well as a heading, the robot will execute it. This is achieved by combining three PID controllers, one for X, one for Y and one for TURN. The input sources for X and Y are encoders and gyro for TURN. In fact, our library allows you to combine any PID controllers for the drive base. For example, we used it quite often in FTC where we do line following using driveBase.setTarget by specifying a Y PID controller using Ultrasonic sensor as the PIDInput and light sensor as the TURN PID controller's PIDInput.
__________________
Reply With Quote
  #6   Spotlight this post!  
Unread 02-09-2016, 12:38 PM
geniusadam69 geniusadam69 is offline
Registered User
FRC #5923
 
Join Date: Feb 2016
Location: Houston, TX
Posts: 5
geniusadam69 is an unknown quantity at this point
Re: Running Two Simultaneous PID Loops

Quote:
Originally Posted by Tominator368 View Post
  1. Create a PIDController object, handing it the proper P,I, and D values, as well as instances of the following two classes:
  2. Create a class extending PIDSource and hand it the value of the controller in PIDget()
  3. Create a class extending PIDOutput and have it change some value inside of PIDWrite()
  4. Use the output of the controllers as needed
I just want to address items 2 and 3 of this. If you do decide to go your own route. The PIDSource and PIDoutput are small classes that need to be extended. The controller will send the output to the PIDOutput. It will call the PIDWrite(), and so you would presumably use this to write to the motors.

The PIDSource is a bit trickier. The pidGet() method should just return the sensor data. All in all they're both just wrappers of data that allow the PIDController class a fixed class to interact with. You may also want to just consider anonymous classes. They simplify your overall project structure.
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 07:28 AM.

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