mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +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
@@ -21,19 +21,14 @@ class Robot: public SampleRobot
|
||||
double motorSpeed;
|
||||
double currentPosition; //sensor voltage reading corresponding to current elevator position
|
||||
|
||||
AnalogInput *potentiometer;
|
||||
Victor *elevatorMotor;
|
||||
Joystick *joystick;
|
||||
AnalogInput potentiometer;
|
||||
Victor elevatorMotor;
|
||||
Joystick joystick;
|
||||
|
||||
public:
|
||||
Robot() :
|
||||
SampleRobot()
|
||||
{
|
||||
//make objects for the potentiometer, elevator motor controller, and joystick
|
||||
potentiometer = new AnalogInput(potChannel);
|
||||
elevatorMotor = new Victor(motorChannel);
|
||||
joystick = new Joystick(joystickChannel);
|
||||
}
|
||||
potentiometer(potChannel), elevatorMotor(motorChannel),
|
||||
joystick(joystickChannel) {}
|
||||
|
||||
/**
|
||||
* Runs during autonomous.
|
||||
@@ -57,7 +52,7 @@ public:
|
||||
currentSetpoint = setpoints[0]; //set to first setpoint
|
||||
|
||||
while (IsOperatorControl() && IsEnabled()) {
|
||||
buttonState = joystick->GetRawButton(buttonNumber); //check if button is pressed
|
||||
buttonState = joystick.GetRawButton(buttonNumber); //check if button is pressed
|
||||
|
||||
//if button has been pressed and released once
|
||||
if (buttonState && !prevButtonState) {
|
||||
@@ -66,9 +61,9 @@ public:
|
||||
}
|
||||
prevButtonState = buttonState; //record previous button state
|
||||
|
||||
currentPosition = potentiometer->GetAverageVoltage(); //get position value
|
||||
currentPosition = potentiometer.GetAverageVoltage(); //get position value
|
||||
motorSpeed = (currentPosition - currentSetpoint)*pGain; //convert position error to speed
|
||||
elevatorMotor->Set(motorSpeed); //drive elevator motor
|
||||
elevatorMotor.Set(motorSpeed); //drive elevator motor
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,4 +76,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
Reference in New Issue
Block a user