-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFireControl.cpp
71 lines (56 loc) · 1.72 KB
/
FireControl.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
#include <iostream>
#include "FireControl.h"
#include "Target.h"
#include "Config.h"
#include <fstream>
using namespace std;
FireControl::FireControl()
{
m_range = new LookupTable(1100, Config::GetSetting("Shooter_MAX_SPEED", 2500));
m_alt_range = new LookupTable(Config::GetSetting("Shooter_ALT_SPEED", 100), Config::GetSetting("Shooter_ALT_SPEED", 100));
}
void FireControl::ParseIntoLookup(LookupTable * lt, std::string fname)
{
// Input stream
ifstream in;
// Open the file
in.open(fname.c_str(), std::ios_base::in);
lt->Clear();
if (!in.is_open()) {
cout << "UH OH! CAN'T LOAD RANGE FILE" << endl;
}
float x, y;
while (in >> x >> y) {
cout << "At " << x << " feet, rpm = " << y << endl;
lt->AddEntry(x,y);
}
in.close();
}
void FireControl::LoadRangeDataFromFile(std::string fname) {
ParseIntoLookup(m_range, fname);
}
void FireControl::LoadAltRangeDataFromFile(std::string fname)
{
ParseIntoLookup(m_alt_range, fname);
}
void FireControl::Calculate(Target *t,bool &position,int &top_rpm,int &bot_rpm)
{
double distance = t->getDistance();
double up_threshold = (Config::GetSetting("Shooter_Switch_Up",20));
double down_threshold = (Config::GetSetting("Shooter_Switch_Down",15));
//position == true : 80 degree === DOWN
//position == false : 45 degrees === UP
if(distance > up_threshold)
{
position = true;
}
else if(distance < down_threshold)
{
position = false;
}
double speed = m_range->Lookup(distance);
cout << "Calculated range for distance " << distance << " to be " << speed << endl;
double shooterspin = Config::GetSetting("Shooter_Spin",0);
bot_rpm = (int) speed;
top_rpm = (int) (bot_rpm - shooterspin);
}