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
@@ -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<DriveTrain> Robot::drivetrain;
|
||||
std::shared_ptr<Pivot> Robot::pivot;
|
||||
std::shared_ptr<Collector> Robot::collector;
|
||||
std::shared_ptr<Shooter> Robot::shooter;
|
||||
std::shared_ptr<Pneumatics> Robot::pneumatics;
|
||||
|
||||
OI* Robot::oi = NULL;
|
||||
std::unique_ptr<OI> 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)
|
||||
|
||||
Reference in New Issue
Block a user