FSR
Dependents: FSR_hello_world FINAL_PROJECT Pousse_seringue_Ulg 0__Pousse_seringue ... more
FSR.cpp@5:d9520bf7eb9e, 2015-10-22 (annotated)
- Committer:
- cshao06
- Date:
- Thu Oct 22 17:06:17 2015 +0000
- Revision:
- 5:d9520bf7eb9e
- Parent:
- 2:3a5f5cc5b35c
FSR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cshao06 | 0:d24a38523990 | 1 | #include "FSR.h" |
cshao06 | 0:d24a38523990 | 2 | #include "mbed.h" |
cshao06 | 0:d24a38523990 | 3 | |
cshao06 | 0:d24a38523990 | 4 | FSR::FSR(PinName pin, float resistance) : _ain(pin), _r(resistance) |
cshao06 | 0:d24a38523990 | 5 | { |
cshao06 | 0:d24a38523990 | 6 | } |
cshao06 | 0:d24a38523990 | 7 | |
cshao06 | 0:d24a38523990 | 8 | float FSR::readRaw() |
cshao06 | 0:d24a38523990 | 9 | { |
cshao06 | 0:d24a38523990 | 10 | float read = _ain; |
cshao06 | 0:d24a38523990 | 11 | return read; |
cshao06 | 0:d24a38523990 | 12 | } |
cshao06 | 0:d24a38523990 | 13 | |
cshao06 | 0:d24a38523990 | 14 | float FSR::readFSRResistance() |
cshao06 | 0:d24a38523990 | 15 | { |
cshao06 | 0:d24a38523990 | 16 | float read = _ain; |
cshao06 | 1:6b702226a5d3 | 17 | return _r * 1 / read - _r; |
cshao06 | 0:d24a38523990 | 18 | } |
cshao06 | 0:d24a38523990 | 19 | |
cshao06 | 0:d24a38523990 | 20 | float FSR::readWeight() |
cshao06 | 0:d24a38523990 | 21 | { |
cshao06 | 0:d24a38523990 | 22 | float read = _ain; |
cshao06 | 2:3a5f5cc5b35c | 23 | float rfsr = _r * 1 / read - _r; |
cshao06 | 0:d24a38523990 | 24 | float slope = (4 - 2) / (log10(6.2) - log10(0.25)); |
cshao06 | 0:d24a38523990 | 25 | float a = log10(rfsr); |
cshao06 | 0:d24a38523990 | 26 | if (a < log10(6.2)) |
cshao06 | 0:d24a38523990 | 27 | { |
cshao06 | 0:d24a38523990 | 28 | return pow(10, ((log10(6.2) - a) * slope + 2)); |
cshao06 | 0:d24a38523990 | 29 | } |
cshao06 | 0:d24a38523990 | 30 | else |
cshao06 | 0:d24a38523990 | 31 | { |
cshao06 | 0:d24a38523990 | 32 | return 0; |
cshao06 | 0:d24a38523990 | 33 | } |
cshao06 | 0:d24a38523990 | 34 | } |