This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
forked from andybarry/simflight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadSimpleConfigServos.m
202 lines (162 loc) · 4.95 KB
/
ReadSimpleConfigServos.m
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
function [rad_to_servo, servo_to_rad, minmaxtrim] = ReadSimpleConfigServos(filename)
% Reads a .cfg file for bot-param-server and looks for particular fields
disp(['Reading ' filename ' for config info']);
rad_to_servo = struct();
servo_to_rad = struct();
minmaxtrim = struct();
trim = struct();
% check to see if the filename is valid
if ~exist(filename, 'file')
disp([filename ' does not exist, assuming default values from plane #3.']);
rad_to_servo.elevL_slope = 453.9260;
rad_to_servo.elevL_y_intercept = 1.3677e+03;
rad_to_servo.elevR_slope = -512.8210;
rad_to_servo.elevR_y_intercept = 1.4113e+03;
rad_to_servo.throttle_slope = 99.6016;
rad_to_servo.throttle_y_intercept = 1.2122e+03;
servo_to_rad.elevL_slope = 0.0022;
servo_to_rad.elevL_y_intercept = -3.0130;
servo_to_rad.elevR_slope = -0.0019;
servo_to_rad.elevR_y_intercept = 2.7520;
servo_to_rad.throttle_slope = 0.0100;
servo_to_rad.throttle_y_intercept = -12.1700;
minmaxtrim.elevL_min = 1125;
minmaxtrim.elevL_max = 1725;
minmaxtrim.elevR_min = 1150;
minmaxtrim.elevR_max = 1800;
minmaxtrim.throttle_min = 1103;
minmaxtrim.throttle_max = 1744;
minmaxtrim.elevL_trim = 1372;
minmaxtrim.elevR_trim = 1479;
minmaxtrim.throttle_trim = 1103;
minmaxtrim.elevL_flight_trim = 1402;
minmaxtrim.elevR_flight_trim = 1494;
return;
end
current_obj = 1;
file_id = fopen(filename,'r');
tline = fgetl(file_id);
while ischar(tline)
if ~isempty(strfind(tline, 'radians_to_servo'))
current_obj = 1;
elseif ~isempty(strfind(tline, 'servo_to_radians'))
current_obj = 2;
end
value = ReadKeyLine(tline, 'elevL_slope');
if ~isempty(value)
if current_obj == 1
rad_to_servo.elevL_slope = value;
else
servo_to_rad.elevL_slope = value;
end
end
value = ReadKeyLine(tline, 'elevL_y_intercept');
if ~isempty(value)
if current_obj == 1
rad_to_servo.elevL_y_intercept = value;
else
servo_to_rad.elevL_y_intercept = value;
end
end
value = ReadKeyLine(tline, 'elevR_slope');
if ~isempty(value)
if current_obj == 1
rad_to_servo.elevR_slope = value;
else
servo_to_rad.elevR_slope = value;
end
end
value = ReadKeyLine(tline, 'elevR_y_intercept');
if ~isempty(value)
if current_obj == 1
rad_to_servo.elevR_y_intercept = value;
else
servo_to_rad.elevR_y_intercept = value;
end
end
value = ReadKeyLine(tline, 'throttle_slope');
if ~isempty(value)
if current_obj == 1
rad_to_servo.throttle_slope = value;
else
servo_to_rad.throttle_slope = value;
end
end
value = ReadKeyLine(tline, 'throttle_y_intercept');
if ~isempty(value)
if current_obj == 1
rad_to_servo.throttle_y_intercept = value;
else
servo_to_rad.throttle_y_intercept = value;
end
end
value = ReadKeyLine(tline, 'elevL_min');
if ~isempty(value)
minmaxtrim.elevL_min = value;
end
value = ReadKeyLine(tline, 'elevL_max');
if ~isempty(value)
minmaxtrim.elevL_max = value;
end
value = ReadKeyLine(tline, 'elevR_min');
if ~isempty(value)
minmaxtrim.elevR_min = value;
end
value = ReadKeyLine(tline, 'elevR_max');
if ~isempty(value)
minmaxtrim.elevR_max = value;
end
value = ReadKeyLine(tline, 'throttle_min');
if ~isempty(value)
minmaxtrim.throttle_min = value;
end
value = ReadKeyLine(tline, 'throttle_max');
if ~isempty(value)
minmaxtrim.throttle_max = value;
end
value = ReadKeyLine(tline, 'elevL_trim');
if ~isempty(value)
minmaxtrim.elevL_trim = value;
end
value = ReadKeyLine(tline, 'elevR_trim');
if ~isempty(value)
minmaxtrim.elevR_trim = value;
end
value = ReadKeyLine(tline, 'throttle_trim');
if ~isempty(value)
minmaxtrim.throttle_trim = value;
end
value = ReadKeyLine(tline, 'elevL_flight_trim');
if ~isempty(value)
minmaxtrim.elevL_flight_trim = value;
end
value = ReadKeyLine(tline, 'elevR_flight_trim');
if ~isempty(value)
minmaxtrim.elevR_flight_trim = value;
end
%disp(tline)
tline = fgetl(file_id);
end
fclose(file_id);
end
function value = ReadKeyLine(line, key)
% handle comments
comment_loc = strfind(line, '#');
if ~isempty(comment_loc)
line = line(1:comment_loc - 1);
end
str_loc = strfind(line, key);
if ~isempty(str_loc)
eq_loc = strfind(line, '=');
if ~isempty(eq_loc)
str_value = line(eq_loc+1:end);
str_value = strrep(str_value, ';', '');
value = str2double( str_value );
if isnan(value)
error(['Read NaN value on line: "' line '" when looking for key: "' key '"']);
end
end
else
value = [];
end
end