TeensyNanoExoCode
Loading...
Searching...
No Matches
FSR.h
Go to the documentation of this file.
1
11#ifndef FSR_h
12#define FSR_h
13
14// Arduino compiles everything in the src folder even if not included so it causes and error for the nano if this is not included.
15#if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)
16
17#include "Arduino.h"
18#include "Board.h"
19#include "Utilities.h"
20
21
22class FSR
23{
24 public:
25 FSR(int pin);
26
36 bool calibrate(bool do_calibrate); // Changes the controller for an individual joint
37
47 bool refine_calibration(bool do_refinement);
48
55 float read(); // reads the pins and updates the data object.f
56
61 bool get_ground_contact();
62
69 void get_contact_thresholds(float &lower_threshold_percent_ground_contact, float &upper_threshold_percent_ground_contact);
70
77 void set_contact_thresholds(float lower_threshold_percent_ground_contact, float upper_threshold_percent_ground_contact);
78 private:
85 bool _calc_ground_contact();
86
87 // Stores the sensor readings
88 uint16_t _raw_reading;
89 float _calibrated_reading;
91 int _pin;
93 // used for calibration
94 const uint16_t _cal_time = 5000;
95 uint16_t _start_time;
96 bool _last_do_calibrate;
97 uint16_t _calibration_min;
98 uint16_t _calibration_max;
100 // used for calibration refinement
101 const uint8_t _num_steps = 7;
102 const float _lower_threshold_percent_calibration_refinement = .33;
103 const float _upper_threshold_percent_calibration_refinement = .66;
104 bool _state;
105 bool _last_do_refinement;
106 unsigned int _step_max_sum;
107 uint16_t _step_max;
108 unsigned int _step_min_sum;
109 uint16_t _step_min;
110 uint8_t _step_count;
111 float _calibration_refinement_min;
112 float _calibration_refinement_max;
114 // used for ground_contact()
115 bool _ground_contact;
116 const uint8_t _ground_state_count_threshold = 4;
117 float _lower_threshold_percent_ground_contact = .15;
118 float _upper_threshold_percent_ground_contact = .25;
120};
121#endif
122#endif