|
Re: PID output to a variable
Thanks mikets. That looks very helpful, but I don't know a whole lot of C++ and I'm not exactly sure about what I am supposed to do with that code that you gave me. Do I need to make a subclass? Do I put the code that controls the motors in the subclass?
So far what I have been trying is:
----------------------------------
class IterativeDemo : public IterativeRobot
{
RobotDrive *myRobot;
PIDEncoder *leftencoder;
PIDEncoder *rightencoder;
float leftAutoDrive;
float rightAutoDrive;
public:
myRobot = new RobotDrive(1, 3, 2, 4);
leftencoder = new PIDEncoder(7,8,true,Encoder::k4X);
leftencoder->SetDistancePerPulse(0.04318); //inches
leftencoder->Start();
rightencoder = new PIDEncoder(9,10,true,Encoder::k4X);
rightencoder->SetDistancePerPulse(0.04318); //inches
rightencoder->Start();
leftAutoControl = new PIDController(0.1, 0.01, 0.001, leftencoder, bogusLeft);
rightAutoControl = new PIDController(0.1, 0.01, 0.001, rightencoder, bogusRight);
}
void AutonomousInit(void) {
auto_periodic_loops = 0; // Reset the loop counter for autonomous mode
disabled_periodic_loops = 0;
tele_periodic_loops = 0;
leftAutoControl->Enable();
rightAutoControl->Enable();
//Initialization
LoopsPerSec = 50;
}
void AutonomousPeriodic(void) {
// feed the user watchdog at every period when in autonomous
GetWatchdog().Feed();
auto_periodic_loops++;
dash_periodic_loops++;
leftAutoControl->SetSetpoint(18);
rightAutoControl->SetSetpoint(18);
leftAutoDrive = bogusLeft;
rightAutoDrive = bogusRight;
myRobot->TankDrive(rightAutoDrive, leftAutoDrive); // drive with tank style
}
---------------------------
The error is in the "leftAutoDrive = bogusLeft" and "rightAutoDrive = bogusRight" parts.
Last edited by prometheus : 26-01-2011 at 16:23.
Reason: Added Code
|