TeensyNanoExoCode
Loading...
Searching...
No Matches
Controller.h
Go to the documentation of this file.
1
12#ifndef Controller_h
13#define Controller_h
14
15// Arduino compiles everything in the src folder even if not included so it causes and error for the nano if this is not included.
16#if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)
17
18#include <Arduino.h>
19
20#include "ExoData.h"
21#include "Board.h"
22#include "ParseIni.h"
23#include <stdint.h>
24#include "Utilities.h"
25#include "config.h"
26#include "Time_Helper.h"
27#include <algorithm>
28#include <utility>
29
36class _Controller
37{
38 public:
45 _Controller(config_defs::joint_id id, ExoData* exo_data);
46
50 virtual ~_Controller(){};
51 //virtual void set_controller(int joint, int controller) = 0; // Changes the controller for an individual joint
52
58 virtual float calc_motor_cmd() = 0;
59
63 void reset_integral();
64
65 protected:
66
67 ExoData* _data;
68 ControllerData* _controller_data;
69 LegData* _leg_data;
70 JointData* _joint_data;
74 Time_Helper* _t_helper;
75 float _t_helper_context;
76 float _t_helper_delta_t;
80 // Values for the PID controller
81 float _integral_val;
82 float _prev_input;
83 float _prev_de_dt;
84 float _prev_pid_time;
96 float _pid(float cmd, float measurement, float p_gain, float i_gain, float d_gain);
97
98 // Values for the Compact Form Model Free Adaptive Controller
99 std::pair<float, float> measurements;
100 std::pair<float, float> outputs;
101 std::pair<float, float> phi;
102 float rho;
103 float lamda;
104 float etta;
105 float mu;
106 float upsilon;
107 float phi_1;
109 float _cf_mfac(float reference, float current_measurement);
110};
111
112class PropulsiveAssistive : public _Controller
113{
114 public:
115 PropulsiveAssistive(config_defs::joint_id id, ExoData* exo_data);
116 ~PropulsiveAssistive(){};
117
118 float calc_motor_cmd();
119 private:
120 void _update_reference_angles(LegData* leg_data, ControllerData* controller_data, float percent_grf);
121 void _capture_neutral_angle(LegData* leg_data, ControllerData* controller_data);
122};
123
133class ProportionalJointMoment : public _Controller
134{
135 public:
136 ProportionalJointMoment(config_defs::joint_id id, ExoData* exo_data);
137 ~ProportionalJointMoment(){};
138
139 float calc_motor_cmd();
140 private:
141 std::pair<float, float> _stance_thresholds_left, _stance_thresholds_right;
142
143 float _inclination_scaling{1.0f};
144};
145
146
154class ZeroTorque : public _Controller
155{
156 public:
157 ZeroTorque(config_defs::joint_id id, ExoData* exo_data);
158 ~ZeroTorque(){};
159
160 float calc_motor_cmd();
161};
162
170class Stasis : public _Controller
171{
172 public:
173 Stasis(config_defs::joint_id id, ExoData* exo_data);
174 ~Stasis(){};
175
176 float calc_motor_cmd();
177};
178
190class HeelToe: public _Controller
191{
192 public:
193 HeelToe(config_defs::joint_id id, ExoData* exo_data);
194 ~HeelToe(){};
195
196 float calc_motor_cmd();
197
198 float cmd_ff;
200 float percent_gait;
201 float prev_percent_gait;
202
203 float fs;
204 float fs_previous;
206 int state;
207 int prev_state;
209 float state_4_start;
210 float state_4_end;
211 float previous_state_4_duration;
212 float prev_cmd;
213 float state_4_start_cmd;
215 float swing_start;
216 float swing_duration;
218 float m;
221 float x1;
222 float y1;
223 float x2;
224 float y2;
225 float x3;
226 float y3;
227
229 float A;
230 float B;
231 float C;
232};
233
244class ExtensionAngle: public _Controller
245{
246 public:
247 ExtensionAngle(config_defs::joint_id id, ExoData* exo_data);
248 ~ExtensionAngle(){};
249
250 float calc_motor_cmd();
251 private:
257 void _update_max_angle(float angle);
258
264 void _update_state(float angle);
265
269 void _reset_angles();
270
271 // the initial angles used for tracking the extent of the range of motions
272 const float _initial_max_angle = utils::degrees_to_radians(10);
273 const float _initial_min_angle = utils::degrees_to_radians(-5);
275 // Used to track the range of motion, angles are in rad.
276 float _max_angle;
277 float _min_angle;
279 uint8_t _state;
281};
282
293class BangBang: public _Controller
294{
295 public:
296 BangBang(config_defs::joint_id id, ExoData* exo_data);
297 ~BangBang(){};
298
299 float calc_motor_cmd();
300 private:
306 void _update_max_angle(float angle);
307
313 void _update_state(float angle);
314
318 void _reset_angles();
319
320 // the initial angles used for tracking the extent of the range of motions
321 const float _initial_max_angle = utils::degrees_to_radians(20);
322 const float _initial_min_angle = utils::degrees_to_radians(-5);
324 // Used to track the range of motion, angles are in rad.
325 float _max_angle;
326 float _min_angle;
328 uint8_t _state;
330};
331
332/*
333 * LateStance Controller
334 * This controller is for the hip joint
335 * Applies const torque during late stance
336 *
337 * see ControllerData.h for details on the parameters used.
338 */
339class LateStance : public _Controller
340{
341public:
342 LateStance(config_defs::joint_id id, ExoData* exo_data);
343 ~LateStance(){};
344
345 float calc_motor_cmd();
346private:
347 void _update_max_angle(float angle);
348 void _update_state(float angle);
349 void _reset_angles();
350
351 // the initial angles used for tracking the extent of the range of motions
352 const float _initial_max_angle = utils::degrees_to_radians(20);
353 const float _initial_min_angle = utils::degrees_to_radians(-5);
354
355 // Used to track the range of motion, angles are in rad.
356 float _max_angle;
357 float _min_angle;
358
359 // Used to track the state 0 is extension mode, 1 is flexion mode.
360 uint8_t _state;
361
362};
363
364/*
365 * GaitPhase Controller
366 * This controller is for the hip joint
367 * Applies flexion or extension torque as a function of the gait phase (needs heel and toe FSRs)
368 *
369 * see ControllerData.h for details on the parameters used.
370 *
371 * This controller is still in development, this is just meant to be a framework for the controller that will be filled out with time
372 */
373class GaitPhase : public _Controller
374{
375 public:
376 GaitPhase(config_defs::joint_id id, ExoData* exo_data);
377 ~GaitPhase(){};
378
379 float calc_motor_cmd();
380
381 float slope;
382 float state;
383
384};
385
386/*
387 * Parabolic Controller
388 * This controller is for the hip joint
389 * Applies flexion or extension torque as a function of the gait phase (needs heel and toe FSRs)
390 *
391 * see ControllerData.h for details on the parameters used.
392 *
393 * This controller is still in development, this is just meant to be a framework for the controller that will be filled out with time
394 */
395class Parabolic : public _Controller
396{
397public:
398 Parabolic(config_defs::joint_id id, ExoData* exo_data);
399 ~Parabolic() {};
400
401 float calc_motor_cmd();
402};
403
419class ZhangCollins: public _Controller
420{
421 public:
422 ZhangCollins(config_defs::joint_id id, ExoData* exo_data);
423 ~ZhangCollins(){};
424
425 float calc_motor_cmd();
426
427 float _spline_generation(float node1, float node2, float node3, float torque_magnitude, float percent_gait);
428
429 float torque_cmd;
430
431 float cmd;
432};
433
452class FranksCollinsHip: public _Controller
453{
454 public:
455 FranksCollinsHip(config_defs::joint_id id, ExoData* exo_data);
456 ~FranksCollinsHip(){};
457
458 float calc_motor_cmd();
459
460 float _spline_generation(float node1, float node2, float node3, float torque_magnitude, float shifted_percent_gait);
461
462 float last_percent_gait;
463 float last_start_time;
464
465};
466
477// class UserDefined: public _Controller
478// {
479 // public:
480 // UserDefined(config_defs::joint_id id, ExoData* exo_data);
481 // ~UserDefined(){};
482
483 // float calc_motor_cmd();
484 // private:
485 // float _percent_x[controller_defs::user_defined::num_sample_points];
486 // const float _step_size = 100/controller_defs::user_defined::num_sample_points;
487
488
489// };
490
501class Sine: public _Controller
502{
503 public:
504 Sine(config_defs::joint_id id, ExoData* exo_data);
505 ~Sine(){};
506
507 float calc_motor_cmd();
508 private:
509
510
511};
512
523class Perturbation : public _Controller
524{
525public:
526 Perturbation(config_defs::joint_id id, ExoData* exo_data);
527 ~Perturbation() {};
528
529 float calc_motor_cmd();
530};
531
532class ConstantTorque : public _Controller
533{
534public:
535 ConstantTorque(config_defs::joint_id id, ExoData* exo_data);
536 ~ConstantTorque() {};
537
538 float calc_motor_cmd();
539
540 float current_torque;
541 int counter;
542};
543
544class ElbowMinMax : public _Controller
545{
546public:
547 ElbowMinMax(config_defs::joint_id id, ExoData* exo_data);
548 ~ElbowMinMax() {};
549
550 float calc_motor_cmd();
551
552};
553
554class PtbGeneral : public _Controller
555{
556public:
557 PtbGeneral(config_defs::joint_id id, ExoData* exo_data);
558 ~PtbGeneral() {};
559
560 float calc_motor_cmd();
561};
562
563class CalibrManager : public _Controller
564{
565public:
566 CalibrManager(config_defs::joint_id id, ExoData* exo_data);
567 ~CalibrManager() {};
568
569 float calc_motor_cmd();
570};
571
572#endif
573#endif
Declares a class used to store data for the Exo to access.
Declares the functions needed and defines mapping between the INI keys and the exo components.
class to store information related to controllers.
Definition ControllerData.h:301
Class to store all the data related to the exo.
Definition ExoData.h:38
class to store information related to joint.
Definition JointData.h:33
class to store information related to the leg.
Definition LegData.h:30
Definition Time_Helper.h:33
joint_id
Definition ParseIni.h:106
float degrees_to_radians(float angle_deg)
converts from degrees to radians
Definition Utilities.cpp:88