-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarControl.cpp
167 lines (142 loc) · 3.62 KB
/
CarControl.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/***************************************************************************
file : CarControl.cpp
copyright : (C) 2007 Daniele Loiacono
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "CarControl.h"
// meta-command value for race restart
int CarControl::META_RESTART=1;
CarControl::CarControl(float accel, float brake, int gear, float steer, float clutch, int focus, int meta)
{
this->accel = accel;
this->brake = brake;
this->gear = gear;
this->steer = steer;
this->clutch = clutch;
this->focus = focus;
this->meta = meta;
}
CarControl::CarControl(float accel, float brake, int gear, float steer, float clutch, int focus)
{
this->accel = accel;
this->brake = brake;
this->gear = gear;
this->steer = steer;
this->clutch = clutch;
this->focus = focus;
this->meta = 0;
}
CarControl::CarControl(string sensors)
{
fromString(sensors);
}
string
CarControl::toString()
{
string str;
str = SimpleParser::stringify("accel", accel);
str += SimpleParser::stringify("brake", brake);
str += SimpleParser::stringify("gear", gear);
str += SimpleParser::stringify("steer", steer);
str += SimpleParser::stringify("clutch", clutch);
str += SimpleParser::stringify("focus", focus);
str += SimpleParser::stringify("meta", meta);
return str;
}
void
CarControl::fromString(string sensors)
{
if (SimpleParser::parse(sensors, "accel", accel)==false)
accel=0.0;
if (SimpleParser::parse(sensors, "brake", brake)==false)
brake=0.0;
if (SimpleParser::parse(sensors, "gear", gear)==false)
gear=1;
if (SimpleParser::parse(sensors, "steer", steer)==false)
steer=0.0;
if (SimpleParser::parse(sensors, "clutch", clutch)==false)
clutch=0.0;
if (SimpleParser::parse(sensors, "meta", meta)==false)
meta=0;
if (SimpleParser::parse(sensors, "focus", focus)==false) //ML
focus=0; //ML
if (focus < -90 || focus > 90)//ML What to do with focus requests out of allowed range?
focus=360;//ML A value of 360 is used for not requesting focus readings; -1 is returned as focus reading to the client
}
float
CarControl::getAccel() const
{
return this->accel;
};
void
CarControl::setAccel (float accel)
{
this->accel = accel;
};
float
CarControl::getBrake() const
{
return this->brake;
};
void
CarControl::setBrake (float brake)
{
this->brake = brake;
};
int
CarControl::getGear() const
{
return this->gear;
};
void
CarControl::setGear(int gear)
{
this->gear = gear;
};
float
CarControl::getSteer() const
{
return this->steer;
};
void
CarControl::setSteer(float steer)
{
this->steer = steer;
};
int
CarControl::getMeta() const
{
return this->meta;
};
void
CarControl::setMeta(int meta)
{
this->meta = meta;
};
float
CarControl::getClutch() const
{
return clutch;
}
void
CarControl::setClutch(float clutch)
{
this->clutch = clutch;
}
int
CarControl::getFocus()
{
return this->focus;
};
void
CarControl::setFocus(int focus)
{
this->focus = focus;
};