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
@@ -9,9 +9,9 @@
|
||||
* this system. Use IterativeRobot or Command-Based instead if you're new.
|
||||
*/
|
||||
class Robot: public SampleRobot {
|
||||
Joystick *joystick;
|
||||
RobotDrive *myRobot;
|
||||
Gyro *gyro;
|
||||
Joystick joystick;
|
||||
RobotDrive myRobot;
|
||||
Gyro gyro;
|
||||
|
||||
//channels for motors
|
||||
const int leftMotorChannel = 1;
|
||||
@@ -27,17 +27,14 @@ class Robot: public SampleRobot {
|
||||
|
||||
public:
|
||||
Robot() :
|
||||
SampleRobot() {
|
||||
//make objects for drive train, joystick, and gyro
|
||||
joystick = new Joystick(0);
|
||||
myRobot = new RobotDrive(new CANTalon(leftMotorChannel),
|
||||
new CANTalon(leftRearMotorChannel),
|
||||
new CANTalon(rightMotorChannel),
|
||||
new CANTalon(rightRearMotorChannel));
|
||||
myRobot->SetInvertedMotor(RobotDrive::kFrontLeftMotor, true);// invert the left side motors
|
||||
myRobot->SetInvertedMotor(RobotDrive::kRearLeftMotor, true);// you may need to change or remove this to match your robot
|
||||
|
||||
gyro = new Gyro(gyroChannel);
|
||||
joystick(0),
|
||||
// Create the robot using CANTalons; change as appropriate for different
|
||||
// motors (eg, Victor, Jaguar, Talon, CANJaguar, etc.).
|
||||
myRobot(new CANTalon(leftMotorChannel), new CANTalon(leftRearMotorChannel),
|
||||
new CANTalon(rightMotorChannel), new CANTalon(rightRearMotorChannel)),
|
||||
gyro(gyroChannel) {
|
||||
myRobot.SetInvertedMotor(RobotDrive::kFrontLeftMotor, true);// invert the left side motors
|
||||
myRobot.SetInvertedMotor(RobotDrive::kRearLeftMotor, true);// you may need to change or remove this to match your robot
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,10 +48,10 @@ public:
|
||||
* Runs the motors with arcade steering.
|
||||
*/
|
||||
void OperatorControl() {
|
||||
gyro->SetSensitivity(voltsPerDegreePerSecond); //calibrate gyro to have the value equal to degrees
|
||||
gyro.SetSensitivity(voltsPerDegreePerSecond); //calibrate gyro to have the value equal to degrees
|
||||
while (IsOperatorControl() && IsEnabled()) {
|
||||
myRobot->MecanumDrive_Cartesian(joystick->GetX(), joystick->GetY(),
|
||||
joystick->GetZ(), gyro->GetAngle());
|
||||
myRobot.MecanumDrive_Cartesian(joystick.GetX(), joystick.GetY(),
|
||||
joystick.GetZ(), gyro.GetAngle());
|
||||
Wait(0.005); // wait 5ms to avoid hogging CPU cycles
|
||||
}
|
||||
}
|
||||
@@ -67,4 +64,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
Reference in New Issue
Block a user