-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShooterSubsystem.cpp
More file actions
165 lines (136 loc) · 3.72 KB
/
ShooterSubsystem.cpp
File metadata and controls
165 lines (136 loc) · 3.72 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
#include "WPILib.h"
#include "PinDefinitions.h"
#include "Pneumatic.cpp"
#include "Potentiometer.cpp"
inline float fabs (float a)
{
return (a<0 ? -a : a);
}
inline float sign (float a)
{
return (a<0 ? -1.0 : 1.0);
}
inline void primeTaskFunc(UINT32 motorLockPistonPtr, UINT32 ratchetPistonPtr, UINT32 winchPtr, UINT32 winchLimitSwitchPtr, UINT32 joystickCancelPtr, UINT32 joystickButtonInt, ...)
{
Pneumatic *motorLockPiston = (Pneumatic *) motorLockPistonPtr;
Pneumatic *ratchetPiston = (Pneumatic *) ratchetPistonPtr;
Relay *winch = (Relay *) winchPtr;
DigitalInput *winchLimitSwitch = (DigitalInput *) winchLimitSwitchPtr;
Joystick *joystickCancel = (Joystick *) joystickCancelPtr;
ratchetPiston->Set(true); // This order is important
motorLockPiston->Set(true);
Wait(.25);
winch->Set(Relay::kReverse);
//while the winch hasn't hit the limit.
while ( winchLimitSwitch->Get() == false && joystickCancel->GetRawButton(9) == false)
{
SmartDashboard::PutBoolean("WINCH SWITCH DEBUG", winchLimitSwitch->Get());
//printf("in loop \n");
}
SmartDashboard::PutBoolean("WINCH SWITCH DEBUG", winchLimitSwitch->Get());
printf("out of loop \n");
winch->Set(Relay::kOff);
Wait(.5);
motorLockPiston->Set(false);
Wait(.25);
}
class Shooter {
Relay winch;
DigitalInput winchLimitSwitch;
Pneumatic motorLockPiston; // Engages motor
Pneumatic ratchetPiston; // Engages ratchet
Talon arm;
DigitalInput armBackLimitSwitch;
DigitalInput armFrontLimitSwitch;
//Potentiometer armPot;
Task primeTask;
public:
Shooter () :
winch (SHOOTER_WINCH_SPIKE),
winchLimitSwitch (SHOOTER_WINCHLIMITSWITCH),
motorLockPiston (SHOOTER_WINCHMOTORSOLIN, SHOOTER_WINCHMOTORSOLOUT),
ratchetPiston (SHOOTER_WINCHRATCHSOLIN, SHOOTER_WINCHRATCHSOLOUT),
arm (SHOOTER_ARMTALON),
armBackLimitSwitch (SHOOTER_ARMLIMITSWITCHBACK),
armFrontLimitSwitch (SHOOTER_ARMLIMITSWITCHFRONT),
//armPot (SHOOTER_ARMPOT),
primeTask ("Prime", (FUNCPTR) primeTaskFunc)
{ }
void Prime(Joystick *joystickCancel, UINT32 joystickCancelButton)
{
primeTask.Start((UINT32) &motorLockPiston, (UINT32) &ratchetPiston, (UINT32) &winch, (UINT32) &winchLimitSwitch, (UINT32) joystickCancel, joystickCancelButton);
}
void SetRatchet (bool state) {
ratchetPiston.Set(state);
}
/*void moveTo(int position) {
// back is low
// forward is high
int sign;
double targetV;
if (position == ANGLE_AUTO) {
targetV = 3.83;
sign = ((GetVoltage() - targetV) < 0) ? 1 : -1;
}
if (sign > 0) { // need to move forwards
while (GetVoltage() < targetV) {
MoveArm(sign*.4);
//WatchdogFeed();
Wait(0.01);
}
} else if (sign < 0) {
while (GetVoltage() > targetV) {
MoveArm(sign*.4);
Wait(.01);
}
}
MoveArm(0);
}*/
/*double GetVoltage () {
return armPot.GetVoltage();
}*/
bool Cancel()
{
return primeTask.Stop();
}
void Fire()
{
if (primeTask.GetID() + 1)
{
return;
}
ratchetPiston.Set(false); // fire.
Wait(0.1);
}
/*float GetAngle()
{
return armPot.Get()*160.0 + 20.0;
}*/
void MoveArm(float power)
{
SmartDashboard::PutBoolean("BACK SWITCH", armBackLimitSwitch.Get());
SmartDashboard::PutBoolean("FRONT SWITCH", armFrontLimitSwitch.Get());
SmartDashboard::PutBoolean("WINCH SWITCH 2", winchLimitSwitch.Get());
if ((armBackLimitSwitch.Get() && power<0.0) || (armFrontLimitSwitch.Get() && power>0.0))
{
arm.Set(0);
}
else
{
arm.Set(power);
}
}
/*void Calibrate()
{
arm.Set(0.8); //TODO: make sure this is the right direction!
while (!armFrontLimitSwitch.Get())
{ }
arm.Set(0.0);
armPot.CalibrateStart();
arm.Set(-0.8); //TODO: make sure this is the right direction!
while (!armBackLimitSwitch.Get())
{ }
arm.Set(0.0);
armPot.CalibrateEnd();
}*/
};