forked from Team612/612-2014
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShooter.cpp
148 lines (131 loc) · 2.77 KB
/
Shooter.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
#include "Shooter.h"
#include "612.h"
#include "main.h"
#include "SmoothJoystick.h"
const float Shooter::SPEED_AXISPOWER = 0.5f;
Shooter::Shooter(uint8_t axisMod,
uint8_t attractMod, uint32_t attractChan,
uint8_t clampMod, uint32_t clampFChan, uint32_t clampRChan,
uint32_t sjPort,
int potSlot, int potChan, double potScale, double potOffset)
{
axis = new CANJaguar(axisMod);
attractor = new Talon(attractMod, attractChan);
clamper = new DoubleSolenoid(clampMod, clampFChan, clampRChan);
shooterJoy = new SmoothJoystick(sjPort);
robot -> gunnerJoy -> addJoyFunctions(&buttonHelper,(void*)this,CLAMP_UP);
robot -> gunnerJoy -> addJoyFunctions(&buttonHelper,(void*)this,CLAMP_DOWN);
robot -> update -> addFunctions(&updateHelper, (void*)this);
pot = new AnalogPotentiometer(potSlot, potChan, potScale, potOffset);
printf("Shooters have been updated\n");
}
Shooter::~Shooter()
{
delete axis;
delete attractor;
delete clamper;
}
void Shooter::pitchUp()
{
axis->Set(SPEED_AXISPOWER);
}
void Shooter::pitchDown()
{
axis->Set(-SPEED_AXISPOWER);
}
void Shooter::pitchStop()
{
axis->Set(0);
}
void Shooter::pitchAngle(double angle)
{
if (angle > 0)
{
pitchUp();
if (currentAng >= angle){
pitchStop();
}
}
if (angle < 0)
{
pitchDown();
if (currentAng <= angle){
pitchStop();
}
}
}
void Shooter::pull()
{
attractor->Set(SPEED_ATTRACTOR);
}
void Shooter::pullStop()
{
attractor->Set(0);
}
//@param goClamp moves clamper, off says to stop clamper
void Shooter::autoClamp()
{
if(clamp == up)
{
clampDown();
}
else
{
clampUp();
}
}
void Shooter::clampDown()
{
pneumatics->setVectorValues(TIME, clamper, DoubleSolenoid::kForward);
pull();
clamp = down;
}
void Shooter::clampUp()
{
pneumatics->setVectorValues(TIME, clamper, DoubleSolenoid::kReverse);
pullStop();
clamp = up;
}
//A for down, Y for clamp up, X to fire
void Shooter::buttonHelper(void* objPtr, uint32_t button){
Shooter* shooterObj=(Shooter*)objPtr;
if(button == CLAMP_UP)
{
shooterObj->clampUp();
}
else if(button == CLAMP_DOWN)
{
shooterObj->clampDown();
}
}
void Shooter::update()
{
currentAng = pot -> Get();
if(shooterJoy -> GetTriggerState() == TRIG_L)
{
pitchUp();
}
else if(shooterJoy -> GetTriggerState() == TRIG_R)
{
pitchDown();
}
else
{
pitchStop();
}
if(shooterJoy -> GetSmoothButton(PICKUP))
{
clampDown();
pitchAngle(-23);
}
else
{
clampUp();
pitchAngle(65432);
}
}
void Shooter::updateHelper(void* instName)
{
Shooter* shooterObj = (Shooter*)instName;
shooterObj -> update();
}