-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyRobot.cpp
More file actions
233 lines (194 loc) · 6.9 KB
/
MyRobot.cpp
File metadata and controls
233 lines (194 loc) · 6.9 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "WPILib.h"
#include "PinDefinitions.h"
#include "Pneumatic.cpp"
#include "DriveSubsystem.cpp"
//#include "NetworkListener.cpp"
#include "ShooterSubsystem.cpp"
#include "PickUpSubsystem.cpp"
#include "Vision.cpp"
#include "pthread.h"
/**
* MyRobot.cpp
* The main class of FRC Team 3941's Aerial Assist robot.
* Subsystems are included by .cpp file because otherwise not all files are
* sent to the robot.
*/
class RobotDemo : public SimpleRobot
{
// CANNOT INITIALIZE THE SAME JAGUAR TWICE!!!!
DriveSubsystem myRobot;
Shooter shooter;
PickUpSubsystem grabber;
Joystick leftStick;
Joystick rightStick;
Joystick operatorStick;
Compressor compressor;
DigitalInput lpswitch;
DigitalInput rpswitch;
AnalogChannel pot;
Encoder leftEncoder;
Vision vision;
//NetworkListener l;
public:
RobotDemo(void):
myRobot(),
shooter(),
grabber(),
leftStick(2),
rightStick(1),
operatorStick(3),
compressor(PRESSURESWITCH_PIN, COMPRELAY_PIN),
lpswitch(DRIVE_LEFTPSWITCH),
rpswitch(DRIVE_RIGHTPSWITCH),
pot(7),
leftEncoder(11, 12, true),
vision()
//l()
{
myRobot.SetExpiration(0.1);
myRobot.SetInvertedMotor(RobotDrive::kFrontLeftMotor, true);
myRobot.SetInvertedMotor(RobotDrive::kRearLeftMotor, true);
myRobot.SetInvertedMotor(RobotDrive::kFrontRightMotor, true);
myRobot.SetInvertedMotor(RobotDrive::kRearRightMotor, true);
}
void LockToLine ()
{
// make sure value is correct
while (lpswitch.Get() == 0 || rpswitch.Get() == 0) { // drive until switch is triggered
myRobot.TankDrive(.3, .3);
}
if (lpswitch.Get() != 0) { // if it hit the left switch first
while (rpswitch.Get() == 0) {
myRobot.TankDrive(0, .3);
}
} else if (rpswitch.Get() != 0) { // if it hit the right switch first
while (lpswitch.Get() == 0) {
myRobot.TankDrive(.3, 0);
}
}
// we are now on the line
}
///////////////////////////////////////////////////////////////
void Autonomous(void)
{
compressor.Start();
leftEncoder.Start();
leftEncoder.Reset();
myRobot.SetSafetyEnabled(false);
double angle = 55;
Wait(.25);
if((pot.GetValue()-608.5)/(-3.566666667)>=angle)
{
while((pot.GetValue()-608.5)/(-3.566666667)>=angle)
{
shooter.MoveArm(1);
}
}
else
{
while((pot.GetValue()-608.5)/(-3.566666667)<=angle)
{
shooter.MoveArm(-1);
}
}
shooter.MoveArm(0);
Wait(.5);
while(leftEncoder.Get()/250*3.14*6/12 < 8){
myRobot.TankDrive(-1, -.9);
}
vision.Process();
while(leftEncoder.Get()/250*3.14*6/12 < 12){
myRobot.TankDrive(-.55, -.5);
}
//Wait(3.2);
myRobot.TankDrive(0, 0);
Wait(.5);
if(!vision.GoalIsHot())
{
Wait(3);
}
shooter.Fire();
/*int resp = l.findtargets();
if (resp == 0) {
SmartDashboard::PutString("Data Recvd", "GOAL IS HOT");
}
*/
compressor.Stop();
}
///////////////////////////////////////////////////////////////
void OperatorControl(void)
{
compressor.Start();
leftEncoder.Start();
leftEncoder.Reset();
myRobot.SetSafetyEnabled(true);
while (IsOperatorControl())
{
SmartDashboard::PutNumber("Potentiometer", (int) (pot.GetValue()-608.5)/(-3.566666667));
SmartDashboard::PutNumber("Encoder", leftEncoder.Get()/250*3.14*6/12);
//printf("loop \n");
myRobot.TankDrive(leftStick, rightStick);
shooter.MoveArm(-operatorStick.GetY());
//shooter.ShowPotentiometer();
// testing controls for the ratchet
if (operatorStick.GetRawButton(11) && operatorStick.GetRawButton(10)) {
shooter.SetRatchet(true);
} else if (operatorStick.GetRawButton(11)) {
shooter.SetRatchet(false);
}
// shooting controls
//printf("shooter buttons \n");
if (operatorStick.GetRawButton(8)) {
printf("GO! \n");
shooter.Prime(&operatorStick, SHOOTER_CANCELBUTTON);
} else if (operatorStick.GetRawButton(1)) {
shooter.Fire();
} /*else if (operatorStick.GetRawButton(11)) {
shooter.Cancel(); // doesn't actually work for some reason
}*/
// grabber arm controls
if (operatorStick.GetRawButton(4)) {
grabber.SetArm(true);
} else if (operatorStick.GetRawButton(5)) {
grabber.SetArm(false);
}
// grabber roller controls
if (operatorStick.GetRawButton(2)) {
grabber.SetRoller(-1);
} else if (operatorStick.GetRawButton(3)) {
grabber.SetRoller(1);
} else {
grabber.SetRoller(0);
}
Wait(0.005); // wait for a motor update time
}
compressor.Stop();
}
///////////////////////////////////////////////////////////////
void Test() {
double angle = 55;
compressor.Start();
while(!compressor.GetPressureSwitchValue())
{
}
compressor.Stop();
if((pot.GetValue()-608.5)/(-3.566666667)>=angle)
{
while((pot.GetValue()-608.5)/(-3.566666667)>=angle)
{
shooter.MoveArm(1);
}
}
else
{
while((pot.GetValue()-608.5)/(-3.566666667)<=angle)
{
shooter.MoveArm(-1);
}
}
shooter.MoveArm(0);
shooter.Prime(&operatorStick, SHOOTER_CANCELBUTTON);
grabber.SetArm(true);
}
};
START_ROBOT_CLASS(RobotDemo);