mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Fixed examples to build/run with new WPILib versions.
Also added some references/smart pointers to a couple places that seemed convenient to the user. I haven't updated the constructors for RobotDrive() related examples, pending the results of gerrit change https://usfirst.collab.net/gerrit/#/c/960/ A few things that we are noticing: --It might be nice if ReturnPIDInput() didn't have to be const; when people try to override it, they have to remember to put the const in and if they don't, then the compiler error isn't the most obvious (especially since this is a change). This would also apply to PIDGet() in the PIDSource interface. --SendableChooser still takes raw pointers. This could lead to an issue I had to debug briefly where you accidentally call GetSelected() on autoChooser and put the resulting raw pointer into a unique_ptr, which destroys the pointer when it goes out of scope. Specifically, I was testing the PacGoat example and I ended up with a situation where if auto mode was run once, it was fine, but if it was run twice, the selected command would have been destroyed by the unique_ptr. I believe that this just requires updating SendableChosser to take shared_ptr. --When the samples are compiled with -pedantic, it points out that START_ROBOT_CLASS macro expansion results in a redundant semicolon. Change-Id: Ib4c025a61263d0d2780d4253faa31713e15333a5
This commit is contained in:
committed by
Brad Miller (WPI)
parent
4f8c1dff2f
commit
e017f93f16
@@ -22,25 +22,20 @@ class Robot: public SampleRobot {
|
||||
//and dGain may cause dangerous, uncontrollable, or undesired behavior!
|
||||
const double pGain = -5.0, iGain = -0.02, dGain = -2.0; //these may need to be positive for a non-inverted motor
|
||||
|
||||
PIDController *pidController;
|
||||
AnalogInput *potentiometer;
|
||||
Victor *elevatorMotor;
|
||||
Joystick *joystick;
|
||||
AnalogInput potentiometer;
|
||||
Victor elevatorMotor;
|
||||
Joystick joystick;
|
||||
PIDController pidController;
|
||||
|
||||
public:
|
||||
Robot() :
|
||||
SampleRobot()
|
||||
{
|
||||
//make objects for potentiometer, the elevator motor controller, and the joystick
|
||||
potentiometer = new AnalogInput(potChannel);
|
||||
elevatorMotor = new Victor(motorChannel);
|
||||
joystick = new Joystick(joystickChannel);
|
||||
|
||||
potentiometer(potChannel), elevatorMotor(motorChannel), joystick(joystickChannel),
|
||||
//potentiometer (AnalogInput) and elevatorMotor (Victor) can be used as a
|
||||
//PIDSource and PIDOutput respectively
|
||||
pidController = new PIDController(pGain, iGain, dGain, potentiometer,
|
||||
elevatorMotor);
|
||||
}
|
||||
//PIDSource and PIDOutput respectively.
|
||||
//The PIDController has to take a pointer to the PIDSource and PIDOutput, so
|
||||
//you must call &potentiometer and &elevatorMotor to get their pointers.
|
||||
pidController(pGain, iGain, dGain, &potentiometer, &elevatorMotor) {}
|
||||
|
||||
/**
|
||||
* Runs during autonomous.
|
||||
@@ -54,20 +49,20 @@ public:
|
||||
* The elevator setpoint is selected by a joystick button.
|
||||
*/
|
||||
void OperatorControl() {
|
||||
pidController->SetInputRange(0, 5); //0 to 5V
|
||||
pidController->SetSetpoint(setPoints[0]); //set to first setpoint
|
||||
pidController.SetInputRange(0, 5); //0 to 5V
|
||||
pidController.SetSetpoint(setPoints[0]); //set to first setpoint
|
||||
|
||||
int index = 0;
|
||||
bool currentValue;
|
||||
bool previousValue = false;
|
||||
|
||||
while (IsOperatorControl() && IsEnabled()) {
|
||||
pidController->Enable(); //begin PID control
|
||||
pidController.Enable(); //begin PID control
|
||||
|
||||
//when the button is pressed once, the selected elevator setpoint is incremented
|
||||
currentValue = joystick->GetRawButton(buttonNumber);
|
||||
currentValue = joystick.GetRawButton(buttonNumber);
|
||||
if (currentValue && !previousValue) {
|
||||
pidController->SetSetpoint(setPoints[index]);
|
||||
pidController.SetSetpoint(setPoints[index]);
|
||||
index = (index + 1) % (sizeof(setPoints)/8); //index of elevator setpoint wraps around
|
||||
}
|
||||
previousValue = currentValue;
|
||||
@@ -82,4 +77,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
Reference in New Issue
Block a user