diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/CommandBase.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/CommandBase.cpp index 528da2a4b6..ebf342bbcf 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/CommandBase.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/CommandBase.cpp @@ -3,10 +3,10 @@ #include "Commands/Scheduler.h" // Initialize a single static instance of all of your subsystems to NULL -ExampleSubsystem* CommandBase::examplesubsystem = NULL; -OI* CommandBase::oi = NULL; +std::unique_ptr CommandBase::examplesubsystem; +std::unique_ptr CommandBase::oi; -CommandBase::CommandBase(char const *name) : +CommandBase::CommandBase(const std::string &name) : Command(name) { } @@ -21,7 +21,7 @@ void CommandBase::init() { // Create a single static instance of all of your subsystems. The following // line should be repeated for each subsystem in the project. - examplesubsystem = new ExampleSubsystem(); + examplesubsystem.reset(new ExampleSubsystem()); - oi = new OI(); + oi.reset(new OI()); } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/CommandBase.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/CommandBase.h index b4492ee38e..d4900a3fe1 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/CommandBase.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/CommandBase.h @@ -15,12 +15,12 @@ class CommandBase: public Command { public: - CommandBase(char const *name); + CommandBase(const std::string &name); CommandBase(); static void init(); // Create a single static instance of all of your subsystems - static ExampleSubsystem *examplesubsystem; - static OI *oi; + static std::unique_ptr examplesubsystem; + static std::unique_ptr oi; }; #endif diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/PIDSubsystem.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/PIDSubsystem.cpp index 53647fc09f..d88641ff61 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/PIDSubsystem.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/PIDSubsystem.cpp @@ -12,11 +12,11 @@ $classname::$classname() : // Enable() - Enables the PID controller. } -double $classname::ReturnPIDInput() +double $classname::ReturnPIDInput() const { // Return your input value for the PID loop // e.g. a sensor, like a potentiometer: - // yourPot->SetAverageVoltage() / kYourMaxVoltage; + // yourPot->SetAverageVoltage() / kYourMaxVoltage; } void $classname::UsePIDOutput(double output) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/PIDSubsystem.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/PIDSubsystem.h index ffb573a3de..2e72a8d560 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/PIDSubsystem.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/PIDSubsystem.h @@ -8,7 +8,7 @@ class $classname: public PIDSubsystem { public: $classname(); - double ReturnPIDInput(); + double ReturnPIDInput() const; void UsePIDOutput(double output); void InitDefaultCommand(); }; diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/Robot.cpp index 471a9f3c32..d062e4c36c 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/command-based/Robot.cpp @@ -6,16 +6,14 @@ class Robot: public IterativeRobot { private: - Command *autonomousCommand; - LiveWindow *lw; + std::unique_ptr autonomousCommand; void RobotInit() { CommandBase::init(); - autonomousCommand = new ExampleCommand(); - lw = LiveWindow::GetInstance(); + autonomousCommand.reset(new ExampleCommand()); } - + /** * This function is called once each time the robot enters Disabled mode. * You can use it to reset any subsystem information you want to clear when @@ -24,7 +22,7 @@ private: void DisabledInit() { } - + void DisabledPeriodic() { Scheduler::GetInstance().Run(); @@ -44,7 +42,7 @@ private: void TeleopInit() { // This makes sure that the autonomous stops running when - // teleop starts running. If you want the autonomous to + // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. if (autonomousCommand != NULL) @@ -58,9 +56,9 @@ private: void TestPeriodic() { - lw->Run(); + LiveWindow::GetInstance().Run(); } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/2015Vision/Color_src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/2015Vision/Color_src/Robot.cpp index c32a8eadcc..45751e4c85 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/2015Vision/Color_src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/2015Vision/Color_src/Robot.cpp @@ -233,5 +233,5 @@ public: } }; -START_ROBOT_CLASS(VisionColor2015Sample); +START_ROBOT_CLASS(VisionColor2015Sample) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/2015Vision/Retro_src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/2015Vision/Retro_src/Robot.cpp index 04310a35bf..00642a109f 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/2015Vision/Retro_src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/2015Vision/Retro_src/Robot.cpp @@ -207,4 +207,4 @@ public: } }; -START_ROBOT_CLASS(VisionRetro2015Sample); +START_ROBOT_CLASS(VisionRetro2015Sample) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/ArcadeDrive/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/ArcadeDrive/src/Robot.cpp index 1ac2827868..cb46a8f987 100755 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/ArcadeDrive/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/ArcadeDrive/src/Robot.cpp @@ -37,4 +37,4 @@ public: }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/AxisCameraSample/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/AxisCameraSample/src/Robot.cpp index a321283789..408859c58e 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/AxisCameraSample/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/AxisCameraSample/src/Robot.cpp @@ -9,7 +9,7 @@ class AxisCameraSample : public SampleRobot IMAQdxSession session; Image *frame; IMAQdxError imaqError; - AxisCamera *camera; + std::unique_ptr camera; public: void RobotInit() override { @@ -18,7 +18,7 @@ public: // open the camera at the IP address assigned. This is the IP address that the camera // can be accessed through the web interface. - camera = new AxisCamera("10.1.91.103"); + camera.reset(new AxisCamera("axis-camera.local")); } void OperatorControl() override { @@ -33,5 +33,5 @@ public: } }; -START_ROBOT_CLASS(AxisCameraSample); +START_ROBOT_CLASS(AxisCameraSample) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANPDP/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANPDP/src/Robot.cpp index 2477ff3cda..7376310a25 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANPDP/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANPDP/src/Robot.cpp @@ -44,4 +44,4 @@ public: }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANTalon/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANTalon/src/Robot.cpp index 2794e7beef..4bd8a85a09 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANTalon/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANTalon/src/Robot.cpp @@ -35,4 +35,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANTalonPID/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANTalonPID/src/Robot.cpp index 837f392764..3831cdefcf 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANTalonPID/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/CANTalonPID/src/Robot.cpp @@ -60,4 +60,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Encoder/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Encoder/src/Robot.cpp index 27f3ef86f6..57797b251a 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Encoder/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Encoder/src/Robot.cpp @@ -79,4 +79,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/CloseClaw.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/CloseClaw.cpp index 8e91eaa47d..9b4262fc00 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/CloseClaw.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/CloseClaw.cpp @@ -2,7 +2,7 @@ #include "Robot.h" CloseClaw::CloseClaw() : Command("CloseClaw") { - Requires(Robot::claw); + Requires(Robot::claw.get()); } // Called just before this Command runs the first time diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/DriveStraight.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/DriveStraight.cpp index fd63c70bf4..b2ae54e911 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/DriveStraight.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/DriveStraight.cpp @@ -2,7 +2,7 @@ #include "Robot.h" DriveStraight::DriveStraight(double distance) { - Requires(Robot::drivetrain); + Requires(Robot::drivetrain.get()); pid = new PIDController(4, 0, 0, new DriveStraightPIDSource(), new DriveStraightPIDOutput()); pid->SetAbsoluteTolerance(0.01); @@ -40,7 +40,7 @@ void DriveStraight::Interrupted() { DriveStraightPIDSource::~DriveStraightPIDSource() {} -double DriveStraightPIDSource::PIDGet() { +double DriveStraightPIDSource::PIDGet() const { return Robot::drivetrain->GetDistance(); } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/DriveStraight.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/DriveStraight.h index 50cd0b8e60..69166b00ae 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/DriveStraight.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/DriveStraight.h @@ -25,7 +25,7 @@ private: class DriveStraightPIDSource: public PIDSource { public: virtual ~DriveStraightPIDSource(); - double PIDGet(); + double PIDGet() const; }; class DriveStraightPIDOutput: public PIDOutput { diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/OpenClaw.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/OpenClaw.cpp index 4e9aec34ad..16ece43b9d 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/OpenClaw.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/OpenClaw.cpp @@ -2,7 +2,7 @@ #include "Robot.h" OpenClaw::OpenClaw() : Command("OpenClaw") { - Requires(Robot::claw); + Requires(Robot::claw.get()); SetTimeout(1); } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetDistanceToBox.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetDistanceToBox.cpp index 81c8bbdfcb..12e6588d5b 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetDistanceToBox.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetDistanceToBox.cpp @@ -2,7 +2,7 @@ #include "Robot.h" SetDistanceToBox::SetDistanceToBox(double distance) { - Requires(Robot::drivetrain); + Requires(Robot::drivetrain.get()); pid = new PIDController(-2, 0, 0, new SetDistanceToBoxPIDSource(), new SetDistanceToBoxPIDOutput()); pid->SetAbsoluteTolerance(0.01); @@ -40,7 +40,7 @@ void SetDistanceToBox::Interrupted() { SetDistanceToBoxPIDSource::~SetDistanceToBoxPIDSource() {} -double SetDistanceToBoxPIDSource::PIDGet() { +double SetDistanceToBoxPIDSource::PIDGet() const { return Robot::drivetrain->GetDistanceToObstacle(); } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetDistanceToBox.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetDistanceToBox.h index 1c284884db..3508a367a4 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetDistanceToBox.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetDistanceToBox.h @@ -25,7 +25,7 @@ private: class SetDistanceToBoxPIDSource: public PIDSource { public: virtual ~SetDistanceToBoxPIDSource(); - double PIDGet(); + double PIDGet() const; }; class SetDistanceToBoxPIDOutput: public PIDOutput { diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetElevatorSetpoint.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetElevatorSetpoint.cpp index 6603ddfacc..d8f475e7a4 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetElevatorSetpoint.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetElevatorSetpoint.cpp @@ -4,7 +4,7 @@ SetElevatorSetpoint::SetElevatorSetpoint(double setpoint) : Command("SetElevatorSetpoint") { this->setpoint = setpoint; - Requires(Robot::elevator); + Requires(Robot::elevator.get()); } // Called just before this Command runs the first time diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetWristSetpoint.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetWristSetpoint.cpp index 16b231b02a..9648d33999 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetWristSetpoint.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/SetWristSetpoint.cpp @@ -3,7 +3,7 @@ SetWristSetpoint::SetWristSetpoint(double setpoint) : Command("SetWristSetpoint") { this->setpoint = setpoint; - Requires(Robot::wrist); + Requires(Robot::wrist.get()); } // Called just before this Command runs the first time diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/TankDriveWithJoystick.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/TankDriveWithJoystick.cpp index b7009eaf28..a3c9e817ee 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/TankDriveWithJoystick.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Commands/TankDriveWithJoystick.cpp @@ -2,7 +2,7 @@ #include "Robot.h" TankDriveWithJoystick::TankDriveWithJoystick() : Command("TankDriveWithJoystick") { - Requires(Robot::drivetrain); + Requires(Robot::drivetrain.get()); } // Called just before this Command runs the first time diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Robot.cpp index b225c29782..866ac156f9 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Robot.cpp @@ -1,34 +1,30 @@ #include "Robot.h" -#include "Commands/Autonomous.h" -DriveTrain* Robot::drivetrain = NULL; -Elevator* Robot::elevator = NULL; -Wrist* Robot::wrist = NULL; -Claw* Robot::claw = NULL; +std::shared_ptr Robot::drivetrain; +std::shared_ptr Robot::elevator; +std::shared_ptr Robot::wrist; +std::shared_ptr Robot::claw; -OI* Robot::oi = NULL; +std::unique_ptr Robot::oi; void Robot::RobotInit() { - drivetrain = new DriveTrain(); - elevator = new Elevator(); - wrist = new Wrist(); - claw = new Claw(); + drivetrain.reset(new DriveTrain()); + elevator.reset(new Elevator()); + wrist.reset(new Wrist()); + claw.reset(new Claw()); - oi = new OI(); + oi.reset(new OI()); - autonomousCommand = new Autonomous(); - lw = LiveWindow::GetInstance(); - - // Show what command your subsystem is running on the SmartDashboard - SmartDashboard::PutData(drivetrain); - SmartDashboard::PutData(elevator); - SmartDashboard::PutData(wrist); - SmartDashboard::PutData(claw); + // Show what command your subsystem is running on the SmartDashboard + SmartDashboard::PutData(drivetrain.get()); + SmartDashboard::PutData(elevator.get()); + SmartDashboard::PutData(wrist.get()); + SmartDashboard::PutData(claw.get()); } void Robot::AutonomousInit() { - autonomousCommand->Start(); + autonomousCommand.Start(); std::cout << "Starting Auto" << std::endl; } @@ -41,7 +37,7 @@ void Robot::TeleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - autonomousCommand->Cancel(); + autonomousCommand.Cancel(); std::cout << "Starting Teleop" << std::endl; } @@ -50,7 +46,7 @@ void Robot::TeleopPeriodic() { } void Robot::TestPeriodic() { - lw->Run(); + lw.Run(); } -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Robot.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Robot.h index 49d996c576..45f88bea18 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Robot.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Robot.h @@ -10,6 +10,7 @@ #include "WPILib.h" #include "Commands/Command.h" +#include "Commands/Autonomous.h" #include "Subsystems/DriveTrain.h" #include "Subsystems/Elevator.h" @@ -19,15 +20,15 @@ class Robot: public IterativeRobot { public: - static DriveTrain* drivetrain; - static Elevator* elevator; - static Wrist* wrist; - static Claw* claw; - static OI* oi; + static std::shared_ptr drivetrain; + static std::shared_ptr elevator; + static std::shared_ptr wrist; + static std::shared_ptr claw; + static std::unique_ptr oi; private: - Command *autonomousCommand; - LiveWindow *lw; + Autonomous autonomousCommand; + LiveWindow &lw = LiveWindow::GetInstance(); void RobotInit(); void AutonomousInit(); diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/DriveTrain.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/DriveTrain.cpp index ce6254c47a..d3578f7d5a 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/DriveTrain.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/DriveTrain.cpp @@ -1,16 +1,12 @@ #include "DriveTrain.h" #include "Commands/TankDriveWithJoystick.h" -DriveTrain::DriveTrain() : Subsystem("DriveTrain") { - front_left_motor = new Talon(1); - back_left_motor = new Talon(2); - front_right_motor = new Talon(3); - back_right_motor = new Talon(4); - drive = new RobotDrive(front_left_motor, back_left_motor, - front_right_motor, back_right_motor); - - left_encoder = new Encoder(1, 2); - right_encoder = new Encoder(3, 4); +DriveTrain::DriveTrain() + : Subsystem("DriveTrain"), left_encoder(new Encoder(1, 2)), + right_encoder(new Encoder(3, 4)), rangefinder(new AnalogInput(6)), + gyro(new Gyro(1)) { + drive = new RobotDrive(new Talon(1), new Talon(2), + new Talon(3), new Talon(4)); // Encoders may measure differently in the real world and in // simulation. In this example the robot moves 0.042 barleycorns @@ -26,18 +22,15 @@ DriveTrain::DriveTrain() : Subsystem("DriveTrain") { right_encoder->SetDistancePerPulse((double) (4.0/12.0*M_PI) / 360.0); #endif - rangefinder = new AnalogInput(6); - gyro = new Gyro(1); - // Let's show everything on the LiveWindow - // TODO: LiveWindow::GetInstance()->AddActuator("Drive Train", "Front_Left Motor", (Talon) front_left_motor); - // TODO: LiveWindow::GetInstance()->AddActuator("Drive Train", "Back Left Motor", (Talon) back_left_motor); - // TODO: LiveWindow::GetInstance()->AddActuator("Drive Train", "Front Right Motor", (Talon) front_right_motor); - // TODO: LiveWindow::GetInstance()->AddActuator("Drive Train", "Back Right Motor", (Talon) back_right_motor); - LiveWindow::GetInstance()->AddSensor("Drive Train", "Left Encoder", left_encoder); - LiveWindow::GetInstance()->AddSensor("Drive Train", "Right Encoder", right_encoder); - LiveWindow::GetInstance()->AddSensor("Drive Train", "Rangefinder", rangefinder); - LiveWindow::GetInstance()->AddSensor("Drive Train", "Gyro", gyro); + // TODO: LiveWindow::GetInstance().AddActuator("Drive Train", "Front_Left Motor", (Talon) front_left_motor); + // TODO: LiveWindow::GetInstance().AddActuator("Drive Train", "Back Left Motor", (Talon) back_left_motor); + // TODO: LiveWindow::GetInstance().AddActuator("Drive Train", "Front Right Motor", (Talon) front_right_motor); + // TODO: LiveWindow::GetInstance().AddActuator("Drive Train", "Back Right Motor", (Talon) back_right_motor); + LiveWindow::GetInstance().AddSensor("Drive Train", "Left Encoder", left_encoder); + LiveWindow::GetInstance().AddSensor("Drive Train", "Right Encoder", right_encoder); + LiveWindow::GetInstance().AddSensor("Drive Train", "Rangefinder", rangefinder); + LiveWindow::GetInstance().AddSensor("Drive Train", "Gyro", gyro); } /** diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/DriveTrain.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/DriveTrain.h index 19aae19138..1f30b1da76 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/DriveTrain.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/DriveTrain.h @@ -10,12 +10,10 @@ */ class DriveTrain : public Subsystem { private: - SpeedController *front_left_motor, *back_left_motor, - *front_right_motor, *back_right_motor; RobotDrive* drive; - Encoder *left_encoder, *right_encoder; - AnalogInput* rangefinder; - Gyro* gyro; + std::shared_ptr left_encoder, right_encoder; + std::shared_ptr rangefinder; + std::shared_ptr gyro; public: DriveTrain(); diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Elevator.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Elevator.cpp index 02c558ffa5..5e8ad83586 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Elevator.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Elevator.cpp @@ -18,16 +18,16 @@ Elevator::Elevator() : PIDSubsystem("Elevator", kP_real, kI_real, 0.0) { #endif // Let's show everything on the LiveWindow - // TODO: LiveWindow::GetInstance()->AddActuator("Elevator", "Motor", (Victor) motor); - // TODO: LiveWindow::GetInstance()->AddSensor("Elevator", "Pot", (AnalogPotentiometer) pot); - LiveWindow::GetInstance()->AddActuator("Elevator", "PID", GetPIDController()); + // TODO: LiveWindow::GetInstance().AddActuator("Elevator", "Motor", (Victor) motor); + // TODO: LiveWindow::GetInstance().AddSensor("Elevator", "Pot", (AnalogPotentiometer) pot); + LiveWindow::GetInstance().AddActuator("Elevator", "PID", GetPIDController()); } void Elevator::Log() { // TODO: SmartDashboard::PutData("Wrist Pot", (AnalogPotentiometer) pot); } -double Elevator::ReturnPIDInput() { +double Elevator::ReturnPIDInput() const { return pot->Get(); } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Elevator.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Elevator.h index d079de03b5..a428d5510c 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Elevator.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Elevator.h @@ -29,7 +29,7 @@ public: * Use the potentiometer as the PID sensor. This method is automatically * called by the subsystem. */ - double ReturnPIDInput(); + double ReturnPIDInput() const; /** diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Wrist.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Wrist.cpp index f09fdbb790..5ab9ff98bd 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Wrist.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Wrist.cpp @@ -18,16 +18,16 @@ Wrist::Wrist() : PIDSubsystem("Wrist", kP_real, 0.0, 0.0) { #endif // Let's show everything on the LiveWindow - // TODO: LiveWindow::GetInstance()->AddActuator("Wrist", "Motor", (Victor) motor); - // TODO: LiveWindow::GetInstance()->AddSensor("Wrist", "Pot", (AnalogPotentiometer) pot); - LiveWindow::GetInstance()->AddActuator("Wrist", "PID", GetPIDController()); + // TODO: LiveWindow::GetInstance().AddActuator("Wrist", "Motor", (Victor) motor); + // TODO: LiveWindow::GetInstance().AddSensor("Wrist", "Pot", (AnalogPotentiometer) pot); + LiveWindow::GetInstance().AddActuator("Wrist", "PID", GetPIDController()); } void Wrist::Log() { // TODO: SmartDashboard::PutData("Wrist Angle", (AnalogPotentiometer) pot); } -double Wrist::ReturnPIDInput() { +double Wrist::ReturnPIDInput() const { return pot->Get(); } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Wrist.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Wrist.h index e80364e7cd..f0f7593b37 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Wrist.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GearsBot/src/Subsystems/Wrist.h @@ -28,7 +28,7 @@ public: * Use the potentiometer as the PID sensor. This method is automatically * called by the subsystem. */ - double ReturnPIDInput(); + double ReturnPIDInput() const; /** * Use the motor as the PID output. This method is automatically called by diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GettingStarted/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GettingStarted/src/Robot.cpp index 478a43ac3c..67303df9b9 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GettingStarted/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GettingStarted/src/Robot.cpp @@ -5,25 +5,20 @@ class Robot: public IterativeRobot RobotDrive myRobot; // robot drive system Joystick stick; // only joystick - LiveWindow *lw; + LiveWindow &lw; int autoLoopCounter; public: Robot() : myRobot(0, 1), // these must be initialized in the same order stick(0), // as they are declared above. - lw(NULL), + lw(LiveWindow::GetInstance()), autoLoopCounter(0) { myRobot.SetExpiration(0.1); } private: - void RobotInit() - { - lw = LiveWindow::GetInstance(); - } - void AutonomousInit() { autoLoopCounter = 0; @@ -52,8 +47,8 @@ private: void TestPeriodic() { - lw->Run(); + lw.Run(); } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Gyro/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Gyro/src/Robot.cpp index 3c5a6d733a..aac6bbbf4b 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Gyro/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Gyro/src/Robot.cpp @@ -26,22 +26,17 @@ class Robot: public SampleRobot { //gyro value of 360 is set to correspond to one full revolution const double voltsPerDegreePerSecond = .0128; - RobotDrive *myRobot; - Gyro *gyro; - Joystick *joystick; + RobotDrive myRobot; + Gyro gyro; + Joystick joystick; public: Robot() : - SampleRobot() - { - //make objects for the drive train, gyro, and joystick - myRobot = new RobotDrive(new CANTalon(leftMotorChannel), - new CANTalon(leftRearMotorChannel), - new CANTalon(rightMotorChannel), - new CANTalon(rightRearMotorChannel)); - gyro = new Gyro(gyroChannel); - joystick = new Joystick(joystickChannel); - } + // Create the drivetrain from 4 CAN Talon SRXs. + myRobot(new CANTalon(leftMotorChannel), new CANTalon(leftRearMotorChannel), + new CANTalon(rightMotorChannel), new CANTalon(rightRearMotorChannel)), + // Assign the gyro and joystick channels. + gyro(gyroChannel), joystick(joystickChannel) {} /** * Runs during autonomous. @@ -59,17 +54,17 @@ public: void OperatorControl() { double turningValue; - gyro->SetSensitivity(voltsPerDegreePerSecond); //calibrates gyro values to equal degrees + gyro.SetSensitivity(voltsPerDegreePerSecond); //calibrates gyro values to equal degrees while (IsOperatorControl() && IsEnabled()) { - turningValue = (angleSetpoint - gyro->GetAngle()) * pGain; - if (joystick->GetY() <= 0) { + turningValue = (angleSetpoint - gyro.GetAngle()) * pGain; + if (joystick.GetY() <= 0) { //forwards - myRobot->Drive(joystick->GetY(), turningValue); + myRobot.Drive(joystick.GetY(), turningValue); } else { //backwards - myRobot->Drive(joystick->GetY(), -turningValue); + myRobot.Drive(joystick.GetY(), -turningValue); } } } @@ -83,4 +78,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GyroMecanum/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GyroMecanum/src/Robot.cpp index f2c4e255fe..02935fcc6e 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GyroMecanum/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/GyroMecanum/src/Robot.cpp @@ -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) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/Robot.cpp index fc874a1031..f3458a959c 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/IntermediateVision/src/Robot.cpp @@ -46,5 +46,5 @@ public: } }; -START_ROBOT_CLASS(IntermediateVisionRobot); +START_ROBOT_CLASS(IntermediateVisionRobot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MecanumDrive/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MecanumDrive/src/Robot.cpp index aa3522062b..67635d28a8 100755 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MecanumDrive/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MecanumDrive/src/Robot.cpp @@ -46,4 +46,4 @@ public: }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MotorControl/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MotorControl/src/Robot.cpp index 567e71faa6..338ba34e10 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MotorControl/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MotorControl/src/Robot.cpp @@ -41,4 +41,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MotorControlEncoder/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MotorControlEncoder/src/Robot.cpp index e9f0751837..f004578498 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MotorControlEncoder/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/MotorControlEncoder/src/Robot.cpp @@ -52,4 +52,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/CloseClaw.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/CloseClaw.cpp index 580a1ab8a3..116b3a077e 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/CloseClaw.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/CloseClaw.cpp @@ -3,7 +3,7 @@ #include "Robot.h" CloseClaw::CloseClaw() { - Requires(Robot::collector); + Requires(Robot::collector.get()); } // Called just before this Command runs the first time diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/DriveForward.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/DriveForward.cpp index 7f05406aa2..b945c4a0cc 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/DriveForward.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/DriveForward.cpp @@ -3,7 +3,7 @@ #include "Robot.h" void DriveForward::init(double dist, double maxSpeed) { - Requires(Robot::drivetrain); + Requires(Robot::drivetrain.get()); distance = dist; driveForwardSpeed = maxSpeed; error = 0; diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/DriveWithJoystick.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/DriveWithJoystick.cpp index da6713a0f0..c244d7d617 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/DriveWithJoystick.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/DriveWithJoystick.cpp @@ -3,7 +3,7 @@ #include "Robot.h" DriveWithJoystick::DriveWithJoystick() { - Requires(Robot::drivetrain); + Requires(Robot::drivetrain.get()); } // Called just before this Command runs the first time diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/ExtendShooter.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/ExtendShooter.cpp index 21d907f6f1..e1acabc1df 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/ExtendShooter.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/ExtendShooter.cpp @@ -3,7 +3,7 @@ #include "Robot.h" ExtendShooter::ExtendShooter() { - Requires(Robot::shooter); + Requires(Robot::shooter.get()); SetTimeout(1); } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/OpenClaw.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/OpenClaw.cpp index abd2a95809..74b042db31 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/OpenClaw.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/OpenClaw.cpp @@ -3,7 +3,7 @@ #include "Robot.h" OpenClaw::OpenClaw() { - Requires(Robot::collector); + Requires(Robot::collector.get()); } // Called just before this Command runs the first time diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/SetCollectionSpeed.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/SetCollectionSpeed.cpp index 46b0f17372..b50154d2db 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/SetCollectionSpeed.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/SetCollectionSpeed.cpp @@ -3,7 +3,7 @@ #include "Robot.h" SetCollectionSpeed::SetCollectionSpeed(double speed) { - Requires(Robot::collector); + Requires(Robot::collector.get()); this->speed = speed; } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/SetPivotSetpoint.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/SetPivotSetpoint.cpp index 2d0541bd5e..0dad144e52 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/SetPivotSetpoint.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/SetPivotSetpoint.cpp @@ -4,7 +4,7 @@ SetPivotSetpoint::SetPivotSetpoint(double setpoint) { this->setpoint = setpoint; - Requires(Robot::pivot); + Requires(Robot::pivot.get()); } // Called just before this Command runs the first time diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/WaitForBall.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/WaitForBall.cpp index 12d862f11d..8788692a14 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/WaitForBall.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/WaitForBall.cpp @@ -3,7 +3,7 @@ #include "Robot.h" WaitForBall::WaitForBall() { - Requires(Robot::collector); + Requires(Robot::collector.get()); } // Called just before this Command runs the first time diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/WaitForPressure.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/WaitForPressure.cpp index 1e61a559e2..1a64be631d 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/WaitForPressure.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Commands/WaitForPressure.cpp @@ -4,7 +4,7 @@ WaitForPressure::WaitForPressure() { - Requires(Robot::pneumatics); + Requires(Robot::pneumatics.get()); } // Called just before this Command runs the first time diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/OI.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/OI.cpp index 93954a1326..249cb34224 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/OI.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/OI.cpp @@ -9,21 +9,21 @@ #include "Commands/DriveForward.h" #include "Commands/SetCollectionSpeed.h" -OI::OI() { - joystick = new Joystick(0); +OI::OI() + : joystick(0), + L1(&joystick, 11), + L2(&joystick, 9), + R1(&joystick, 12), + R2(&joystick, 10), + sticks(&joystick, 2, 3) { - R1 = new JoystickButton(joystick, 12); - R1->WhenPressed(new LowGoal()); - R2 = new JoystickButton(joystick, 10); - R2->WhenPressed(new Collect()); + R1.WhenPressed(new LowGoal()); + R2.WhenPressed(new Collect()); - L1 = new JoystickButton(joystick, 11); - L1->WhenPressed(new SetPivotSetpoint(Pivot::SHOOT)); - L2 = new JoystickButton(joystick, 9); - L2->WhenPressed(new SetPivotSetpoint(Pivot::SHOOT_NEAR)); + L1.WhenPressed(new SetPivotSetpoint(Pivot::SHOOT)); + L2.WhenPressed(new SetPivotSetpoint(Pivot::SHOOT_NEAR)); - sticks = new DoubleButton(joystick, 2, 3); - sticks->WhenActive(new Shoot()); + sticks.WhenActive(new Shoot()); // SmartDashboard Buttons @@ -36,5 +36,5 @@ OI::OI() { Joystick* OI::GetJoystick() { - return joystick; + return &joystick; } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/OI.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/OI.h index 83123e5cab..fdee45285c 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/OI.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/OI.h @@ -6,9 +6,9 @@ class OI { private: - Joystick* joystick; - JoystickButton *L1, *L2, *R1, *R2; - DoubleButton* sticks; + Joystick joystick; + JoystickButton L1, L2, R1, R2; + DoubleButton sticks; public: OI(); Joystick* GetJoystick(); diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Robot.cpp index 137480071d..c59cbf7140 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Robot.cpp @@ -1,46 +1,40 @@ #include "Robot.h" -#include "Commands/DriveAndShootAutonomous.h" -#include "Commands/DriveForward.h" -DriveTrain* Robot::drivetrain = NULL; -Pivot* Robot::pivot = NULL; -Collector* Robot::collector = NULL; -Shooter* Robot::shooter = NULL; -Pneumatics* Robot::pneumatics = NULL; +std::shared_ptr Robot::drivetrain; +std::shared_ptr Robot::pivot; +std::shared_ptr Robot::collector; +std::shared_ptr Robot::shooter; +std::shared_ptr Robot::pneumatics; -OI* Robot::oi = NULL; +std::unique_ptr Robot::oi; void Robot::RobotInit() { - drivetrain = new DriveTrain(); - pivot = new Pivot(); - collector = new Collector(); - shooter = new Shooter(); - pneumatics = new Pneumatics(); + drivetrain.reset(new DriveTrain()); + pivot.reset(new Pivot()); + collector.reset(new Collector()); + shooter.reset(new Shooter()); + pneumatics.reset(new Pneumatics()); - // Show what command your subsystem is running on the SmartDashboard - SmartDashboard::PutData(drivetrain); - SmartDashboard::PutData(pivot); - SmartDashboard::PutData(collector); - SmartDashboard::PutData(shooter); - SmartDashboard::PutData(pneumatics); + oi.reset(new OI()); - oi = new OI(); - - autonomousCommand = new DriveAndShootAutonomous(); - lw = LiveWindow::GetInstance(); + // Show what command your subsystem is running on the SmartDashboard + SmartDashboard::PutData(drivetrain.get()); + SmartDashboard::PutData(pivot.get()); + SmartDashboard::PutData(collector.get()); + SmartDashboard::PutData(shooter.get()); + SmartDashboard::PutData(pneumatics.get()); // instantiate the command used for the autonomous period - autoChooser = new SendableChooser(); - autoChooser->AddDefault("Drive and Shoot", new DriveAndShootAutonomous()); - autoChooser->AddObject("Drive Forward", new DriveForward()); - SmartDashboard::PutData("Auto Mode", autoChooser); + autoChooser.AddDefault("Drive and Shoot", driveAndShootAuto.get()); + autoChooser.AddObject("Drive Forward", driveForwardAuto.get()); + SmartDashboard::PutData("Auto Mode", &autoChooser); pneumatics->Start(); // Pressurize the pneumatics. } void Robot::AutonomousInit() { - autonomousCommand = (Command*) autoChooser->GetSelected(); + autonomousCommand = (Command *)autoChooser.GetSelected(); autonomousCommand->Start(); } @@ -54,7 +48,7 @@ void Robot::TeleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (autonomousCommand != NULL) { + if (autonomousCommand != nullptr) { autonomousCommand->Cancel(); } std::cout << "Starting Teleop" << std::endl; @@ -66,7 +60,7 @@ void Robot::TeleopPeriodic() { } void Robot::TestPeriodic() { - lw->Run(); + LiveWindow::GetInstance().Run(); } void Robot::DisabledInit() { @@ -87,4 +81,4 @@ void Robot::Log() { SmartDashboard::PutNumber("Right Distance", drivetrain->GetRightEncoder()->GetDistance()); } -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Robot.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Robot.h index 4bc7ae60a5..d4437cdef0 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Robot.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Robot.h @@ -11,6 +11,8 @@ #include "WPILib.h" #include "Commands/Command.h" +#include "Commands/DriveAndShootAutonomous.h" +#include "Commands/DriveForward.h" #include "Subsystems/DriveTrain.h" #include "Subsystems/Pivot.h" #include "Subsystems/Collector.h" @@ -20,17 +22,18 @@ class Robot: public IterativeRobot { public: - static DriveTrain* drivetrain; - static Pivot* pivot; - static Collector* collector; - static Shooter* shooter; - static Pneumatics* pneumatics; - static OI* oi; + static std::shared_ptr drivetrain; + static std::shared_ptr pivot; + static std::shared_ptr collector; + static std::shared_ptr shooter; + static std::shared_ptr pneumatics; + static std::unique_ptr oi; private: - Command *autonomousCommand; - LiveWindow *lw; - SendableChooser* autoChooser; + Command* autonomousCommand = nullptr; + std::unique_ptr driveAndShootAuto{new DriveAndShootAutonomous()}, + driveForwardAuto{new DriveForward()}; + SendableChooser autoChooser; void RobotInit(); void AutonomousInit(); @@ -44,5 +47,4 @@ private: void Log(); }; - #endif /* ROBOT_H_ */ diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Collector.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Collector.cpp index 245090ff23..24a060f4f9 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Collector.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Collector.cpp @@ -1,19 +1,19 @@ #include "Collector.h" Collector::Collector() : - Subsystem("Collector") + Subsystem("Collector"), + // Configure devices + rollerMotor(new Victor(6)), + ballDetector(new DigitalInput(10)), + piston(new Solenoid(1)), + openDetector(new DigitalInput(6)) { - // Configure devices - rollerMotor = new Victor(6); - ballDetector = new DigitalInput(10); - openDetector = new DigitalInput(6); - piston = new Solenoid(1); // Put everything to the LiveWindow for testing. // XXX: LiveWindow::GetInstance()->AddActuator("Collector", "Roller Motor", (Victor) rollerMotor); - LiveWindow::GetInstance()->AddSensor("Collector", "Ball Detector", ballDetector); - LiveWindow::GetInstance()->AddSensor("Collector", "Claw Open Detector", openDetector); - LiveWindow::GetInstance()->AddActuator("Collector", "Piston", piston); + LiveWindow::GetInstance().AddSensor("Collector", "Ball Detector", ballDetector); + LiveWindow::GetInstance().AddSensor("Collector", "Claw Open Detector", openDetector); + LiveWindow::GetInstance().AddActuator("Collector", "Piston", piston); } bool Collector::HasBall() { diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Collector.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Collector.h index 8b0e4c0117..f727709d3d 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Collector.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Collector.h @@ -19,10 +19,10 @@ public: private: // Subsystem devices - SpeedController* rollerMotor; - DigitalInput* ballDetector; - Solenoid* piston; - DigitalInput* openDetector; + std::shared_ptr rollerMotor; + std::shared_ptr ballDetector; + std::shared_ptr piston; + std::shared_ptr openDetector; public: Collector(); diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/DriveTrain.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/DriveTrain.cpp index 5c8f092b24..7e1caf58f4 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/DriveTrain.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/DriveTrain.cpp @@ -3,13 +3,17 @@ #define _USE_MATH_DEFINES #include -DriveTrain::DriveTrain() : - Subsystem("DriveTrain") { - // Configure drive motors - frontLeftCIM = new Victor(1); - frontRightCIM = new Victor(2); - backLeftCIM = new Victor(3); - backRightCIM = new Victor(4); +DriveTrain::DriveTrain() + : Subsystem("DriveTrain"), + // Configure drive motors + frontLeftCIM(new Victor(1)), + frontRightCIM(new Victor(2)), + backLeftCIM(new Victor(3)), + backRightCIM(new Victor(4)), + drive(frontRightCIM, backLeftCIM, frontRightCIM, backRightCIM), + rightEncoder(new Encoder(1, 2, true, Encoder::k4X)), + leftEncoder(new Encoder(3, 4, false, Encoder::k4X)), + gyro(new Gyro(0)) { // XXX: LiveWindow::GetInstance()->AddActuator("DriveTrain", "Front Left CIM", (Victor) frontLeftCIM); // XXX: LiveWindow::GetInstance()->AddActuator("DriveTrain", "Front Right CIM", (Victor) frontRightCIM); // XXX: LiveWindow::GetInstance()->AddActuator("DriveTrain", "Back Left CIM", (Victor) backLeftCIM); @@ -17,19 +21,16 @@ DriveTrain::DriveTrain() : // Configure the RobotDrive to reflect the fact that all our motors are // wired backwards and our drivers sensitivity preferences. - drive = new RobotDrive(frontLeftCIM, backLeftCIM, frontRightCIM, backRightCIM); - drive->SetSafetyEnabled(true); - drive->SetExpiration(0.1); - drive->SetSensitivity(0.5); - drive->SetMaxOutput(1.0); - drive->SetInvertedMotor(RobotDrive::kFrontLeftMotor, true); - drive->SetInvertedMotor(RobotDrive::kRearLeftMotor, true); - drive->SetInvertedMotor(RobotDrive::kFrontRightMotor, true); - drive->SetInvertedMotor(RobotDrive::kRearRightMotor, true); + drive.SetSafetyEnabled(false); + drive.SetExpiration(0.1); + drive.SetSensitivity(0.5); + drive.SetMaxOutput(1.0); + drive.SetInvertedMotor(RobotDrive::kFrontLeftMotor, true); + drive.SetInvertedMotor(RobotDrive::kRearLeftMotor, true); + drive.SetInvertedMotor(RobotDrive::kFrontRightMotor, true); + drive.SetInvertedMotor(RobotDrive::kRearRightMotor, true); // Configure encoders - rightEncoder = new Encoder(1, 2, true, Encoder::k4X); - leftEncoder = new Encoder(3, 4, false, Encoder::k4X); rightEncoder->SetPIDSourceParameter(PIDSource::kDistance); leftEncoder->SetPIDSourceParameter(PIDSource::kDistance); @@ -43,15 +44,14 @@ DriveTrain::DriveTrain() : leftEncoder->SetDistancePerPulse((4.0/*in*/*M_PI)/(360.0*12.0/*in/ft*/)); #endif - LiveWindow::GetInstance()->AddSensor("DriveTrain", "Right Encoder", rightEncoder); - LiveWindow::GetInstance()->AddSensor("DriveTrain", "Left Encoder", leftEncoder); + LiveWindow::GetInstance().AddSensor("DriveTrain", "Right Encoder", rightEncoder); + LiveWindow::GetInstance().AddSensor("DriveTrain", "Left Encoder", leftEncoder); // Configure gyro - gyro = new Gyro(2); #ifdef REAL gyro->SetSensitivity(0.007); // TODO: Handle more gracefully? #endif - LiveWindow::GetInstance()->AddSensor("DriveTrain", "Gyro", gyro); + LiveWindow::GetInstance().AddSensor("DriveTrain", "Gyro", gyro); } void DriveTrain::InitDefaultCommand() { @@ -59,22 +59,22 @@ void DriveTrain::InitDefaultCommand() { } void DriveTrain::TankDrive(Joystick* joy) { - drive->TankDrive(joy->GetY(), joy->GetRawAxis(4)); + drive.TankDrive(joy->GetY(), joy->GetRawAxis(4)); } void DriveTrain::TankDrive(double leftAxis, double rightAxis) { - drive->TankDrive(leftAxis, rightAxis); + drive.TankDrive(leftAxis, rightAxis); } void DriveTrain::Stop() { - drive->TankDrive(0.0, 0.0); + drive.TankDrive(0.0, 0.0); } -Encoder* DriveTrain::GetLeftEncoder() { +std::shared_ptr DriveTrain::GetLeftEncoder() { return leftEncoder; } -Encoder* DriveTrain::GetRightEncoder() { +std::shared_ptr DriveTrain::GetRightEncoder() { return rightEncoder; } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/DriveTrain.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/DriveTrain.h index 7080c0f29b..842ccbae13 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/DriveTrain.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/DriveTrain.h @@ -12,11 +12,11 @@ class DriveTrain: public Subsystem { private: // Subsystem devices - SpeedController *frontLeftCIM, *frontRightCIM; - SpeedController *backLeftCIM, *backRightCIM; - RobotDrive* drive; - Encoder *rightEncoder, *leftEncoder; - Gyro* gyro; + std::shared_ptr frontLeftCIM, frontRightCIM; + std::shared_ptr backLeftCIM, backRightCIM; + RobotDrive drive; + std::shared_ptr rightEncoder, leftEncoder; + std::shared_ptr gyro; public: DriveTrain(); @@ -46,12 +46,12 @@ public: /** * @return The encoder getting the distance and speed of left side of the drivetrain. */ - Encoder* GetLeftEncoder(); + std::shared_ptr GetLeftEncoder(); /** * @return The encoder getting the distance and speed of right side of the drivetrain. */ - Encoder* GetRightEncoder(); + std::shared_ptr GetRightEncoder(); /** * @return The current angle of the drivetrain. diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pivot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pivot.cpp index 6ab3353dd6..6b51da5bba 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pivot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pivot.cpp @@ -1,7 +1,15 @@ #include "Pivot.h" Pivot::Pivot() : - PIDSubsystem("Pivot", 7.0, 0.0, 8.0) + PIDSubsystem("Pivot", 7.0, 0.0, 8.0), + // Sensors for measuring the position of the pivot. + upperLimitSwitch(new DigitalInput(13)), + lowerLimitSwitch(new DigitalInput(12)), + // 0 degrees is vertical facing up. + // Angle increases the more forward the pivot goes. + pot(new AnalogPotentiometer(1)), + // Motor to move the pivot. + motor(new Victor(5)) { SetAbsoluteTolerance(0.005); GetPIDController()->SetContinuous(false); @@ -11,28 +19,17 @@ Pivot::Pivot() : SetAbsoluteTolerance(5); #endif - // Motor to move the pivot. - motor = new Victor(5); - - // Sensors for measuring the position of the pivot. - upperLimitSwitch = new DigitalInput(13); - lowerLimitSwitch = new DigitalInput(12); - - // 0 degrees is vertical facing up. - // Angle increases the more forward the pivot goes. - pot = new AnalogPotentiometer(1); - // Put everything to the LiveWindow for testing. - LiveWindow::GetInstance()->AddSensor("Pivot", "Upper Limit Switch", upperLimitSwitch); - LiveWindow::GetInstance()->AddSensor("Pivot", "Lower Limit Switch", lowerLimitSwitch); - // XXX: LiveWindow::GetInstance()->AddSensor("Pivot", "Pot", (AnalogPotentiometer) pot); - // XXX: LiveWindow::GetInstance()->AddActuator("Pivot", "Motor", (Victor) motor); - LiveWindow::GetInstance()->AddActuator("Pivot", "PIDSubsystem Controller", GetPIDController()); + LiveWindow::GetInstance().AddSensor("Pivot", "Upper Limit Switch", upperLimitSwitch); + LiveWindow::GetInstance().AddSensor("Pivot", "Lower Limit Switch", lowerLimitSwitch); + // XXX: LiveWindow::GetInstance().AddSensor("Pivot", "Pot", (AnalogPotentiometer) pot); + // XXX: LiveWindow::GetInstance().AddActuator("Pivot", "Motor", (Victor) motor); + LiveWindow::GetInstance().AddActuator("Pivot", "PIDSubsystem Controller", GetPIDController()); } void InitDefaultCommand() {} -double Pivot::ReturnPIDInput() { +double Pivot::ReturnPIDInput() const { return pot->Get(); } diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pivot.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pivot.h index 086e7b7f83..4c5af09755 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pivot.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pivot.h @@ -19,10 +19,10 @@ public: private: // Subsystem devices - DigitalInput* upperLimitSwitch; - DigitalInput* lowerLimitSwitch; - Potentiometer* pot; - SpeedController* motor; + std::shared_ptr upperLimitSwitch; + std::shared_ptr lowerLimitSwitch; + std::shared_ptr pot; + std::shared_ptr motor; public: Pivot(); @@ -35,7 +35,7 @@ public: /** * @return The angle read in by the potentiometer */ - double ReturnPIDInput(); + double ReturnPIDInput() const; /** * Set the motor speed based off of the PID output diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pneumatics.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pneumatics.cpp index 3177d4f9c5..d224c6aee5 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pneumatics.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pneumatics.cpp @@ -1,14 +1,14 @@ #include "Pneumatics.h" Pneumatics::Pneumatics() : - Subsystem("Pneumatics") + Subsystem("Pneumatics"), + pressureSensor(new AnalogInput(3)) { - pressureSensor = new AnalogInput(3); #ifdef REAL compressor = new Compressor(uint8_t(1)); // TODO: (1, 14, 1, 8); #endif - LiveWindow::GetInstance()->AddSensor("Pneumatics", "Pressure Sensor", pressureSensor); + LiveWindow::GetInstance().AddSensor("Pneumatics", "Pressure Sensor", pressureSensor); } /** diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pneumatics.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pneumatics.h index f66913eed2..7cbcb7cb97 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pneumatics.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Pneumatics.h @@ -12,7 +12,7 @@ class Pneumatics: public Subsystem { private: - AnalogInput* pressureSensor; + std::shared_ptr pressureSensor; #ifdef REAL Compressor* compressor; #endif diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Shooter.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Shooter.cpp index 9bb58a90e3..703fd7263f 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Shooter.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Shooter.cpp @@ -1,21 +1,21 @@ #include "Shooter.h" Shooter::Shooter() : - Subsystem("Shooter") + Subsystem("Shooter"), + // Configure Devices + piston1(new DoubleSolenoid(3, 4)), + piston2(new DoubleSolenoid(5, 6)), + latchPiston(new Solenoid(1, 2)), + piston1ReedSwitchFront(new DigitalInput(9)), + piston1ReedSwitchBack(new DigitalInput(11)), + hotGoalSensor(new DigitalInput(7)) { - // Configure Devices - hotGoalSensor = new DigitalInput(3); - piston1 = new DoubleSolenoid(3, 4); - piston2 = new DoubleSolenoid(5, 6); - latchPiston = new Solenoid(1, 2); - piston1ReedSwitchFront = new DigitalInput(9); - piston1ReedSwitchBack = new DigitalInput(11); // Put everything to the LiveWindow for testing. - LiveWindow::GetInstance()->AddSensor("Shooter", "Hot Goal Sensor", hotGoalSensor); - LiveWindow::GetInstance()->AddSensor("Shooter", "Piston1 Reed Switch Front ", piston1ReedSwitchFront); - LiveWindow::GetInstance()->AddSensor("Shooter", "Piston1 Reed Switch Back ", piston1ReedSwitchBack); - LiveWindow::GetInstance()->AddActuator("Shooter", "Latch Piston", latchPiston); + LiveWindow::GetInstance().AddSensor("Shooter", "Hot Goal Sensor", hotGoalSensor); + LiveWindow::GetInstance().AddSensor("Shooter", "Piston1 Reed Switch Front ", piston1ReedSwitchFront); + LiveWindow::GetInstance().AddSensor("Shooter", "Piston1 Reed Switch Back ", piston1ReedSwitchBack); + LiveWindow::GetInstance().AddActuator("Shooter", "Latch Piston", latchPiston); } void Shooter::InitDefaultCommand() diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Shooter.h b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Shooter.h index 7f3063c1d9..a80f22a549 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Shooter.h +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PacGoat/src/Subsystems/Shooter.h @@ -18,12 +18,12 @@ class Shooter: public Subsystem { private: // Devices - DoubleSolenoid* piston1; - DoubleSolenoid* piston2; - Solenoid* latchPiston; - DigitalInput* piston1ReedSwitchFront; - DigitalInput* piston1ReedSwitchBack; - DigitalInput* hotGoalSensor; // NOTE: Currently ignored in simulation + std::shared_ptr piston1; + std::shared_ptr piston2; + std::shared_ptr latchPiston; + std::shared_ptr piston1ReedSwitchFront; + std::shared_ptr piston1ReedSwitchBack; + std::shared_ptr hotGoalSensor; // NOTE: Currently ignored in simulation public: Shooter(); diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Potentiometer/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Potentiometer/src/Robot.cpp index 0076ae00a5..a5a10f4f79 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Potentiometer/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Potentiometer/src/Robot.cpp @@ -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) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PotentiometerPID/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PotentiometerPID/src/Robot.cpp index 14a6d31abe..c1b151fd87 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PotentiometerPID/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/PotentiometerPID/src/Robot.cpp @@ -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) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/QuickVision/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/QuickVision/src/Robot.cpp index 9ee47c0829..5cf80ad325 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/QuickVision/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/QuickVision/src/Robot.cpp @@ -25,5 +25,5 @@ public: } }; -START_ROBOT_CLASS(QuickVisionRobot); +START_ROBOT_CLASS(QuickVisionRobot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Relay/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Relay/src/Robot.cpp index 8d199b2dc2..c9c42a4baf 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Relay/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Relay/src/Robot.cpp @@ -66,4 +66,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Solenoid/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Solenoid/src/Robot.cpp index 54e28d11b5..f16faccb44 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Solenoid/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Solenoid/src/Robot.cpp @@ -74,4 +74,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Ultrasonic/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Ultrasonic/src/Robot.cpp index eacd2e90a8..8b74316cc0 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Ultrasonic/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/Ultrasonic/src/Robot.cpp @@ -9,8 +9,8 @@ * this system. Use IterativeRobot or Command-Based instead if you're new. */ class Robot: public SampleRobot { - AnalogInput *ultrasonic; //ultrasonic sensor - RobotDrive *myRobot; + AnalogInput ultrasonic; //ultrasonic sensor + RobotDrive myRobot; public: const int ultrasonicChannel = 3; //analog input pin @@ -27,14 +27,9 @@ public: Robot() : - SampleRobot() { - //make objects for the sensor and drive train - ultrasonic = new AnalogInput(ultrasonicChannel); - myRobot = new RobotDrive(new CANTalon(leftMotorChannel), - new CANTalon(leftRearMotorChannel), - new CANTalon(rightMotorChannel), - new CANTalon(rightRearMotorChannel)); - } + ultrasonic(ultrasonicChannel), + myRobot(new CANTalon(leftMotorChannel), new CANTalon(leftRearMotorChannel), + new CANTalon(rightMotorChannel), new CANTalon(rightRearMotorChannel)) {} /** * Runs during autonomous. @@ -53,9 +48,9 @@ public: double currentSpeed; //speed to set the drive train motors while (IsOperatorControl() && IsEnabled()) { - currentDistance = ultrasonic->GetValue() * valueToInches; //sensor returns a value from 0-4095 that is scaled to inches + currentDistance = ultrasonic.GetValue() * valueToInches; //sensor returns a value from 0-4095 that is scaled to inches currentSpeed = (holdDistance - currentDistance) * pGain; //convert distance error to a motor speed - myRobot->Drive(currentSpeed, 0); //drive robot + myRobot.Drive(currentSpeed, 0); //drive robot } } @@ -67,4 +62,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/UltrasonicPID/src/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/UltrasonicPID/src/Robot.cpp index ec8ce13d5d..ed5ca254c5 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/UltrasonicPID/src/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/examples/UltrasonicPID/src/Robot.cpp @@ -9,9 +9,9 @@ * this system. Use IterativeRobot or Command-Based instead if you're new. */ class Robot: public SampleRobot { - AnalogInput *ultrasonic; //ultrasonic sensor - RobotDrive *myRobot; - PIDController *pidController; + AnalogInput ultrasonic; //ultrasonic sensor + RobotDrive myRobot; + PIDController pidController; public: const int ultrasonicChannel = 3; //analog input @@ -36,32 +36,24 @@ public: //internal class to write to myRobot (a RobotDrive object) using a PIDOutput class MyPIDOutput: public PIDOutput { public: - RobotDrive* rd; - MyPIDOutput(RobotDrive *r) + RobotDrive &rd; + MyPIDOutput(RobotDrive &r) : rd(r) { - rd = r; - rd->SetSafetyEnabled(false); + rd.SetSafetyEnabled(false); } void PIDWrite(float output) { - rd->Drive(output, 0); //write to myRobot (RobotDrive) by reference + rd.Drive(output, 0); //write to myRobot (RobotDrive) by reference } }; Robot() : - SampleRobot() { //make objects for sensor and drive train - ultrasonic = new AnalogInput(ultrasonicChannel); - myRobot = new RobotDrive(new CANTalon(leftMotorChannel), - new CANTalon(leftRearMotorChannel), - new CANTalon(rightMotorChannel), - new CANTalon(rightRearMotorChannel)); - + ultrasonic(ultrasonicChannel), + myRobot(new CANTalon(leftMotorChannel), new CANTalon(leftRearMotorChannel), + new CANTalon(rightMotorChannel), new CANTalon(rightRearMotorChannel)), //ultrasonic (AnalogInput) can be used as a PIDSource without modification, //PIDOutput is an instance of the internal class MyPIDOutput made earlier - pidController = new PIDController(pGain, iGain, dGain, ultrasonic, - new MyPIDOutput(myRobot)); - - } + pidController(pGain, iGain, dGain, &ultrasonic, new MyPIDOutput(myRobot)) {} /** * Runs during autonomous. @@ -76,14 +68,14 @@ public: * sensor. */ void OperatorControl() { - pidController->SetSetpoint(holdDistance * VoltsToInches); //set setpoint to 12 inches + pidController.SetSetpoint(holdDistance * VoltsToInches); //set setpoint to 12 inches //set expected range to 0-24 inches; e.g. at 24 inches from object go full //forward, at 0 inches from object go full backward. - pidController->SetInputRange(0, 24 * VoltsToInches); + pidController.SetInputRange(0, 24 * VoltsToInches); while (IsOperatorControl() && IsEnabled()) { - pidController->Enable(); //begin PID control + pidController.Enable(); //begin PID control } } @@ -96,4 +88,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/iterative/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/iterative/Robot.cpp index 92d1106faa..b409b30e34 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/iterative/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/iterative/Robot.cpp @@ -3,11 +3,10 @@ class Robot: public IterativeRobot { private: - LiveWindow *lw; + LiveWindow &lw = LiveWindow::GetInstance(); void RobotInit() { - lw = LiveWindow::GetInstance(); } void AutonomousInit() @@ -32,8 +31,8 @@ private: void TestPeriodic() { - lw->Run(); + lw.Run(); } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/sample/Robot.cpp b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/sample/Robot.cpp index 627f7f6ba6..c360da0671 100644 --- a/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/sample/Robot.cpp +++ b/eclipse-plugins/edu.wpi.first.wpilib.plugins.cpp/resources/templates/sample/Robot.cpp @@ -55,4 +55,4 @@ public: } }; -START_ROBOT_CLASS(Robot); +START_ROBOT_CLASS(Robot) diff --git a/wpilibc/wpilibC++/include/Commands/PIDCommand.h b/wpilibc/wpilibC++/include/Commands/PIDCommand.h index 60266a9eaf..fd0c3c6446 100644 --- a/wpilibc/wpilibC++/include/Commands/PIDCommand.h +++ b/wpilibc/wpilibC++/include/Commands/PIDCommand.h @@ -35,7 +35,7 @@ class PIDCommand : public Command, public PIDOutput, public PIDSource { virtual double PIDGet() const; protected: - PIDController *GetPIDController() const; + std::shared_ptr GetPIDController() const; virtual void _Initialize(); virtual void _Interrupted(); virtual void _End(); @@ -48,7 +48,7 @@ class PIDCommand : public Command, public PIDOutput, public PIDSource { private: /** The internal {@link PIDController} */ - std::unique_ptr m_controller; + std::shared_ptr m_controller; public: virtual void InitTable(std::shared_ptr table); diff --git a/wpilibc/wpilibC++/include/Commands/PIDSubsystem.h b/wpilibc/wpilibC++/include/Commands/PIDSubsystem.h index de04c3377d..b4cf754fd5 100644 --- a/wpilibc/wpilibC++/include/Commands/PIDSubsystem.h +++ b/wpilibc/wpilibC++/include/Commands/PIDSubsystem.h @@ -59,14 +59,14 @@ class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource { virtual bool OnTarget() const; protected: - PIDController *GetPIDController(); + std::shared_ptr GetPIDController(); virtual double ReturnPIDInput() const = 0; virtual void UsePIDOutput(double output) = 0; private: /** The internal {@link PIDController} */ - std::unique_ptr m_controller; + std::shared_ptr m_controller; public: virtual void InitTable(std::shared_ptr table); diff --git a/wpilibc/wpilibC++/include/LiveWindow/LiveWindow.h b/wpilibc/wpilibC++/include/LiveWindow/LiveWindow.h index 4f7c84882e..e6904aba7d 100644 --- a/wpilibc/wpilibC++/include/LiveWindow/LiveWindow.h +++ b/wpilibc/wpilibC++/include/LiveWindow/LiveWindow.h @@ -37,6 +37,8 @@ class LiveWindow { "instead.")]] void AddSensor(const std::string &subsystem, const std::string &name, LiveWindowSendable *component); + void AddSensor(const std::string &subsystem, const std::string &name, + LiveWindowSendable &component); void AddSensor(const std::string &subsystem, const std::string &name, std::shared_ptr component); [[deprecated( @@ -44,6 +46,8 @@ class LiveWindow { "instead.")]] void AddActuator(const std::string &subsystem, const std::string &name, LiveWindowSendable *component); + void AddActuator(const std::string &subsystem, const std::string &name, + LiveWindowSendable &component); void AddActuator(const std::string &subsystem, const std::string &name, std::shared_ptr component); void AddSensor(std::string type, int channel, LiveWindowSendable *component); diff --git a/wpilibc/wpilibC++/src/Commands/Command.cpp b/wpilibc/wpilibC++/src/Commands/Command.cpp index df25ba41aa..78e05f7d1c 100644 --- a/wpilibc/wpilibC++/src/Commands/Command.cpp +++ b/wpilibc/wpilibC++/src/Commands/Command.cpp @@ -36,7 +36,7 @@ Command::Command(const std::string &name) : Command(name, -1.0) {} * @param timeout the time (in seconds) before this command "times out" * @see Command#isTimedOut() isTimedOut() */ -Command::Command(double timeout) : Command(nullptr, timeout) {} +Command::Command(double timeout) : Command("", timeout) {} /** * Creates a new command with the given name and timeout. @@ -45,8 +45,8 @@ Command::Command(double timeout) : Command(nullptr, timeout) {} * @see Command#isTimedOut() isTimedOut() */ Command::Command(const std::string &name, double timeout) { - if (name.size() == 0) wpi_setWPIErrorWithContext(NullParameter, "name"); - if (timeout < 0.0) + // We use -1.0 to indicate no timeout. + if (timeout < 0.0 && timeout != -1.0) wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); m_timeout = timeout; diff --git a/wpilibc/wpilibC++/src/Commands/PIDCommand.cpp b/wpilibc/wpilibC++/src/Commands/PIDCommand.cpp index d2953ef44f..16b7fa6645 100644 --- a/wpilibc/wpilibC++/src/Commands/PIDCommand.cpp +++ b/wpilibc/wpilibC++/src/Commands/PIDCommand.cpp @@ -12,30 +12,30 @@ PIDCommand::PIDCommand(const std::string &name, double p, double i, double d, double f, double period) : Command(name) { - m_controller = std::make_unique(p, i, d, this, this, period); + m_controller = std::make_shared(p, i, d, this, this, period); } PIDCommand::PIDCommand(double p, double i, double d, double f, double period) { - m_controller = std::make_unique(p, i, d, f, this, this, period); + m_controller = std::make_shared(p, i, d, f, this, this, period); } PIDCommand::PIDCommand(const std::string &name, double p, double i, double d) : Command(name) { - m_controller = std::make_unique(p, i, d, this, this); + m_controller = std::make_shared(p, i, d, this, this); } PIDCommand::PIDCommand(const std::string &name, double p, double i, double d, double period) : Command(name) { - m_controller = std::make_unique(p, i, d, this, this, period); + m_controller = std::make_shared(p, i, d, this, this, period); } PIDCommand::PIDCommand(double p, double i, double d) { - m_controller = std::make_unique(p, i, d, this, this); + m_controller = std::make_shared(p, i, d, this, this); } PIDCommand::PIDCommand(double p, double i, double d, double period) { - m_controller = std::make_unique(p, i, d, this, this, period); + m_controller = std::make_shared(p, i, d, this, this, period); } void PIDCommand::_Initialize() { m_controller->Enable(); } @@ -52,7 +52,9 @@ void PIDCommand::PIDWrite(float output) { UsePIDOutput(output); } double PIDCommand::PIDGet() const { return ReturnPIDInput(); } -PIDController *PIDCommand::GetPIDController() const { return m_controller.get(); } +std::shared_ptr PIDCommand::GetPIDController() const { + return m_controller; +} void PIDCommand::SetSetpoint(double setpoint) { m_controller->SetSetpoint(setpoint); diff --git a/wpilibc/wpilibC++/src/Commands/PIDSubsystem.cpp b/wpilibc/wpilibC++/src/Commands/PIDSubsystem.cpp index f0219100a9..e5fe6107d1 100644 --- a/wpilibc/wpilibC++/src/Commands/PIDSubsystem.cpp +++ b/wpilibc/wpilibC++/src/Commands/PIDSubsystem.cpp @@ -19,7 +19,7 @@ */ PIDSubsystem::PIDSubsystem(const std::string &name, double p, double i, double d) : Subsystem(name) { - m_controller = std::make_unique(p, i, d, this, this); + m_controller = std::make_shared(p, i, d, this, this); } /** @@ -115,7 +115,9 @@ void PIDSubsystem::Disable() { m_controller->Disable(); } * * @return the {@link PIDController} used by this {@link PIDSubsystem} */ -PIDController *PIDSubsystem::GetPIDController() { return m_controller.get(); } +std::shared_ptr PIDSubsystem::GetPIDController() { + return m_controller; +} /** * Sets the setpoint to the given value. If {@link PIDCommand#SetRange(double, diff --git a/wpilibc/wpilibC++/src/LiveWindow/LiveWindow.cpp b/wpilibc/wpilibC++/src/LiveWindow/LiveWindow.cpp index c9633a8d0a..9c60db8356 100644 --- a/wpilibc/wpilibC++/src/LiveWindow/LiveWindow.cpp +++ b/wpilibc/wpilibC++/src/LiveWindow/LiveWindow.cpp @@ -50,12 +50,16 @@ void LiveWindow::SetEnabled(bool enabled) { } /** - * Add a Sensor associated with the subsystem and with call it by the given - * name. + * @name AddSensor(subsystem, name, component) + * Add a Sensor associated with the subsystem and call it by the given name. * @param subsystem The subsystem this component is part of. * @param name The name of this component. * @param component A LiveWindowSendable component that represents a sensor. */ +//@{ +/** + * @brief Use a STL smart pointer to share ownership of component. + */ void LiveWindow::AddSensor(const std::string &subsystem, const std::string &name, std::shared_ptr component) { m_components[component].subsystem = subsystem; @@ -63,21 +67,42 @@ void LiveWindow::AddSensor(const std::string &subsystem, const std::string &name m_components[component].isSensor = true; } -[[deprecated( - "Raw pointers are deprecated; pass the component using shared_ptr " - "instead.")]] -void LiveWindow::AddSensor(const std::string &subsystem, const std::string &name, LiveWindowSendable *component) { +/** + * @brief Pass a reference to LiveWindow and retain ownership of the component. + */ +void LiveWindow::AddSensor(const std::string &subsystem, + const std::string &name, + LiveWindowSendable &component) { AddSensor(subsystem, name, std::shared_ptr( - component, NullDeleter())); + &component, [](LiveWindowSendable*){})); } /** - * Add an Actuator associated with the subsystem and with call it by the given - * name. + * @brief Use a raw pointer to the LiveWindow. + * @deprecated Prefer smart pointers or references. + */ +[[deprecated( + "Raw pointers are deprecated; pass the component using shared_ptr " + "instead.")]] +void LiveWindow::AddSensor(const std::string &subsystem, + const std::string &name, + LiveWindowSendable *component) { + AddSensor(subsystem, name, std::shared_ptr( + component, NullDeleter())); +} +//@} + +/** + * @name AddActuator(subsystem, name, component) + * Add an Actuator associated with the subsystem and call it by the given name. * @param subsystem The subsystem this component is part of. * @param name The name of this component. * @param component A LiveWindowSendable component that represents a actuator. */ +//@{ +/** + * @brief Use a STL smart pointer to share ownership of component. + */ void LiveWindow::AddActuator(const std::string &subsystem, const std::string &name, std::shared_ptr component) { m_components[component].subsystem = subsystem; @@ -85,18 +110,30 @@ void LiveWindow::AddActuator(const std::string &subsystem, const std::string &na m_components[component].isSensor = false; } -[[deprecated( - "Raw pointers are deprecated; pass the component using shared_ptr " - "instead.")]] +/** + * @brief Pass a reference to LiveWindow and retain ownership of the component. + */ +void LiveWindow::AddActuator(const std::string &subsystem, + const std::string &name, + LiveWindowSendable &component) { + AddActuator(subsystem, name, std::shared_ptr( + &component, [](LiveWindowSendable*){})); +} + +/** + * @brief Use a raw pointer to the LiveWindow. + * @deprecated Prefer smart pointers or references. + */ void LiveWindow::AddActuator(const std::string &subsystem, const std::string &name, LiveWindowSendable *component) { AddActuator(subsystem, name, std::shared_ptr( component, NullDeleter())); } +//@} /** - * INTERNAL + * Meant for internal use in other WPILib classes. */ [[deprecated]] void LiveWindow::AddSensor(std::string type, int channel, @@ -116,7 +153,7 @@ void LiveWindow::AddSensor(std::string type, int channel, } /** - * INTERNAL + * Meant for internal use in other WPILib classes. */ void LiveWindow::AddActuator(std::string type, int channel, LiveWindowSendable *component) { @@ -131,7 +168,7 @@ void LiveWindow::AddActuator(std::string type, int channel, } /** - * INTERNAL + * Meant for internal use in other WPILib classes. */ void LiveWindow::AddActuator(std::string type, int module, int channel, LiveWindowSendable *component) {