From 88ec9d52484d1143a5ff29ba9feff821726883a4 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sun, 11 Jan 2015 16:02:49 -0500 Subject: [PATCH] Started working on command based robot (does not work) --- src/CommandBase.cpp | 25 ++++++++++++++++++++ src/CommandBase.h | 20 ++++++++++++++++ src/DentRobot.cpp | 39 ++++++++++++++++++++++++++++++ src/HHBase.cpp | 28 ---------------------- src/HHBase.h | 26 -------------------- src/HHRobot.cpp | 46 ------------------------------------ src/HHRobot.h | 19 --------------- src/OI.cpp | 4 ++++ src/OI.h | 12 ++++++++++ src/RobotMap.h | 6 +++++ src/Subsystems/Collector.cpp | 7 ++++++ src/Subsystems/Collector.h | 13 ++++++++++ src/classes/Collector.cpp | 22 ----------------- src/classes/Collector.h | 15 ------------ src/hhlib | 1 - 15 files changed, 126 insertions(+), 157 deletions(-) create mode 100644 src/CommandBase.cpp create mode 100644 src/CommandBase.h create mode 100644 src/DentRobot.cpp delete mode 100644 src/HHBase.cpp delete mode 100644 src/HHBase.h delete mode 100644 src/HHRobot.cpp delete mode 100644 src/HHRobot.h create mode 100644 src/OI.cpp create mode 100644 src/OI.h create mode 100644 src/RobotMap.h create mode 100644 src/Subsystems/Collector.cpp create mode 100644 src/Subsystems/Collector.h delete mode 100644 src/classes/Collector.cpp delete mode 100644 src/classes/Collector.h delete mode 160000 src/hhlib diff --git a/src/CommandBase.cpp b/src/CommandBase.cpp new file mode 100644 index 0000000..7c8c4d5 --- /dev/null +++ b/src/CommandBase.cpp @@ -0,0 +1,25 @@ +#include "CommandBase.h" +#include "Subsystems/Drivetrain.h" +#include "Subsystems/Collector.h" +#include "Subsystems/Elevator.h" +#include "Commands/Drive.h" +#include "Commands/Collect.h" +#include "Commands/Eject.h" +#include "Commands/Raise.h" +#include "Commands/Lower.h" +Drivetrain* CommandBase::drivetrain = NULL; +Collector* CommandBase::collector = NULL; +Elevator* CommandBase::elevator = NULL; +OI* CommandBase::oi = NULL; +CommandBase::CommandBase(char const *name) : Command(name) { +} +CommandBase::CommandBase() : Command() { +} +void CommandBase::init() +{ + drivetrain = new Drivetrain(); + collector = new Collector(); + elevator = new Elevator(); + oi = new OI(); +} + diff --git a/src/CommandBase.h b/src/CommandBase.h new file mode 100644 index 0000000..3c5f352 --- /dev/null +++ b/src/CommandBase.h @@ -0,0 +1,20 @@ +#ifndef COMMAND_BASE_H +#define COMMAND_BASE_H + +#include +#include "Commands/Command.h" +#include "Subsystems/ExampleSubsystem.h" +#include "OI.h" +#include "WPILib.h" + +class CommandBase: public Command { +public: + CommandBase(char const *name); + CommandBase(); + static void init(); + static Drivetrain *drivetrain; + static Collector *collector; + static Elevator *elevator; + static OI *oi; +}; +#endif diff --git a/src/DentRobot.cpp b/src/DentRobot.cpp new file mode 100644 index 0000000..7a8a37b --- /dev/null +++ b/src/DentRobot.cpp @@ -0,0 +1,39 @@ +#include "WPILib.h" +#include "Commands/Command.h" +#include "Commands/Drive.h" +#include "Commands/Collect.h" +#include "Commands/Eject.h" +#include "Commands/Raise.h" +#include "Commands/Lower.h" +class DentRobot: public IterativeRobot { +private: + Command *autonomousCommand = NULL; + LiveWindow *lw; + void RobotInit() { + CommandBase::init(); + lw = LiveWindow::GetInstance(); + } + void DisabledPeriodic() { + Scheduler::GetInstance()->Run(); + } + void AutonomousInit() { + if(autonomousCommand != NULL) { + autonomousCommand->Start(); + } + } + void AutonomousPeriodic() { + Scheduler::GetInstance()->Run(); + } + void TeleopInit() { + if(autonomousCommand != NULL) { + autonomousCommand->Cancel(); + } + } + void TeleopPeriodic() { + Scheduler::GetInstance()->Run(); + } + void TestPeriodic() { + lw->Run(); + } +}; +START_ROBOT_CLASS(DentRobot); diff --git a/src/HHBase.cpp b/src/HHBase.cpp deleted file mode 100644 index 0023bc3..0000000 --- a/src/HHBase.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "HHBase.h" -#include -#include -#include -#include -HHBase::HHBase(): - hhbot(new HHRobot()){ - printf("Done\n"); - } -void HHBase::RobotInit(){ -} -void HHBase::DisabledInit(){} -void HHBase::AutonomousInit(){ -} -void HHBase::TeleopInit(){ -} -void HHBase::DisabledContinuous(){} -void HHBase::AutonomousContinuous(){} -void HHBase::TeleopContinuous(){} -void HHBase::DisabledPeriodic(){} -void HHBase::AutonomousPeriodic(){ -} -void HHBase::TeleopPeriodic(){ - hhbot->Handler(); -} -void HHBase::Test(){} -START_ROBOT_CLASS(HHBase); -// vim: ts=2:sw=2:et diff --git a/src/HHBase.h b/src/HHBase.h deleted file mode 100644 index c4e66e2..0000000 --- a/src/HHBase.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __HH_BASE_H__ -#define __HH_BASE_H__ -#include -#include -#include "HHRobot.h" -//Because this is the first header to be included, classes need to be declared here -class HHRobot; -class HHBase : public IterativeRobot{ - private: - HHRobot *hhbot; - public: - HHBase(); - void RobotInit(); - void DisabledInit(); - void AutonomousInit(); - void TeleopInit(); - void DisabledContinuous(); - void AutonomousContinuous(); - void TeleopContinuous(); - void DisabledPeriodic(); - void AutonomousPeriodic(); - void TeleopPeriodic(); - void Test(); -}; -#endif -// vim: ts=2:sw=2:et diff --git a/src/HHRobot.cpp b/src/HHRobot.cpp deleted file mode 100644 index 1020bc1..0000000 --- a/src/HHRobot.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "HHRobot.h" -#include "HHBase.h" -HHRobot::HHRobot(): - hhdrive(new RobotDrive(2,0,3,1)), - gyro(new Gyro(1)), - collector(new DentCollector(4, 5, 6, 7)), - driveStick(new Extreme3dPro(0)){ - hhdrive->SetExpiration(0.1); - hhdrive->SetInvertedMotor(RobotDrive::kFrontRightMotor, true); - hhdrive->SetInvertedMotor(RobotDrive::kRearLeftMotor,true); - } -void HHRobot::Init(){ - printf("Initing\n"); - printf("Code Version: %f\n",0000.1); - gyro->Reset(); -} -//Main function used to handle periodic tasks on the robot -void HHRobot::Handler(){ - const float Kp = 0.3; - if(driveStick->GetJoystickButton(1)==1){ - hhdrive->MecanumDrive_Cartesian(driveStick->GetJoystickAxis("z"), 0, driveStick->GetJoystickAxis("x")); - }else if(driveStick->GetJoystickButton(2)==1){ - hhdrive->MecanumDrive_Cartesian(driveStick->GetJoystickAxis("z"), driveStick->GetJoystickAxis("y"), 0); - }else if(driveStick->GetJoystickButton(3)==1){ - hhdrive->Drive(driveStick->GetJoystickAxis("y"), driveStick->GetJoystickAxis("y")*Kp*-gyro->GetAngle()); - }else{ - hhdrive->MecanumDrive_Cartesian(driveStick->GetJoystickAxis("z"), driveStick->GetJoystickAxis("y"), driveStick->GetJoystickAxis("x")); - } - if(driveStick->GetJoystickButton(11)==1){ - collector->Collect(driveStick->GetThrottle()); - }else if(driveStick->GetJoystickButton(12)==1){ - collector->Collect(-driveStick->GetThrottle()); - }else if(driveStick->GetJoystickButton(9)==1){ - collector->Raise(driveStick->GetThrottle()); - }else if(driveStick->GetJoystickButton(10)==1){ - collector->Raise(-driveStick->GetThrottle()); - }else{ - collector->Rest(); - } - SmartDashboard::PutNumber("hambone1", driveStick->GetThrottle()); - SmartDashboard::PutNumber("hambone2", driveStick->GetJoystickAxis("joystick")); - SmartDashboard::PutNumber("hambone3", driveStick->GetRawJoystickAxis(3)); - printf("hambone2: %f", driveStick->GetThrottle()); - Wait(0.005); -} -// vim: ts=2:sw=2:et diff --git a/src/HHRobot.h b/src/HHRobot.h deleted file mode 100644 index f6dc004..0000000 --- a/src/HHRobot.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __ROBOT_H__ -#define __ROBOT_H__ -#include -#include "HHBase.h" -#include "classes/Collector.h" -#include "hhlib/input/controller/Joystick.h" -class HHRobot{ - private: - RobotDrive *hhdrive; - Gyro *gyro; - DentCollector *collector; - Extreme3dPro *driveStick; - public: - HHRobot(); - void Init(); - void Handler(); -}; -#endif -// vim: ts=2:sw=2:et diff --git a/src/OI.cpp b/src/OI.cpp new file mode 100644 index 0000000..8425006 --- /dev/null +++ b/src/OI.cpp @@ -0,0 +1,4 @@ +#include "OI.h" + +OI::OI() { +} diff --git a/src/OI.h b/src/OI.h new file mode 100644 index 0000000..51aef6e --- /dev/null +++ b/src/OI.h @@ -0,0 +1,12 @@ +#ifndef OI_H +#define OI_H + +#include "WPILib.h" + +class OI +{ +private: +public: + OI(); +}; +#endif diff --git a/src/RobotMap.h b/src/RobotMap.h new file mode 100644 index 0000000..11d078f --- /dev/null +++ b/src/RobotMap.h @@ -0,0 +1,6 @@ +#ifndef ROBOTMAP_H +#define ROBOTMAP_H + +#include "WPILib.h" + +#endif diff --git a/src/Subsystems/Collector.cpp b/src/Subsystems/Collector.cpp new file mode 100644 index 0000000..7cf0192 --- /dev/null +++ b/src/Subsystems/Collector.cpp @@ -0,0 +1,7 @@ +#include "ExampleSubsystem.h" +#include "../RobotMap.h" + +ExampleSubsystem::ExampleSubsystem() : Subsystem("ExampleSubsystem") { +} +void ExampleSubsystem::InitDefaultCommand() { +} diff --git a/src/Subsystems/Collector.h b/src/Subsystems/Collector.h new file mode 100644 index 0000000..b9b6c45 --- /dev/null +++ b/src/Subsystems/Collector.h @@ -0,0 +1,13 @@ +#ifndef COLLECTOR_H +#define COLLECTOR_H + +#include "Commands/Subsystem.h" +#include "WPILib.h" +class Collector: public Subsystem +{ +private: +public: + ExampleSubsystem(); + void InitDefaultCommand(); +}; +#endif diff --git a/src/classes/Collector.cpp b/src/classes/Collector.cpp deleted file mode 100644 index 919158c..0000000 --- a/src/classes/Collector.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "Collector.h" -DentCollector::DentCollector(int fl, int fr, int rl, int rr){ - collectorLeft = new Talon(fl); - collectorRight = new Talon(fr); - raiserLeft = new Talon(rl); - raiserRight = new Talon(rr); -} -void DentCollector::Collect(float power){ - collectorLeft->Set(power); - collectorRight->Set(power); -} -void DentCollector::Raise(float power){ - raiserLeft->Set(power); - raiserRight->Set(power); -} -void DentCollector::Rest(){ - raiserLeft->Set(0); - raiserRight->Set(0); - collectorLeft->Set(0); - collectorRight->Set(0); -} -// vim: ts=2:sw=2:et diff --git a/src/classes/Collector.h b/src/classes/Collector.h deleted file mode 100644 index f112d0a..0000000 --- a/src/classes/Collector.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __COLLECTOR_H__ -#include -#define __COLLECTOR_H__ -//#include "" -class DentCollector{ - private: - Talon *collectorLeft, *collectorRight, *raiserLeft, *raiserRight; - public: - DentCollector(int, int, int, int); - void Collect(float); - void Raise(float); - void Rest(); -}; -#endif -// vim: ts=2:sw=2:et diff --git a/src/hhlib b/src/hhlib deleted file mode 160000 index 38a965d..0000000 --- a/src/hhlib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 38a965dd1f7c6737f722f56c0f7940805ece9917