View Single Post
  #5   Spotlight this post!  
Unread 02-03-2015, 13:51
JABot67 JABot67 is offline
Unregistered User
AKA: John Bottenberg
FRC #2930 (Sonic Squirrels)
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Redmond, WA
Posts: 328
JABot67 has a reputation beyond reputeJABot67 has a reputation beyond reputeJABot67 has a reputation beyond reputeJABot67 has a reputation beyond reputeJABot67 has a reputation beyond reputeJABot67 has a reputation beyond reputeJABot67 has a reputation beyond reputeJABot67 has a reputation beyond reputeJABot67 has a reputation beyond reputeJABot67 has a reputation beyond reputeJABot67 has a reputation beyond repute
Re: Driving Straight With Encoders

Quote:
Originally Posted by microbuns View Post
I was thinking about somehow trying to minimize the difference between the two sides' encoders, but I'm not exactly sure what/how to go about that. Do you just have some speed factor you add to one side and subtract to the other that scales off the difference of the two sides?
This is a good approach. I've seen the following work pretty well:

Code:
// Set up drivePID as a PIDController with a custom PIDSource that
// calculates the distance between the encoders and outputs the result
// in PIDGet(). The PIDOutput doesn't matter and should be a dummy.

// In AutonomousInit
drivePID.Enable();

// In AutonomousPeriodic
drivePID.SetSetpoint(0);
double movement = someConstant;
double rotation = drivePID.Get();

drive.ArcadeDrive(movement, rotation, /*SquaredInputs=*/ false);
This is where drivePID is an instance of the PIDController class. The PIDController class is pretty obnoxious in that its source and output have to be of the types PIDSource and PIDOutput, respectively. This means that you (the FRC team) have to create a class that inherits from PIDSource which calculates the difference between two encoders and returns that in the virtual function PIDGet().

Gotta say, sometimes the flow of information in C++ is really hard to follow.
__________________
John Bottenberg - University of Michigan '14 - Microsoft
FLL Team "Dark Matter": 2003-2005
Robofest Team "Dark Matter": 2005-2008
Team 67 Programmer: 2007-2010
Team 3322 Programming Mentor: 2012-2014
Team 2930 Engineering Mentor: 2015-????

Last edited by JABot67 : 02-03-2015 at 14:03. Reason: Fix up the code