Go to Post Here, and in general, avoid jumping to conclusions without research. This will serve you well in life. - DonRotolo [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 Rating: Thread Rating: 44 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 20-02-2013, 12:58
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Running multiple PID loops on the drivetrain

Is it possible to use more than one PID controller for a subsystem like the drivetrain? Example: An encoder PID loop to drive to a distance setpoint, while a gyro PID loop keeps the robot going straight.

You could also substitute encoder with Ultrasonic sensor, etc.

If you can't run them simultaneously, is there a way to switch between PID controllers to, say, drive forward 5 meters distance (via encoder), then turn 90 degrees (via gyro), then drive forward again, etc?
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Reply With Quote
  #2   Spotlight this post!  
Unread 20-02-2013, 13:02
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: Running multiple PID loops on the drivetrain

Quote:
Originally Posted by F22Rapture View Post
Is it possible to use more than one PID controller for a subsystem like the drivetrain? Example: An encoder PID loop to drive to a distance setpoint, while a gyro PID loop keeps the robot going straight.

You could also substitute encoder with Ultrasonic sensor, etc.

If you can't run them simultaneously, is there a way to switch between PID controllers to, say, drive forward 5 meters distance (via encoder), then turn 90 degrees (via gyro), then drive forward again, etc?
Yes. Feed the output of the PIDs into Arcade Drive. Use the output of the angle control PID as the joystick input that makes the robot turn, and use the output of the distance PID as the joystick input that makes the robot drive forward.
__________________
-
An ounce of perception is worth a pound of obscure.
Reply With Quote
  #3   Spotlight this post!  
Unread 20-02-2013, 13:15
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Running multiple PID loops on the drivetrain

Quote:
Originally Posted by Chris Hibner View Post
Yes. Feed the output of the PIDs into Arcade Drive. Use the output of the angle control PID as the joystick input that makes the robot turn, and use the output of the distance PID as the joystick input that makes the robot drive forward.
Nice and elegant. I like it.

Have you tried this before and can confirm that it works?
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Reply With Quote
  #4   Spotlight this post!  
Unread 20-02-2013, 13:34
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,572
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 multiple PID loops on the drivetrain

It gets a little tricky with the PIDController class, since it wants to write directly to a speed controller, which doesn't work when you want to mix the results of multiple PID controllers and output to multiple speed controllers. What we did was create a class called DummyPIDOutput that implements PIDOutput but doesn't output anything. We then read the DummyPIDOutput in our drive code and do the mixing there.

There's probably an easier way, but this what worked for us. I've attached our DummyPIDOutput class.
Attached Files
File Type: java DummyPIDOutput.java (786 Bytes, 140 views)
Reply With Quote
  #5   Spotlight this post!  
Unread 20-02-2013, 13:52
loafdog loafdog is offline
Registered User
AKA: Maciej
FRC #2876 (DevilBotz)
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2009
Location: Burlington, MA
Posts: 35
loafdog is an unknown quantity at this point
Re: Running multiple PID loops on the drivetrain

The first few posts of this thread are useful.
http://www.chiefdelphi.com/forums/sh...ad.php?t=98300

I've spent alot of time looking at CD threads about using PIDController and picked up some useful tips about pid and java. Try searching and reading what others have posted.

We tried creating two PID controllers in our drive train subsystem. One uses two encoders(averaged) on the drive train and the other uses a gryo. In the PID constructors we specified a different PIDOutput class/object that did not write data to jaguars unless we set vars to allow it. See
http://code.google.com/p/frc2876/sou...riveTrain.java

And this is the command we use to combine the distance/turn PIDs to make robot drive in a straight line:
http://code.google.com/p/frc2876/sou...dStraight.java

We did not get a chance to finish testing this before having to bag the robot so I can't say if it works. But based on the CD thread I found above plenty of teams are doing something like this.
Reply With Quote
  #6   Spotlight this post!  
Unread 20-02-2013, 17:29
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Running multiple PID loops on the drivetrain

If you extend PIDCommand and require() the subsystem, your PID will automatically be cancelled when another is started, allowing you to have different PID controls.
__________________
I code stuff.
Reply With Quote
  #7   Spotlight this post!  
Unread 20-02-2013, 17:41
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,187
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Running multiple PID loops on the drivetrain

We do this and the logic is pretty simple.

Code:
motorL.set(straightControllerResult + turnControllerResult);
motorR.set(straightControllerResult - turnControllerResult);
Where straight controller and turn controller are separate PID controllers, using the drive encoders for distance and the gyro for angle respectively.

We did something similar to Joe (we don't use the WPILib PIDController, but we have a similar modular output system in ours).

Code:
private class DTOutput implements PIDOuput {
  boolean isStraight = false;
  double t,s;
  public DTOutput(boolean isStraightController) {
    isStraight = isStraightController;
  }

  public void set(double val) {
    if (isStraight)
      s = val;
    else
      t = val;
    drive(t+s,t-s);
  }
 ...
  straightController = new PIDController(whatever, new DTOutput(true));
..
Inelegant that we need to cache the values, but it gets the job done.
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 14:39.

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