-
Notifications
You must be signed in to change notification settings - Fork 0
/
Robot.cpp
151 lines (127 loc) · 5 KB
/
Robot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
*
* $$$$$$$$\ $$\ $$$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\
* \__$$ __| \__|$$ _____| $$ ___$$\ $$ __$$\ $$ ___$$\ $$ __$$\
* $$ | $$$$$$\ $$\ $$ | $$$$$$\ $$$$$$\ $$$$$$$\ $$$$$$\ \_/ $$ |\__/ $$ |\_/ $$ |$$ / \__|
* $$ |$$ __$$\ $$ |$$$$$\ $$ __$$\ $$ __$$\ $$ _____|$$ __$$\ $$$$$ / $$$$$$ | $$$$$ / $$$$$$$\
* $$ |$$ | \__|$$ |$$ __|$$ / $$ |$$ | \__|$$ / $$$$$$$$ | \___$$\ $$ ____/ \___$$\ $$ __$$\
* $$ |$$ | $$ |$$ | $$ | $$ |$$ | $$ | $$ ____| $$\ $$ |$$ | $$\ $$ |$$ / $$ |
* $$ |$$ | $$ |$$ | \$$$$$$ |$$ | \$$$$$$$\ \$$$$$$$\ \$$$$$$ |$$$$$$$$\ \$$$$$$ | $$$$$$ |
* \__|\__| \__|\__| \______/ \__| \_______| \_______| \______/ \________| \______/ \______/
*
* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*
* Lead Programmer: Eric Bernard
* Programmer's Assistants:
* + John Winship
* + Antonio Figueiredo
* + Kevin Kohls
*
* Thanks to all the teams who helped us
* out via email and through ChiefDelphi!
*
*/
//I just wanna see shweg. -Kevin, 2k17.
#include <Commands/AutoDriveAtPegFromLeft.h>
#include <Commands/AutoDriveAtPegFromRight.h>
#include <memory>
#include <Commands/Command.h>
#include <Commands/Scheduler.h>
#include <IterativeRobot.h>
#include <LiveWindow/LiveWindow.h>
#include <SmartDashboard/SendableChooser.h>
#include <SmartDashboard/SmartDashboard.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
//Include all the commands//
#include "Subsystems/Debug.h"
#include "Commands/TeleopDefault.h"
#include "Commands/DropGear.h"
#include "Commands/PushGear.h"
#include "Commands/DoNothing.h"
#include "Commands/AutoDrive.h"
#include "Commands/AutoDriveAtPeg.h"
#include "Commands/AutoDriveAtPegFromLeft.h"
#include "Commands/AutoDriveAtPegFromRight.h"
#include "Commands/AutoDriveFromLeftNV.h"
#include "Commands/AutoDriveFromRightNV.h"
#include "CommandBase.h"
using namespace frc;
using namespace std;
double Debug = false;
class Robot: public IterativeRobot {
private:
SendableChooser<Command*> autonomousChooser;
SendableChooser<Command*> teleopChooser;
unique_ptr<Command> autonomousMode;
unique_ptr<Command> teleopMode;
Command* teleopDefault;
Command* autoDefault;
static void VisionThread() {
cs::UsbCamera camera = CameraServer::GetInstance()->StartAutomaticCapture();
camera.SetBrightness(20);
if (camera.IsConnected()) {
camera.SetResolution(640,480);
camera.SetFPS(60);
cs::CvSink cvSink = CameraServer::GetInstance()->GetVideo();
cs::CvSource outputStreamStd = CameraServer::GetInstance()->PutVideo("Color", 640, 480);
cv::Mat source;
cv::Mat output;
while (true) {
cvSink.GrabFrame(source);
cvtColor(source, output, cv::COLOR_BGR2RGB);
outputStreamStd.PutFrame(output);
}
}
}
public:
void RobotInit() override {
CommandBase::init(); //Initializes all commands and subsystems
//Moved to down here because sometimes the SmartDashboard forgets to add them.
std::thread visionThread(VisionThread);
visionThread.detach();
}
void DisabledInit() override {
CommandBase::debug->ResetTracking();
frc::Scheduler::GetInstance()->ResetAll();
frc::Scheduler::GetInstance()->RemoveAll();
teleopChooser.AddDefault("Default Driver", new TeleopDefault());
autonomousChooser.AddDefault("Drive at Peg (center) [NV]", new AutoDrive());
autonomousChooser.AddObject("Drive at Peg (left) [NV]", new AutoDriveFromLeftNV());
autonomousChooser.AddObject("Drive at Peg (right) [NV]", new AutoDriveFromRightNV());
autonomousChooser.AddObject("Drive at Peg (center) [VT]", new AutoDriveAtPeg());
SmartDashboard::PutData("Autonomous Modes", &autonomousChooser);
SmartDashboard::PutData("Teleoperated Modes", &teleopChooser);
}
void AutonomousInit() override {
CommandBase::debug->StartTracking();
CommandBase::debug->Enable();
autonomousMode.release(); //RELINQUISH THE AUTONOMOUS!
autonomousMode.reset(autonomousChooser.GetSelected());
if (autonomousMode != nullptr) {
autonomousMode->Start();
CommandBase::debug->LogWithTime("AutoInit", "Starting autonomous program...");
} else {
CommandBase::debug->LogWithTime("AutoInit", "Autonomous program could not start.");
}
}
void AutonomousPeriodic() override {
frc::Scheduler::GetInstance()->Run();
}
void TeleopInit() override {
CommandBase::debug->StartTracking();
CommandBase::debug->Enable();
teleopMode.release(); //RELINQUISH THE TELEOP!
teleopMode.reset(teleopChooser.GetSelected());
if (teleopMode != nullptr) {
CommandBase::debug->LogWithTime("TeleopInit", "Starting teleop program...");
teleopMode->Start();
} else {
CommandBase::debug->LogWithTime("TeleopInit", "Teleop program could not start.");
}
}
void TeleopPeriodic() override {
frc::Scheduler::GetInstance()->Run();
}
};
START_ROBOT_CLASS(Robot);