mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Fixed examples to build/run with new WPILib versions.
Also added some references/smart pointers to a couple places that seemed convenient to the user. I haven't updated the constructors for RobotDrive() related examples, pending the results of gerrit change https://usfirst.collab.net/gerrit/#/c/960/ A few things that we are noticing: --It might be nice if ReturnPIDInput() didn't have to be const; when people try to override it, they have to remember to put the const in and if they don't, then the compiler error isn't the most obvious (especially since this is a change). This would also apply to PIDGet() in the PIDSource interface. --SendableChooser still takes raw pointers. This could lead to an issue I had to debug briefly where you accidentally call GetSelected() on autoChooser and put the resulting raw pointer into a unique_ptr, which destroys the pointer when it goes out of scope. Specifically, I was testing the PacGoat example and I ended up with a situation where if auto mode was run once, it was fine, but if it was run twice, the selected command would have been destroyed by the unique_ptr. I believe that this just requires updating SendableChosser to take shared_ptr. --When the samples are compiled with -pedantic, it points out that START_ROBOT_CLASS macro expansion results in a redundant semicolon. Change-Id: Ib4c025a61263d0d2780d4253faa31713e15333a5
This commit is contained in:
committed by
Brad Miller (WPI)
parent
4f8c1dff2f
commit
e017f93f16
@@ -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<ExampleSubsystem> CommandBase::examplesubsystem;
|
||||
std::unique_ptr<OI> 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());
|
||||
}
|
||||
|
||||
@@ -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> examplesubsystem;
|
||||
static std::unique_ptr<OI> oi;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -8,7 +8,7 @@ class $classname: public PIDSubsystem
|
||||
{
|
||||
public:
|
||||
$classname();
|
||||
double ReturnPIDInput();
|
||||
double ReturnPIDInput() const;
|
||||
void UsePIDOutput(double output);
|
||||
void InitDefaultCommand();
|
||||
};
|
||||
|
||||
@@ -6,16 +6,14 @@
|
||||
class Robot: public IterativeRobot
|
||||
{
|
||||
private:
|
||||
Command *autonomousCommand;
|
||||
LiveWindow *lw;
|
||||
std::unique_ptr<Command> 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)
|
||||
|
||||
|
||||
@@ -233,5 +233,5 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(VisionColor2015Sample);
|
||||
START_ROBOT_CLASS(VisionColor2015Sample)
|
||||
|
||||
|
||||
@@ -207,4 +207,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(VisionRetro2015Sample);
|
||||
START_ROBOT_CLASS(VisionRetro2015Sample)
|
||||
|
||||
@@ -37,4 +37,4 @@ public:
|
||||
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -9,7 +9,7 @@ class AxisCameraSample : public SampleRobot
|
||||
IMAQdxSession session;
|
||||
Image *frame;
|
||||
IMAQdxError imaqError;
|
||||
AxisCamera *camera;
|
||||
std::unique_ptr<AxisCamera> 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)
|
||||
|
||||
|
||||
@@ -44,4 +44,4 @@ public:
|
||||
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -35,4 +35,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -60,4 +60,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -79,4 +79,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
class DriveStraightPIDSource: public PIDSource {
|
||||
public:
|
||||
virtual ~DriveStraightPIDSource();
|
||||
double PIDGet();
|
||||
double PIDGet() const;
|
||||
};
|
||||
|
||||
class DriveStraightPIDOutput: public PIDOutput {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "Robot.h"
|
||||
|
||||
OpenClaw::OpenClaw() : Command("OpenClaw") {
|
||||
Requires(Robot::claw);
|
||||
Requires(Robot::claw.get());
|
||||
SetTimeout(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
class SetDistanceToBoxPIDSource: public PIDSource {
|
||||
public:
|
||||
virtual ~SetDistanceToBoxPIDSource();
|
||||
double PIDGet();
|
||||
double PIDGet() const;
|
||||
};
|
||||
|
||||
class SetDistanceToBoxPIDOutput: public PIDOutput {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<DriveTrain> Robot::drivetrain;
|
||||
std::shared_ptr<Elevator> Robot::elevator;
|
||||
std::shared_ptr<Wrist> Robot::wrist;
|
||||
std::shared_ptr<Claw> Robot::claw;
|
||||
|
||||
OI* Robot::oi = NULL;
|
||||
std::unique_ptr<OI> 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)
|
||||
|
||||
@@ -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> drivetrain;
|
||||
static std::shared_ptr<Elevator> elevator;
|
||||
static std::shared_ptr<Wrist> wrist;
|
||||
static std::shared_ptr<Claw> claw;
|
||||
static std::unique_ptr<OI> oi;
|
||||
|
||||
private:
|
||||
Command *autonomousCommand;
|
||||
LiveWindow *lw;
|
||||
Autonomous autonomousCommand;
|
||||
LiveWindow &lw = LiveWindow::GetInstance();
|
||||
|
||||
void RobotInit();
|
||||
void AutonomousInit();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<Encoder> left_encoder, right_encoder;
|
||||
std::shared_ptr<AnalogInput> rangefinder;
|
||||
std::shared_ptr<Gyro> gyro;
|
||||
|
||||
public:
|
||||
DriveTrain();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -46,5 +46,5 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(IntermediateVisionRobot);
|
||||
START_ROBOT_CLASS(IntermediateVisionRobot)
|
||||
|
||||
|
||||
@@ -46,4 +46,4 @@ public:
|
||||
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -41,4 +41,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -52,4 +52,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Robot.h"
|
||||
|
||||
ExtendShooter::ExtendShooter() {
|
||||
Requires(Robot::shooter);
|
||||
Requires(Robot::shooter.get());
|
||||
SetTimeout(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Robot.h"
|
||||
|
||||
SetCollectionSpeed::SetCollectionSpeed(double speed) {
|
||||
Requires(Robot::collector);
|
||||
Requires(Robot::collector.get());
|
||||
this->speed = speed;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
WaitForPressure::WaitForPressure()
|
||||
{
|
||||
Requires(Robot::pneumatics);
|
||||
Requires(Robot::pneumatics.get());
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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> drivetrain;
|
||||
static std::shared_ptr<Pivot> pivot;
|
||||
static std::shared_ptr<Collector> collector;
|
||||
static std::shared_ptr<Shooter> shooter;
|
||||
static std::shared_ptr<Pneumatics> pneumatics;
|
||||
static std::unique_ptr<OI> oi;
|
||||
|
||||
private:
|
||||
Command *autonomousCommand;
|
||||
LiveWindow *lw;
|
||||
SendableChooser* autoChooser;
|
||||
Command* autonomousCommand = nullptr;
|
||||
std::unique_ptr<Command> driveAndShootAuto{new DriveAndShootAutonomous()},
|
||||
driveForwardAuto{new DriveForward()};
|
||||
SendableChooser autoChooser;
|
||||
|
||||
void RobotInit();
|
||||
void AutonomousInit();
|
||||
@@ -44,5 +47,4 @@ private:
|
||||
void Log();
|
||||
};
|
||||
|
||||
|
||||
#endif /* ROBOT_H_ */
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -19,10 +19,10 @@ public:
|
||||
|
||||
private:
|
||||
// Subsystem devices
|
||||
SpeedController* rollerMotor;
|
||||
DigitalInput* ballDetector;
|
||||
Solenoid* piston;
|
||||
DigitalInput* openDetector;
|
||||
std::shared_ptr<SpeedController> rollerMotor;
|
||||
std::shared_ptr<DigitalInput> ballDetector;
|
||||
std::shared_ptr<Solenoid> piston;
|
||||
std::shared_ptr<DigitalInput> openDetector;
|
||||
|
||||
public:
|
||||
Collector();
|
||||
|
||||
@@ -3,13 +3,17 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
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<Encoder> DriveTrain::GetLeftEncoder() {
|
||||
return leftEncoder;
|
||||
}
|
||||
|
||||
Encoder* DriveTrain::GetRightEncoder() {
|
||||
std::shared_ptr<Encoder> DriveTrain::GetRightEncoder() {
|
||||
return rightEncoder;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<SpeedController> frontLeftCIM, frontRightCIM;
|
||||
std::shared_ptr<SpeedController> backLeftCIM, backRightCIM;
|
||||
RobotDrive drive;
|
||||
std::shared_ptr<Encoder> rightEncoder, leftEncoder;
|
||||
std::shared_ptr<Gyro> 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<Encoder> GetLeftEncoder();
|
||||
|
||||
/**
|
||||
* @return The encoder getting the distance and speed of right side of the drivetrain.
|
||||
*/
|
||||
Encoder* GetRightEncoder();
|
||||
std::shared_ptr<Encoder> GetRightEncoder();
|
||||
|
||||
/**
|
||||
* @return The current angle of the drivetrain.
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ public:
|
||||
|
||||
private:
|
||||
// Subsystem devices
|
||||
DigitalInput* upperLimitSwitch;
|
||||
DigitalInput* lowerLimitSwitch;
|
||||
Potentiometer* pot;
|
||||
SpeedController* motor;
|
||||
std::shared_ptr<DigitalInput> upperLimitSwitch;
|
||||
std::shared_ptr<DigitalInput> lowerLimitSwitch;
|
||||
std::shared_ptr<Potentiometer> pot;
|
||||
std::shared_ptr<SpeedController> 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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
class Pneumatics: public Subsystem
|
||||
{
|
||||
private:
|
||||
AnalogInput* pressureSensor;
|
||||
std::shared_ptr<AnalogInput> pressureSensor;
|
||||
#ifdef REAL
|
||||
Compressor* compressor;
|
||||
#endif
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<DoubleSolenoid> piston1;
|
||||
std::shared_ptr<DoubleSolenoid> piston2;
|
||||
std::shared_ptr<Solenoid> latchPiston;
|
||||
std::shared_ptr<DigitalInput> piston1ReedSwitchFront;
|
||||
std::shared_ptr<DigitalInput> piston1ReedSwitchBack;
|
||||
std::shared_ptr<DigitalInput> hotGoalSensor; // NOTE: Currently ignored in simulation
|
||||
|
||||
public:
|
||||
Shooter();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -25,5 +25,5 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(QuickVisionRobot);
|
||||
START_ROBOT_CLASS(QuickVisionRobot)
|
||||
|
||||
|
||||
@@ -66,4 +66,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -74,4 +74,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -55,4 +55,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
START_ROBOT_CLASS(Robot);
|
||||
START_ROBOT_CLASS(Robot)
|
||||
|
||||
@@ -35,7 +35,7 @@ class PIDCommand : public Command, public PIDOutput, public PIDSource {
|
||||
virtual double PIDGet() const;
|
||||
|
||||
protected:
|
||||
PIDController *GetPIDController() const;
|
||||
std::shared_ptr<PIDController> 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<PIDController> m_controller;
|
||||
std::shared_ptr<PIDController> m_controller;
|
||||
|
||||
public:
|
||||
virtual void InitTable(std::shared_ptr<ITable> table);
|
||||
|
||||
@@ -59,14 +59,14 @@ class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
|
||||
virtual bool OnTarget() const;
|
||||
|
||||
protected:
|
||||
PIDController *GetPIDController();
|
||||
std::shared_ptr<PIDController> GetPIDController();
|
||||
|
||||
virtual double ReturnPIDInput() const = 0;
|
||||
virtual void UsePIDOutput(double output) = 0;
|
||||
|
||||
private:
|
||||
/** The internal {@link PIDController} */
|
||||
std::unique_ptr<PIDController> m_controller;
|
||||
std::shared_ptr<PIDController> m_controller;
|
||||
|
||||
public:
|
||||
virtual void InitTable(std::shared_ptr<ITable> table);
|
||||
|
||||
@@ -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<LiveWindowSendable> 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<LiveWindowSendable> component);
|
||||
void AddSensor(std::string type, int channel, LiveWindowSendable *component);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<PIDController>(p, i, d, this, this, period);
|
||||
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(double p, double i, double d, double f, double period) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, f, this, this, period);
|
||||
m_controller = std::make_shared<PIDController>(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<PIDController>(p, i, d, this, this);
|
||||
m_controller = std::make_shared<PIDController>(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<PIDController>(p, i, d, this, this, period);
|
||||
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(double p, double i, double d) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this);
|
||||
m_controller = std::make_shared<PIDController>(p, i, d, this, this);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(double p, double i, double d, double period) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this, period);
|
||||
m_controller = std::make_shared<PIDController>(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<PIDController> PIDCommand::GetPIDController() const {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
void PIDCommand::SetSetpoint(double setpoint) {
|
||||
m_controller->SetSetpoint(setpoint);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
PIDSubsystem::PIDSubsystem(const std::string &name, double p, double i, double d)
|
||||
: Subsystem(name) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this);
|
||||
m_controller = std::make_shared<PIDController>(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<PIDController> PIDSubsystem::GetPIDController() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the setpoint to the given value. If {@link PIDCommand#SetRange(double,
|
||||
|
||||
@@ -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<LiveWindowSendable> 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<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
&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<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
}
|
||||
//@}
|
||||
|
||||
/**
|
||||
* @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<LiveWindowSendable> 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<LiveWindowSendable>(
|
||||
&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<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
}
|
||||
//@}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
Reference in New Issue
Block a user