This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainProgram.cpp
179 lines (144 loc) · 4.56 KB
/
MainProgram.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "WPILib.h"
#include "ControlBoard.h"
#include "DriveController.h"
#include "CameraController.h"
#include "AutonomousController.h"
#include "ShooterController.h"
#include "RobotModel.h"
#include "Debugging.h"
#include "DSLCDPrinter.h"
// The MainProgram that is linked into the FRC code
class MainProgram : public IterativeRobot {
public:
RemoteController *humanControl;
RobotModel *robot;
CameraController *cameraController;
AutonomousController *autoController;
DriveController *driveController;
ShooterController *shooterController;
// ADXL345_I2C *accel;
DSLCDPrinter *dsLCDPrinter;
LiveWindow *lw;
double currTimeSec;
double lastTimeSec;
double deltaTimeSec;
MainProgram(void) {
// constructor
robot = new RobotModel();
humanControl = new ControlBoard(robot);
driveController = new DriveController(robot, humanControl);
cameraController = new CameraController(robot, humanControl);
shooterController = new ShooterController(robot, humanControl);
autoController = new AutonomousController(robot, cameraController, shooterController);
// accel = new ADXL345_I2C(1/*,DataFormat_Range(kRange_2G*/);
dsLCDPrinter = new DSLCDPrinter(robot->dsLCD);
dsLCDPrinter->AddLCDMessage(new RobotModelLCDMessage(robot));
dsLCDPrinter->AddLCDMessage(new CameraControllerLCDMessage(cameraController));
lw = LiveWindow::GetInstance();
currTimeSec = 0.0;
lastTimeSec = 0.0;
deltaTimeSec = 0.0;
SetPeriod(0.01);
}
void RobotInit(void) {
//lw is live window on drive station
lw->AddSensor("Gyro", "Gyro angle", robot->gyro);
lw->AddSensor("Right Encoder", "Right encoder val",
robot->rightWheelEncoder);
lw->AddSensor("Left Encoder", "Left encoder val",
robot->leftWheelEncoder);
robot->EnableCompressor();
robot->ResetGyro();
robot->ResetEncoder(robot->leftWheelEncoder);
robot->ResetEncoder(robot->rightWheelEncoder);
robot->ResetTimer();
}
void DisabledInit(void) {
// Actions that are performed once as soon as the robot becomes disabled
driveController->Reset();
#ifdef USE_CAMERA
cameraController->Reset(); // to be completed
#endif
autoController->Reset();
shooterController->Reset();
}
void AutonomousInit(void) {
// Actions that are performed once as soon as the autonomous period begins
RefreshAllIni();
robot->ResetGyro();
robot->ResetEncoder(robot->leftWheelEncoder);
robot->ResetEncoder(robot->rightWheelEncoder);
robot->SetWheelSpeed(RobotModel::kBothWheels, 0.0);
robot->ResetTimer();
autoController->Reset();
shooterController->Reset();
#ifdef USE_CAMERA
cameraController->Reset();
#endif
autoController->StartAutonomous();
}
void TeleopInit(void) {
// Actions that are performed once as soon as the teleop period begins
RefreshAllIni();
driveController->Reset();
#ifdef USE_CAMERA
cameraController->Reset();
#endif
shooterController->Reset();
robot->ResetEncoder(robot->leftWheelEncoder);
robot->ResetEncoder(robot->rightWheelEncoder);
robot->ResetGyro();
}
void StateInit(void) {
RobotInit();
DisabledInit();
AutonomousInit();
TeleopInit();
}
void DisabledPeriodic(void) {
// Actions that are performed periodically while the robot is disabled
}
void AutonomousPeriodic(void) {
// Actions that are performed periodically during autonomous
lastTimeSec = currTimeSec;
currTimeSec = robot->timer->Get();
deltaTimeSec = currTimeSec - lastTimeSec;
/*
humanControl->ReadControls();
driveController->Update(currTimeSec, deltaTimeSec);
*/
autoController->Update(currTimeSec, deltaTimeSec);
MATCH_PERIODIC(10, dsLCDPrinter->Update());
}
void TeleopPeriodic(void) {
// Actions that are performed periodically during teleop
lastTimeSec = currTimeSec;
currTimeSec = robot->timer->Get();
deltaTimeSec = currTimeSec - lastTimeSec;
humanControl->ReadControls();
driveController->Update(currTimeSec, deltaTimeSec);
shooterController->Update(currTimeSec, deltaTimeSec);
#ifdef USE_CAMERA
cameraController->Update(currTimeSec, deltaTimeSec);
#endif
MATCH_PERIODIC(10, dsLCDPrinter->Update());
}
void TestPeriodic() {
lw->Run();
//Actions that are performed periodically during test mode
MATCH_PERIODIC(10, dsLCDPrinter->Update());
}
void RefreshAllIni() {
robot->RefreshIni();
enableDoPeriodic = robot->pini->geti("DEBUGGING", "enableDoPeriodic", 1);
if (enableDoPeriodic == 1) {
printf("DO_PERIODIC is enabled\n");
} else printf("DO_PERIODIC is disabled\n");
autoController->RefreshIni();
shooterController->RefreshIni();
#ifdef USE_CAMERA
cameraController->RefreshIni();
#endif
}
};
START_ROBOT_CLASS(MainProgram);