From fb51f39da7eaa79e590c43ce1e466afb371f62da Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Mon, 6 Apr 2015 20:36:35 -0400 Subject: [PATCH] Added BinIn, BinOut commands, BinCollector subsystem for collecting bins, mapped left button 3 and 4 to move BinCollector elevator. Works 100% --- Commands/BinCollector/BinIn.cpp | 26 ++++++++++++++++++++ Commands/BinCollector/BinIn.h | 42 ++++++++++++++++++++++++++++++++ Commands/BinCollector/BinOut.cpp | 26 ++++++++++++++++++++ Commands/BinCollector/BinOut.h | 42 ++++++++++++++++++++++++++++++++ DentRobot.cpp | 2 ++ DentRobot.h | 5 ++++ OI.cpp | 12 ++++++--- RobotMap.h | 3 +++ Subsystems/BinCollector.cpp | 16 ++++++++++++ Subsystems/BinCollector.h | 36 +++++++++++++++++++++++++++ mainpage.dox | 3 +++ 11 files changed, 209 insertions(+), 4 deletions(-) create mode 100644 Commands/BinCollector/BinIn.cpp create mode 100644 Commands/BinCollector/BinIn.h create mode 100644 Commands/BinCollector/BinOut.cpp create mode 100644 Commands/BinCollector/BinOut.h create mode 100644 Subsystems/BinCollector.cpp create mode 100644 Subsystems/BinCollector.h diff --git a/Commands/BinCollector/BinIn.cpp b/Commands/BinCollector/BinIn.cpp new file mode 100644 index 0000000..d0b6960 --- /dev/null +++ b/Commands/BinCollector/BinIn.cpp @@ -0,0 +1,26 @@ +#include "BinIn.h" +#include "../../DentRobot.h" +#include "../../OI.h" +BinIn::BinIn(float timeout): Command("BinIn"){ + SetTimeout(timeout); +} +void BinIn::Initialize(){ +} +void BinIn::Execute(){ + DentRobot::binCollector->Set(0.75); + End(); +} +bool BinIn::IsFinished(){ + if(IsTimedOut()){ + printf("Robot stoped collecting bin.\n"); + return true; + }else{ + return false; + } +} +void BinIn::End(){ +} +void BinIn::Interrupted(){ + End(); +} +// vim: ts=2:sw=2:et diff --git a/Commands/BinCollector/BinIn.h b/Commands/BinCollector/BinIn.h new file mode 100644 index 0000000..cd33936 --- /dev/null +++ b/Commands/BinCollector/BinIn.h @@ -0,0 +1,42 @@ +#ifndef BinIn_H +#define BinIn_H + +#include "Commands/Command.h" +#include "WPILib.h" + +/** + * @brief Lowers the bin collector until a timeout is reached + */ +class BinIn: public Command{ + public: + /** + * @brief Constructs BinIn + * + * @param timeout Timeout in seconds + */ + BinIn(float timeout); + /** + * @brief Initializes the class + */ + void Initialize(); + /** + * @brief Lowers the bin collector at -1.0 power + */ + void Execute(); + /** + * @brief Checks if the command is finished + * + * @return True only if the timeout was reached + */ + bool IsFinished(); + /** + * @brief Sets the bin collector to stop + */ + void End(); + /** + * @brief Calls End() + */ + void Interrupted(); +}; +#endif +// vim: ts=2:sw=2:et diff --git a/Commands/BinCollector/BinOut.cpp b/Commands/BinCollector/BinOut.cpp new file mode 100644 index 0000000..561491a --- /dev/null +++ b/Commands/BinCollector/BinOut.cpp @@ -0,0 +1,26 @@ +#include "BinOut.h" +#include "../../DentRobot.h" +#include "../../OI.h" +BinOut::BinOut(double timeout): Command("BinOut"){ + SetTimeout(timeout); +} +void BinOut::Initialize(){ +} +void BinOut::Execute(){ + DentRobot::binCollector->Set(0.1); + End(); +} +bool BinOut::IsFinished(){ + if(IsTimedOut()){ + printf("Robot stoped ejecting bin.\n"); + return true; + }else{ + return false; + } +} +void BinOut::End(){ +} +void BinOut::Interrupted(){ + End(); +} +// vim: ts=2:sw=2:et diff --git a/Commands/BinCollector/BinOut.h b/Commands/BinCollector/BinOut.h new file mode 100644 index 0000000..bb3d281 --- /dev/null +++ b/Commands/BinCollector/BinOut.h @@ -0,0 +1,42 @@ +#ifndef BinOut_H +#define BinOut_H + +#include "Commands/Command.h" +#include "WPILib.h" + +/** + * @brief Raises the bin collector until a timeout is reached + */ +class BinOut: public Command{ + public: + /** + * @brief Constructs BinOut + * + * @param timeout Timeout in seconds + */ + BinOut(double timeout); + /** + * @brief Initializes the class + */ + void Initialize(); + /** + * @brief Raises the bin colector at 1.0 power + */ + void Execute(); + /** + * @brief Checks if the command is finished + * + * @return True only if the timeout was reached + */ + bool IsFinished(); + /** + * @brief Sets the bin colector to stop + */ + void End(); + /** + * @brief Calls End() + */ + void Interrupted(); +}; +#endif +// vim: ts=2:sw=2:et diff --git a/DentRobot.cpp b/DentRobot.cpp index e8c7891..8f1ca4c 100644 --- a/DentRobot.cpp +++ b/DentRobot.cpp @@ -9,6 +9,7 @@ Elevator* DentRobot::elevator = NULL; BinElevator* DentRobot::binElevator = NULL; CommandGroup* DentRobot::aut = NULL; Pneumatics* DentRobot::pneumatics = NULL; +BinCollector* DentRobot::binCollector = NULL; DentRobot::DentRobot(){ oi = new OI(); collector = new Collector(); @@ -16,6 +17,7 @@ DentRobot::DentRobot(){ elevator = new Elevator(); binElevator = new BinElevator(); pneumatics = new Pneumatics(); + binCollector = new BinCollector(); //CameraServer::GetInstance()->SetQuality(25); //CameraServer::GetInstance()->StartAutomaticCapture("cam0"); printf("The robot is on\n"); diff --git a/DentRobot.h b/DentRobot.h index 94bd52c..acda4b1 100644 --- a/DentRobot.h +++ b/DentRobot.h @@ -7,6 +7,7 @@ #include "Subsystems/Drivetrain.h" #include "Subsystems/Collector.h" #include "Subsystems/Pneumatics.h" +#include "Subsystems/BinCollector.h" #include "Commands/Autonomous/Autonomous.h" /** * @brief The Hitchhikers 2015 robot, Dent @@ -48,6 +49,10 @@ class DentRobot: public IterativeRobot{ * @brief The Pneumatics system (unused) */ static Pneumatics* pneumatics; + /** + * @brief The BinCollector for collecting bins + */ + static BinCollector* binCollector; /** * @brief The Autonomous command */ diff --git a/OI.cpp b/OI.cpp index e01344c..8732d1c 100644 --- a/OI.cpp +++ b/OI.cpp @@ -9,6 +9,8 @@ #include "Commands/BinElevator/BinRaise.h" #include "Commands/BinElevator/BinCloseArms.h" #include "Commands/BinElevator/BinOpenArms.h" +#include "Commands/BinCollector/BinIn.h" +#include "Commands/BinCollector/BinOut.h" #include "Commands/Autonomous/CollectTote.h" #include "Commands/Autonomous/ReleaseTote.h" OI::OI(){ @@ -47,16 +49,18 @@ OI::OI(){ // BinElevator JoystickButton *right3 = new JoystickButton(rightStick, 3); JoystickButton *right5 = new JoystickButton(rightStick, 5); - //JoystickButton *right7 = new JoystickButton(rightStick, 7); - //JoystickButton *right8 = new JoystickButton(rightStick, 8); - //right7->WhenPressed(new BinOpenArms()); - //right8->WhenPressed(new BinCloseArms()); binRaise = new BinRaise(3.0); binLower = new BinLower(2.0); right3->WhileHeld(binLower); right3->CancelWhenPressed(binRaise); right5->WhileHeld(binRaise); right5->CancelWhenPressed(binLower); + + // BinCollector + JoystickButton *left3 = new JoystickButton(leftStick, 3); + JoystickButton *left4 = new JoystickButton(leftStick, 4); + left3->WhileHeld(new BinIn(2.0)); + left4->WhileHeld(new BinOut(2.0)); } Joystick* OI::GetRightStick(){ return rightStick; diff --git a/RobotMap.h b/RobotMap.h index 0471087..f6b34f8 100644 --- a/RobotMap.h +++ b/RobotMap.h @@ -37,5 +37,8 @@ #define COLLECTOR_RIGHT_CAN 9 #define COLLECTOR_SONAR_ANALOG 3 +// BinCollector +#define BINCOLLECTOR 0 + #endif // vim: ts=2:sw=2:et diff --git a/Subsystems/BinCollector.cpp b/Subsystems/BinCollector.cpp new file mode 100644 index 0000000..5e2c81f --- /dev/null +++ b/Subsystems/BinCollector.cpp @@ -0,0 +1,16 @@ +#include "BinCollector.h" +#include "../RobotMap.h" + +BinCollector::BinCollector(): Subsystem("BinCollector"){ + binCollectorMotor = new Servo(BINCOLLECTOR); +} +void BinCollector::InitDefaultCommand(){ +} +void BinCollector::Set(double pos){ + binCollectorMotor->Set(pos); + printf("BinCollector angle: %f\n", pos); +} +double BinCollector::Get(){ + return binCollectorMotor->Get(); +} +// vim: ts=2:sw=2:et diff --git a/Subsystems/BinCollector.h b/Subsystems/BinCollector.h new file mode 100644 index 0000000..9a92489 --- /dev/null +++ b/Subsystems/BinCollector.h @@ -0,0 +1,36 @@ +#ifndef BinCollector_H +#define BinCollector_H + +#include "WPILib.h" +/** + * @brief Collects bins + * + * Collects bins with a servo + */ +class BinCollector: public Subsystem{ + private: + Servo *binCollectorMotor; //