View Single Post
  #11   Spotlight this post!  
Unread 02-03-2009, 07:48 AM
Mike Mahar Mike Mahar is offline
Registered User
FRC #0138
 
Join Date: Jan 2007
Location: Amherst, NH
Posts: 64
Mike Mahar will become famous soon enough
Re: WPILib PID controller object

Quote:
Originally Posted by sircedric4 View Post
************************************************** ****
In my .h file:
Jaguar *TurretPIDMotor;
AnalogChannel *TurretPIDPot;
PIDController *turretControl;

In my .cpp file:

In TeleopInit()
Jaguar TurretPIDMotor(3);
AnalogChannel TurretPIDPot(1);
PIDController turretControl(0.1,0.001,0.0, &TurretPIDPot, &TurretPIDMotor);
turretControl.Enable();

In TeleopPeriodic()
TurretGoto is being set from 0-5 using an equation and it is float defined
turretControl->SetSetPoint(TurretGoto);

************************************************** **
Change the lines in TeleopInit to:
Code:
turretPIDMotor = new Jaguar(3);
turretPIDPot = new AnalogChannel(1);
turretControl = new PIDController(0,1, 0.001, 0.0, turretPIDPot, turretPIDMotor);
turretControl->Enable();
Note that the ampersands (&) are no long on the 4th and 5th arguments to PIDController.

You were declaring a pointer to all of these classes and then allocating local versions in TeleopInit. The local version were being deleted when TeleopInit returned and the pointers you had in TeleopPeriodic were NULL and causing your program to crash.
Reply With Quote