mirror of
https://github.com/team2059/Dent
synced 2024-12-18 20:52:29 -05:00
Started working on command based robot (does not work)
This commit is contained in:
parent
ba21daae67
commit
88ec9d5248
25
src/CommandBase.cpp
Normal file
25
src/CommandBase.cpp
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
|
20
src/CommandBase.h
Normal file
20
src/CommandBase.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef COMMAND_BASE_H
|
||||||
|
#define COMMAND_BASE_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#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
|
39
src/DentRobot.cpp
Normal file
39
src/DentRobot.cpp
Normal file
@ -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);
|
@ -1,28 +0,0 @@
|
|||||||
#include "HHBase.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <map>
|
|
||||||
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
|
|
26
src/HHBase.h
26
src/HHBase.h
@ -1,26 +0,0 @@
|
|||||||
#ifndef __HH_BASE_H__
|
|
||||||
#define __HH_BASE_H__
|
|
||||||
#include <WPILib.h>
|
|
||||||
#include <string>
|
|
||||||
#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
|
|
@ -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
|
|
@ -1,19 +0,0 @@
|
|||||||
#ifndef __ROBOT_H__
|
|
||||||
#define __ROBOT_H__
|
|
||||||
#include <WPILib.h>
|
|
||||||
#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
|
|
4
src/OI.cpp
Normal file
4
src/OI.cpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#include "OI.h"
|
||||||
|
|
||||||
|
OI::OI() {
|
||||||
|
}
|
12
src/OI.h
Normal file
12
src/OI.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef OI_H
|
||||||
|
#define OI_H
|
||||||
|
|
||||||
|
#include "WPILib.h"
|
||||||
|
|
||||||
|
class OI
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
public:
|
||||||
|
OI();
|
||||||
|
};
|
||||||
|
#endif
|
6
src/RobotMap.h
Normal file
6
src/RobotMap.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef ROBOTMAP_H
|
||||||
|
#define ROBOTMAP_H
|
||||||
|
|
||||||
|
#include "WPILib.h"
|
||||||
|
|
||||||
|
#endif
|
7
src/Subsystems/Collector.cpp
Normal file
7
src/Subsystems/Collector.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "ExampleSubsystem.h"
|
||||||
|
#include "../RobotMap.h"
|
||||||
|
|
||||||
|
ExampleSubsystem::ExampleSubsystem() : Subsystem("ExampleSubsystem") {
|
||||||
|
}
|
||||||
|
void ExampleSubsystem::InitDefaultCommand() {
|
||||||
|
}
|
13
src/Subsystems/Collector.h
Normal file
13
src/Subsystems/Collector.h
Normal file
@ -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
|
@ -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
|
|
@ -1,15 +0,0 @@
|
|||||||
#ifndef __COLLECTOR_H__
|
|
||||||
#include <WPILib.h>
|
|
||||||
#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
|
|
@ -1 +0,0 @@
|
|||||||
Subproject commit 38a965dd1f7c6737f722f56c0f7940805ece9917
|
|
Loading…
Reference in New Issue
Block a user