From 93f166e1b868c108995e0def5d7e63c643ef3fcb Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 15 Mar 2016 21:16:03 -0400 Subject: [PATCH] Move code in Shooter.h to a .cpp file which is where it belongs. Grumble grumble --- .gitignore | 1 + Robot2016/Makefile | 6 +- Robot2016/src/Shooter.cpp | 151 ++++++++++++++++++++++++++++++++++ Robot2016/src/Shooter.h | 165 ++++---------------------------------- 4 files changed, 170 insertions(+), 153 deletions(-) create mode 100644 Robot2016/src/Shooter.cpp diff --git a/.gitignore b/.gitignore index 0852c56..2ee21b1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ Robot2016/.settings Robot2016/sysProps.xml FRCUserProgram /RemoteSystemsTempFiles/ +*.o diff --git a/Robot2016/Makefile b/Robot2016/Makefile index 36efedf..514df4d 100644 --- a/Robot2016/Makefile +++ b/Robot2016/Makefile @@ -11,12 +11,12 @@ all: deploy build: FRCUserProgram -FRCUserProgram: src/Robot.cpp +FRCUserProgram: src/Robot.cpp src/Shooter.o @echo "Building FRCUserProgram" - $(CXX) $(CPPFLAGS) $< -o $@ $(LDFLAGS) + $(CXX) $(CPPFLAGS) $^ -o $@ $(LDFLAGS) clean: - rm FRCUserProgram + rm FRCUserProgram src/Shooter.o deploy: build @echo "Copying FRCUserProgram" diff --git a/Robot2016/src/Shooter.cpp b/Robot2016/src/Shooter.cpp new file mode 100644 index 0000000..5909d48 --- /dev/null +++ b/Robot2016/src/Shooter.cpp @@ -0,0 +1,151 @@ +#include +#include "Shooter.h" + +Shooter::Shooter(CANTalon *s1, CANTalon *s2, CANTalon *r) : + launcher(s1), + pickup(s2), + ramp(r), + ready(true), + state(READY) +{ + // shooterDrive = new RobotDrive(s1, s2); +} + +/** + * Call this method on TeleopInit so that the ramp is properly + * set at the beginning of the match. + */ + +Shooter::~Shooter() +{ + delete launcher; + delete pickup; + delete ramp; +} + +void Shooter::StopShooter() +{ + ready = true; + ramp->Set(0); + launcher->Set(0); + pickup->Set(0); +} + +void Shooter::LowerRamp() +{ + ramp->Set(-RAMP_POWER); + if(ramp->Limits::kReverseLimit){ + SmartDashboard::PutNumber("ramp", 2); //going to put a circlar dial to show where the ramp could be + } else { + SmartDashboard::PutNumber("ramp", 1); + } +} + +void Shooter::RaiseRamp() +{ + ramp->Set(RAMP_POWER); + if(ramp->Limits::kForwardLimit){ + SmartDashboard::PutNumber("ramp", 0); //going to put a circlar dial to show where the ramp could be + } else { + SmartDashboard::PutNumber("ramp", 1); + } +} + +void Shooter::StopRamp() +{ + ramp->Set(0); +} +void Shooter::Shoot() +{ + if (shotClock.Get() > (SPINUP_TIME + 0.1)) + { + state = RESETTING; + } + switch (state) + { + case READY: + { + state = SPINNINGUP; + ramp->Set(-1); + launcher->Set(LAUNCH_POWER); + pickup->Set(LAUNCH_POWER); + shotClock.Reset(); + shotClock.Start(); + break; + } + case SPINNINGUP: + { + if (shotClock.Get() > SPINUP_TIME) + { + state = LAUNCH; + shotClock.Reset(); + shotClock.Start(); + } else + { + //std::cout << "*Goku noises*\n"; + } + break; + } + case LAUNCH: + { + ramp->Set(LAUNCH_POWER); + state = LAUNCHING; + break; + } + case LAUNCHING: + { + if (shotClock.Get() > LAUNCH_TIME) + { + + state = RESETTING; + } + break; + } + case RESETTING: + { + ramp->Set(0); + launcher->Set(0); + pickup->Set(0); + state = READY; + break; + } + case ON_FIRE: + { + std::cout << "Something is wrong with the launch sequence.\n"; + break; + } + } + +} + +void Shooter::PickUp(bool state /*= true*/) +{ + pickup->Set((float) (state * PICKUP_POWER)); + launcher->Set((float) (state * PICKUP_POWER * -1)); + //std::cout << "picking up!\n"; +} + +/** + * Call this to run the pickup backwards if the ball gets jammed somehow... + */ +void Shooter::Unjam() +{ + pickup->Set(-1 * PICKUP_POWER); +} + +void Shooter::ShootLow() +{ + pickup->Set(-1); +} + +void Shooter::SetPower(float power) +{ + pickup->Set(power); + launcher->Set(power); + //std::cout << "setting shooter power" << std::endl; +} + +int Shooter::GetState() +{ + return state; +} diff --git a/Robot2016/src/Shooter.h b/Robot2016/src/Shooter.h index 8339baf..ad505b6 100644 --- a/Robot2016/src/Shooter.h +++ b/Robot2016/src/Shooter.h @@ -14,7 +14,7 @@ #define LAUNCH_TIME 0.5 #define RAMP_POWER 0.3 -class Shooter +class Shooter { public: @@ -33,154 +33,19 @@ public: RESETTING }; - Shooter(CANTalon *s1, CANTalon *s2, CANTalon *r) - { - // shooterDrive = new RobotDrive(s1, s2); - launcher = s1; - pickup = s2; - ramp = r; - ready = true; - state = READY; - } + Shooter(CANTalon *s1, CANTalon *s2, CANTalon *r); + virtual ~Shooter(); + void StopShooter(); + void LowerRamp(); + void RaiseRamp(); + void StopRamp(); + void Shoot(); + void PickUp(bool state = true); + void Unjam(); + void ShootLow(); + void SetPower(float power); + int GetState(); - /** - * Call this method on TeleopInit so that the ramp is properly - * set at the beginning of the match. - */ - - virtual ~Shooter() - { - delete launcher; - delete pickup; - delete ramp; - } - - void StopShooter() - { - ready = true; - ramp->Set(0); - launcher->Set(0); - pickup->Set(0); - } - - void LowerRamp() - { - ramp->Set(-RAMP_POWER); - if(ramp->Limits::kReverseLimit){ - SmartDashboard::PutNumber("ramp", 2); //going to put a circlar dial to show where the ramp could be - } else { - SmartDashboard::PutNumber("ramp", 1); - } - } - - void RaiseRamp() - { - ramp->Set(RAMP_POWER); - if(ramp->Limits::kForwardLimit){ - SmartDashboard::PutNumber("ramp", 0); //going to put a circlar dial to show where the ramp could be - } else { - SmartDashboard::PutNumber("ramp", 1); - } - } - - void StopRamp() - { - ramp->Set(0); - } - void Shoot() - { - if (shotClock.Get() > (SPINUP_TIME + 0.1)) - { - state = RESETTING; - } - switch (state) - { - case READY: - { - state = SPINNINGUP; - ramp->Set(-1); - launcher->Set(LAUNCH_POWER); - pickup->Set(LAUNCH_POWER); - shotClock.Reset(); - shotClock.Start(); - break; - } - case SPINNINGUP: - { - if (shotClock.Get() > SPINUP_TIME) - { - state = LAUNCH; - shotClock.Reset(); - shotClock.Start(); - } else - { - //std::cout << "*Goku noises*\n"; - } - break; - } - case LAUNCH: - { - ramp->Set(LAUNCH_POWER); - state = LAUNCHING; - break; - } - case LAUNCHING: - { - if (shotClock.Get() > LAUNCH_TIME) - { - - state = RESETTING; - } - break; - } - case RESETTING: - { - ramp->Set(0); - launcher->Set(0); - pickup->Set(0); - state = READY; - break; - } - case ON_FIRE: - { - std::cout << "Something is wrong with the launch sequence.\n"; - break; - } - } - - } - - void PickUp(bool state = true) - { - pickup->Set((float) (state * PICKUP_POWER)); - launcher->Set((float) (state * PICKUP_POWER * -1)); - //std::cout << "picking up!\n"; - } - - /** - * Call this to run the pickup backwards if the ball gets jammed somehow... - */ - void Unjam() - { - pickup->Set(-1 * PICKUP_POWER); - } - - void ShootLow() - { - pickup->Set(-1); - } - - void SetPower(float power) - { - pickup->Set(power); - launcher->Set(power); - //std::cout << "setting shooter power" << std::endl; - } - - int GetState() - { - return state; - } private: //RobotDrive *shooterDrive; @@ -188,8 +53,8 @@ private: CANTalon *pickup; CANTalon *ramp; ShooterState state; - - Timer shotClock; + + Timer shotClock; bool ready; int fake_position; };