TeensyNanoExoCode
Loading...
Searching...
No Matches
ParseIni.h
Go to the documentation of this file.
1
11#ifndef ParseIni_h
12#define ParseIni_h
13
14// used for uint8_t
15#include <stdint.h>
16
20namespace ini_config
21{
22 const int buffer_length = 500;
23 const int key_length = 25;
24 const int section_length = 10;
25 const int number_of_keys = 17;
26 //const char *config_filename = "/config.ini"; // this line creates an "Error compiling for board Teensy 3.6." so I am just hard coding it.
27}
28
29// Includes for reading the ini file from the SD card.
30// 1 is the lowest value to confirm that data is present for sending over SPI
31
32// TODO: Add Bluetooth name.
33
37namespace config_defs
38{
39 enum class board_name : uint8_t
40 {
41 AK_board = 1,
42 };
43
44 enum class board_version : uint8_t
45 {
46 zero_one = 1,
47 zero_three = 2,
48 zero_four = 3,
49 zero_five_one = 4,
50 };
51
52 enum class battery : uint8_t
53 {
54 smart = 1,
55 dumb = 2,
56 };
57
58 enum class exo_name : uint8_t
59 {
60 bilateral_ankle = 1,
61 bilateral_hip = 2,
63 left_ankle = 4,
64 right_ankle = 5,
65 left_hip = 6,
66 right_hip = 7,
69 test = 10,
70 right_knee = 11,
71 };
72
73 enum class exo_side : uint8_t
74 {
75 bilateral = 1,
76 left = 2,
77 right = 3,
78 };
79
80 enum class JointType
81 {
82 hip = 1,
83 knee = 2,
84 ankle = 3,
85 };
86
87 enum class motor : uint8_t
88 {
89 not_used = 1,
90 AK60 = 2,
91 AK80 = 3,
92 AK60_v1_1 = 4,
93 AK60_v1_1_T = 5,
94 };
95
96 enum class gearing : uint8_t
97 {
98 gearing_1_1 = 1,
99 gearing_2_1 = 2,
100 gearing_3_1 = 3,
101 gearing_4_5_1 = 4,
102 };
103
104
105 enum class joint_id : uint8_t
106 {
107 // byte format : [0, is_left, !is_left, unused_joint, unused_joint, is_ankle, is_knee, is_hip]
108 left = 0b01000000,
109 right = 0b00100000,
110
111 hip = 0b00000001,
112 knee = 0b00000010,
113 ankle = 0b00000100,
114
115 left_hip = left|hip,
118
122 };
123
124 enum class hip_controllers : uint8_t
125 {
126 disabled = 1,
127 zero_torque = 2,
128 heel_toe = 3,
129 extension_angle = 4,
131 bang_bang = 6,
132 late_stance = 7,
133 gait_phase = 8,
134 user_defined = 9,
135 sine = 10,
136 stasis = 11,
137 perturbation = 12,
138 parabolic = 13,
139 constant_torque = 14,
140 ptb_general = 15,
141 };
142
143 enum class knee_controllers : uint8_t
144 {
145 disabled = 1,
146 zero_torque = 2,
147 user_defined = 3,
148 sine = 4,
149 stasis = 5,
150 perturbation = 6,
151 constant_torque = 7,
152 elbow_min_max = 8,
153 };
154
155 enum class ankle_controllers : uint8_t
156 {
157 disabled = 1,
158 zero_torque = 2,
159 pjmc = 3,
160 zhang_collins = 4,
161 user_defined = 5,
162 sine = 6,
163 stasis = 7,
164 perturbation = 8,
165 constant_torque = 9,
166 ptb_general = 10,
167 gasp = 11,
168 elbow_min_max = 12,
169 calibr_manager = 13,
170 };
171
172 enum class flip_dir : uint8_t
173 {
174 neither = 1,
175 left = 2,
176 right = 3,
177 both = 4,
178 };
179
180 static const int board_name_idx = 0;
181 static const int board_version_idx = 1;
182
183 static const int battery_idx = 2;
184
185 static const int exo_name_idx = 3;
186 static const int exo_side_idx = 4;
187
188 static const int hip_idx = 5;
189 static const int knee_idx = 6;
190 static const int ankle_idx = 7;
191
192 static const int hip_gear_idx = 8;
193 static const int knee_gear_idx = 9;
194 static const int ankle_gear_idx = 10;
195
196 static const int exo_hip_default_controller_idx = 11;
197 static const int exo_knee_default_controller_idx = 12;
198 static const int exo_ankle_default_controller_idx = 13;
199
200 static const int hip_flip_dir_idx = 14;
201 static const int knee_flip_dir_idx = 15;
202 static const int ankle_flip_dir_idx = 16;
203
204 static const int hip_flip_motor_dir_idx = 17;
205 static const int knee_flip_motor_dir_idx = 18;
206 static const int ankle_flip_motor_dir_idx = 19;
207
208 static const int hip_flip_torque_dir_idx = 20;
209 static const int knee_flip_torque_dir_idx = 21;
210 static const int ankle_flip_torque_dir_idx = 22;
211
212 static const int hip_flip_angle_dir_idx = 23;
213 static const int knee_flip_angle_dir_idx = 24;
214 static const int ankle_flip_angle_dir_idx = 25;
215}
216
217#if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)
218 #include <SD.h>
219 #include <SPI.h>
220 #include "IniFile.h"
221
222
223
224 // Need to install ArduinoSTL in the library manager to use map
225 #include <map>
226 #include <string>
227
228
229
230 // The select pin used for the SD card
231 #ifndef SD_SELECT
232 #define SD_SELECT BUILTIN_SDCARD
233 #endif
234
235
236
237
238
244 void ini_parser(uint8_t* config_to_send); // uses default filename
245
252 void ini_parser(char* filename, uint8_t* config_to_send); //uses sent filename
253 // TODO: create non-verbose version of get section keys.
254
263 void get_section_key(IniFile ini, const char* section, const char* key, char* buffer, size_t buffer_len);
264
265 /*
266 * ini_print_error_message(uint8_t e, bool eol = true)
267 *
268 * Prints the error messages of IniFile object.
269 * e is the error message, and eol true means a println will be used at the end.
270 *
271 * Requires that Serial is defined.
272 */
281 void ini_print_error_message(uint8_t e, bool eol = true);
282
283
289 namespace config_map
290 {
291
292
293
294 // define our own type so we don't have to type so much
295 typedef std::map<std::string, uint8_t> IniKeyCode;
296
297 const IniKeyCode board_name = {{"AK_Board", (uint8_t)config_defs::board_name::AK_board},};
298 const IniKeyCode board_version =
299 {
300 {"0.1", (uint8_t)config_defs::board_version::zero_one},
303 };
304
305 const IniKeyCode battery =
306 {
307 {"smart", (uint8_t)config_defs::battery::smart},
308 {"dumb", (uint8_t)config_defs::battery::dumb},
309 };
310
311 const IniKeyCode exo_name
312 {
313 {"bilateralAnkle", (uint8_t)config_defs::exo_name::bilateral_ankle},
314 {"bilateralHip", (uint8_t)config_defs::exo_name::bilateral_hip},
315 {"bilateralHipAnkle", (uint8_t)config_defs::exo_name::bilateral_hip_ankle},
316 {"leftAnkle", (uint8_t)config_defs::exo_name::left_ankle},
317 {"rightAnkle", (uint8_t)config_defs::exo_name::right_ankle},
318 {"leftHip", (uint8_t)config_defs::exo_name::left_hip},
319 {"rightHip", (uint8_t)config_defs::exo_name::right_hip},
320 {"leftHipAnkle", (uint8_t)config_defs::exo_name::left_hip_ankle},
321 {"rightHipAnkle", (uint8_t)config_defs::exo_name::right_hip_ankle},
322 {"test", (uint8_t)config_defs::exo_name::test},
323 {"rightKnee", (uint8_t)config_defs::exo_name::right_knee},
324 };
325
326 const IniKeyCode exo_side
327 {
328 {"bilateral", (uint8_t)config_defs::exo_side::bilateral},
329 {"left", (uint8_t)config_defs::exo_side::left},
330 {"right", (uint8_t)config_defs::exo_side::right},
331 };
332
333 const IniKeyCode motor
334 {
335 {"0", (uint8_t)config_defs::motor::not_used},
336 {"AK60", (uint8_t)config_defs::motor::AK60},
337 {"AK80", (uint8_t)config_defs::motor::AK80},
338 {"AK60v1.1", (uint8_t)config_defs::motor::AK60_v1_1},
339 {"AK60v1.1T", (uint8_t)config_defs::motor::AK60_v1_1_T},
340 };
341
342 const IniKeyCode gearing
343 {
344 {"1", (uint8_t)config_defs::gearing::gearing_1_1},
345 {"2", (uint8_t)config_defs::gearing::gearing_2_1},
346 {"3", (uint8_t)config_defs::gearing::gearing_3_1},
347 {"4.5", (uint8_t)config_defs::gearing::gearing_4_5_1},
348 };
349
350
351 const IniKeyCode hip_controllers
352 {
354 {"zeroTorque", (uint8_t)config_defs::hip_controllers::zero_torque},
355 {"heelToe", (uint8_t)config_defs::hip_controllers::heel_toe},
356 {"extensionAngle", (uint8_t)config_defs::hip_controllers::extension_angle},
357 {"franksCollinsHip", (uint8_t)config_defs::hip_controllers::franks_collins_hip},
358 {"bangBang", (uint8_t)config_defs::hip_controllers::bang_bang},
359 {"lateStance", (uint8_t)config_defs::hip_controllers::late_stance},
360 {"gaitPhase", (uint8_t)config_defs::hip_controllers::gait_phase},
361 {"userDefined", (uint8_t)config_defs::hip_controllers::user_defined},
362 {"sine", (uint8_t)config_defs::hip_controllers::sine},
363 {"stasis", (uint8_t)config_defs::hip_controllers::stasis},
364 {"perturbation", (uint8_t)config_defs::hip_controllers::perturbation},
365 {"parabolic", (uint8_t)config_defs::hip_controllers::parabolic},
366 {"constantTorque", (uint8_t)config_defs::hip_controllers::constant_torque},
367 {"ptbGeneral", (uint8_t)config_defs::hip_controllers::ptb_general},
368 };
369
370 const IniKeyCode knee_controllers
371 {
373 {"zeroTorque", (uint8_t)config_defs::knee_controllers::zero_torque},
374 {"userDefined", (uint8_t)config_defs::knee_controllers::user_defined},
375 {"sine", (uint8_t)config_defs::knee_controllers::sine},
376 {"stasis", (uint8_t)config_defs::knee_controllers::stasis},
377 {"perturbation", (uint8_t)config_defs::knee_controllers::perturbation},
378 {"constantTorque", (uint8_t)config_defs::knee_controllers::constant_torque},
379 {"elbowMinMax", (uint8_t)config_defs::knee_controllers::elbow_min_max},
380 };
381
382 const IniKeyCode ankle_controllers
383 {
385 {"zeroTorque", (uint8_t)config_defs::ankle_controllers::zero_torque},
386 {"PJMC", (uint8_t)config_defs::ankle_controllers::pjmc},
387 {"zhangCollins", (uint8_t)config_defs::ankle_controllers::zhang_collins},
388 {"userDefined", (uint8_t)config_defs::ankle_controllers::user_defined},
389 {"sine", (uint8_t)config_defs::ankle_controllers::sine},
390 {"stasis", (uint8_t)config_defs::ankle_controllers::stasis},
391 {"perturbation", (uint8_t)config_defs::ankle_controllers::perturbation},
392 {"constantTorque", (uint8_t)config_defs::ankle_controllers::constant_torque},
393 {"ptbGeneral", (uint8_t)config_defs::ankle_controllers::ptb_general},
394 {"GAsP", (uint8_t)config_defs::ankle_controllers::gasp},
395 {"elbowMinMax", (uint8_t)config_defs::ankle_controllers::elbow_min_max},
396 {"calibrManager", (uint8_t)config_defs::ankle_controllers::calibr_manager},
397 };
398
399 const IniKeyCode flip_dir
400 {
401 {"0", (uint8_t)config_defs::flip_dir::neither},
402 {"left", (uint8_t)config_defs::flip_dir::left},
403 {"right", (uint8_t)config_defs::flip_dir::right},
404 {"both", (uint8_t)config_defs::flip_dir::both},
405
406 };
407 };
408
409
410
411
415 struct ConfigData{
416
417 std::string board_name;
418 std::string board_version;
419
420 std::string battery;
421
422 std::string exo_name;
423 std::string exo_sides;
424
425 std::string exo_hip;
426 std::string exo_knee;
427 std::string exo_ankle;
428
429 std::string hip_gearing;
430 std::string knee_gearing;
431 std::string ankle_gearing;
432
433 std::string exo_hip_default_controller;
434 std::string exo_knee_default_controller;
435 std::string exo_ankle_default_controller;
436
437 std::string hip_flip_dir;
438 std::string knee_flip_dir;
439 std::string ankle_flip_dir;
440
441 std::string hip_flip_motor_dir;
442 std::string knee_flip_motor_dir;
443 std::string ankle_flip_motor_dir;
444
445 std::string hip_flip_torque_dir;
446 std::string knee_flip_torque_dir;
447 std::string ankle_flip_torque_dir;
448
449 std::string hip_flip_angle_dir;
450 std::string knee_flip_angle_dir;
451 std::string ankle_flip_angle_dir;
452 };
453#endif
454
455
456#endif
Definition IniFile.h:23
Namespace that defines numeric coding for different keys values. These are used throughout the code.
Definition ParseIni.h:38
joint_id
Definition ParseIni.h:106
ankle_controllers
Definition ParseIni.h:156
battery
Definition ParseIni.h:53
flip_dir
Definition ParseIni.h:173
exo_name
Definition ParseIni.h:59
motor
Definition ParseIni.h:88
hip_controllers
Definition ParseIni.h:125
board_version
Definition ParseIni.h:45
JointType
Definition ParseIni.h:81
knee_controllers
Definition ParseIni.h:144
exo_side
Definition ParseIni.h:74
board_name
Definition ParseIni.h:40
gearing
Definition ParseIni.h:97
define the constants to use for the various arrays.
Definition ParseIni.h:21
const int section_length
Definition ParseIni.h:24
const int number_of_keys
Definition ParseIni.h:25
const int key_length
Definition ParseIni.h:23
const int buffer_length
Definition ParseIni.h:22