Now with Boilerplate and as used in finished DROPSAW project
lcm101.h@3:22f8cfcad8d6, 2018-10-12 (annotated)
- Committer:
- cnckiwi31
- Date:
- Fri Oct 12 12:09:59 2018 +0000
- Revision:
- 3:22f8cfcad8d6
- Parent:
- 2:77cffacfd89e
- Child:
- 4:f7af875abe50
current on 12-10-2018
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
megrootens | 0:116acb03eb85 | 1 | #ifndef _LCM101_H_ |
megrootens | 0:116acb03eb85 | 2 | #define _LCM101_H_ |
megrootens | 0:116acb03eb85 | 3 | |
megrootens | 0:116acb03eb85 | 4 | #include "mbed.h" |
megrootens | 0:116acb03eb85 | 5 | |
megrootens | 0:116acb03eb85 | 6 | /** |
megrootens | 0:116acb03eb85 | 7 | * Simple class to read out an LCM101 S-beam force sensor connected to an analog |
megrootens | 0:116acb03eb85 | 8 | * input. |
megrootens | 0:116acb03eb85 | 9 | */ |
megrootens | 0:116acb03eb85 | 10 | class Lcm101 { |
megrootens | 0:116acb03eb85 | 11 | public: |
megrootens | 0:116acb03eb85 | 12 | |
megrootens | 0:116acb03eb85 | 13 | /** |
megrootens | 0:116acb03eb85 | 14 | * @param pin_a_in PinName of analog input |
megrootens | 0:116acb03eb85 | 15 | * @param offset of analog value (calibration data) |
megrootens | 0:116acb03eb85 | 16 | * @param factor multiplication factor for analog value (calibration data) |
megrootens | 0:116acb03eb85 | 17 | */ |
megrootens | 0:116acb03eb85 | 18 | Lcm101(PinName pin_a_in, float offset, float factor) : |
megrootens | 0:116acb03eb85 | 19 | analog_in_(pin_a_in), |
megrootens | 0:116acb03eb85 | 20 | kOffset_(offset), |
megrootens | 0:116acb03eb85 | 21 | kFactor_(factor) |
megrootens | 0:116acb03eb85 | 22 | { |
megrootens | 0:116acb03eb85 | 23 | } |
megrootens | 0:116acb03eb85 | 24 | |
megrootens | 0:116acb03eb85 | 25 | /** |
megrootens | 0:116acb03eb85 | 26 | * @return unscaled analog input value |
megrootens | 0:116acb03eb85 | 27 | */ |
megrootens | 0:116acb03eb85 | 28 | float getForceRaw() |
megrootens | 0:116acb03eb85 | 29 | { |
megrootens | 0:116acb03eb85 | 30 | return analog_in_.read(); |
megrootens | 0:116acb03eb85 | 31 | } |
megrootens | 0:116acb03eb85 | 32 | |
megrootens | 0:116acb03eb85 | 33 | /** |
megrootens | 0:116acb03eb85 | 34 | * @return force value kOffset_ + kFactor_ * getForceRaw(); |
megrootens | 0:116acb03eb85 | 35 | */ |
megrootens | 0:116acb03eb85 | 36 | float getForce() |
megrootens | 0:116acb03eb85 | 37 | { |
megrootens | 0:116acb03eb85 | 38 | return kOffset_ + kFactor_ * getForceRaw(); |
Technical_Muffin | 2:77cffacfd89e | 39 | //it appears that higher order polynomials show better accuracy, within the 40 kg range that is. |
Technical_Muffin | 2:77cffacfd89e | 40 | // Awaiting other instructions, a linear fit will be currently used however. |
megrootens | 0:116acb03eb85 | 41 | } |
megrootens | 0:116acb03eb85 | 42 | |
megrootens | 0:116acb03eb85 | 43 | /** |
cnckiwi31 | 3:22f8cfcad8d6 | 44 | * sets force scaling offset so that current output is force zero |
cnckiwi31 | 3:22f8cfcad8d6 | 45 | */ |
cnckiwi31 | 3:22f8cfcad8d6 | 46 | void nullForce() |
cnckiwi31 | 3:22f8cfcad8d6 | 47 | { |
cnckiwi31 | 3:22f8cfcad8d6 | 48 | kOffset_ = kOffset_ - getForce(); |
cnckiwi31 | 3:22f8cfcad8d6 | 49 | return; |
cnckiwi31 | 3:22f8cfcad8d6 | 50 | } |
cnckiwi31 | 3:22f8cfcad8d6 | 51 | |
cnckiwi31 | 3:22f8cfcad8d6 | 52 | /** |
megrootens | 0:116acb03eb85 | 53 | * @return ffset of analog value |
megrootens | 0:116acb03eb85 | 54 | */ |
megrootens | 0:116acb03eb85 | 55 | float get_offset() { return kOffset_; } |
megrootens | 0:116acb03eb85 | 56 | |
megrootens | 0:116acb03eb85 | 57 | /** |
megrootens | 0:116acb03eb85 | 58 | * @return factor multiplication factor for analog value |
megrootens | 0:116acb03eb85 | 59 | */ |
megrootens | 0:116acb03eb85 | 60 | float get_factor() { return kFactor_; } |
megrootens | 0:116acb03eb85 | 61 | |
megrootens | 0:116acb03eb85 | 62 | |
megrootens | 0:116acb03eb85 | 63 | private: |
megrootens | 0:116acb03eb85 | 64 | AnalogIn analog_in_; |
megrootens | 0:116acb03eb85 | 65 | |
cnckiwi31 | 3:22f8cfcad8d6 | 66 | float kOffset_; |
megrootens | 0:116acb03eb85 | 67 | const float kFactor_; |
megrootens | 0:116acb03eb85 | 68 | }; |
megrootens | 0:116acb03eb85 | 69 | |
megrootens | 0:116acb03eb85 | 70 | #endif |