-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShooter.cpp
More file actions
144 lines (126 loc) · 3.92 KB
/
Shooter.cpp
File metadata and controls
144 lines (126 loc) · 3.92 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
#include "Shooter.h"
#include "WPIlib.h"
#include <fstream>
#include <iomanip>
Shooter::Shooter(int CANJagTOP, int CANJagBOTTOM, int solenoid1, int solenoid2)
{
top = new CANJaguar(CANJagTOP);
bottom = new CANJaguar(CANJagBOTTOM);
sol = new DoubleSolenoid(solenoid1,solenoid2);
this->ResetCanJags();
shooterPosition = false;
OldTop = 0;
OldBot = 0;
}
void Shooter::ResetCanJags()
{
SetUpCANJaguar(top);
SetUpCANJaguar(bottom);
}
void Shooter::LogHeaders(ofstream &fout)
{
fout<< "TopShooter Target,";
fout<< "TopShooter Actual,";
fout<< "TopShooter Voltage,";
fout<< "TopShooter Current,";
fout<< "TopShooter Fault,";
fout<< "BottomShooter Target,";
fout<< "BottomShooter Actual,";
fout<< "BottomShooter Voltage,";
fout<< "BottomShooter Current,";
fout << "BottomShooter Fault,";
fout<< "Shooter Solenoid,";
}
void Shooter::LogMotors(ofstream &fout)
{
fout<< top->Get()<< ",";
fout<< top->GetSpeed()<< ",";
fout<< top->GetOutputVoltage()<< ",";
fout<< top->GetOutputCurrent()<< ",";
fout<< top->GetFaults() << ",";
fout<< bottom->Get()<< ",";
fout<< bottom->GetSpeed()<< ",";
fout<< bottom->GetOutputVoltage()<< ",";
fout<< bottom->GetOutputCurrent()<< ",";
fout << bottom->GetFaults() << ",";
fout<< int(GetPosition())<<",";
}
void Shooter::SetPosition(bool upbutton, bool downbutton)
{
//position == true : 80 degree
//position == false : 45 degrees
if(upbutton)
{
sol->Set(DoubleSolenoid::kReverse);
shooterPosition = true;
}
else if(downbutton)
{
sol->Set(DoubleSolenoid::kForward);
shooterPosition = false;
}
else
{
sol->Set(DoubleSolenoid::kOff);
}
}
bool Shooter::GetPosition()
{
return shooterPosition;
}
void Shooter::SetWheelSpeed(double top_RPM, double bottom_RPM)
{
RateLimit(top_RPM,bottom_RPM);
top->Set(top_RPM);
bottom->Set(bottom_RPM);
//cout << "Shooter: " << top_RPM << " " << bottom_RPM << endl;
}
void Shooter::RateLimit(double &TopAxis, double &BotAxis)
{
const double SHOOTER_MAX_RATE = (Config::GetSetting("Shooter_SetPointRateLimit",125));
if(TopAxis > (OldTop+SHOOTER_MAX_RATE))
TopAxis = OldTop+SHOOTER_MAX_RATE;
else if(TopAxis < (OldTop-SHOOTER_MAX_RATE))
TopAxis = OldTop-SHOOTER_MAX_RATE;
if(BotAxis > (OldBot+SHOOTER_MAX_RATE))
BotAxis = OldBot+SHOOTER_MAX_RATE;
else if(BotAxis < (OldBot-SHOOTER_MAX_RATE))
BotAxis = OldBot-SHOOTER_MAX_RATE;
OldTop = TopAxis;
OldBot = BotAxis;
}
void Shooter::ManualControl(double tAxis, double bAxis) {
int shooter_increment = (int) Config::GetSetting("Shooter_Wheel_Increment",100);
double top_speed = (1.0-((1.0 + tAxis)/2.0)) * Shooter_MAX_SPEED;
double bot_speed = (1.0-((1.0 + bAxis)/2.0)) * Shooter_MAX_SPEED;
int wheel_speed_processed_top = (int)top_speed;
int wheel_speed_processed_bot = (int)bot_speed;
// Chomp off speeds
wheel_speed_processed_top /= shooter_increment;
wheel_speed_processed_top *= shooter_increment;
wheel_speed_processed_bot /= shooter_increment;
wheel_speed_processed_bot *= shooter_increment;
float top_wheel, bottom_wheel;
top_wheel = (float) wheel_speed_processed_top;
bottom_wheel = (float) wheel_speed_processed_bot;
SetWheelSpeed(top_wheel,bottom_wheel);
//cout<<"Top Wheel:"<< setw(10)<< top_wheel << " Bottom Wheel:" << setw(10) << bottom_wheel << endl;
}
void Shooter::ManualControl(double zAxis)
{
// With only one speed, set to both
ManualControl(zAxis, zAxis);
}
void Shooter::SetUpCANJaguar(CANJaguar* motor)
{
for (int i = 0; i < 10; ++i) {
motor->ChangeControlMode(CANJaguar::kSpeed);
motor->SetSpeedReference(CANJaguar::kSpeedRef_QuadEncoder);
motor->ConfigEncoderCodesPerRev(int(LINES_PER_REV));
motor->SetPID(ShooterKP,ShooterKI,ShooterKD);
motor->ConfigNeutralMode(CANJaguar::kNeutralMode_Coast);
motor->EnableControl(0.0);
if (motor->GetSpeedReference() == CANJaguar::kSpeedRef_QuadEncoder)
break;
}
}