View Single Post
  #7   Spotlight this post!  
Unread 02-20-2013, 05:41 PM
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,182
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