N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
sensors/sensors.h@33:e7b132029bae, 2015-03-16 (annotated)
- Committer:
- nki
- Date:
- Mon Mar 16 03:09:48 2015 +0000
- Revision:
- 33:e7b132029bae
- Parent:
- 30:2b6d426f3bfc
- Child:
- 54:e8d9bc885723
New working set - reverted to synchronous current sensor reads
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bwang | 1:1f58bdcf2956 | 1 | #ifndef __SENSORS_H |
bwang | 1:1f58bdcf2956 | 2 | #define __SENSORS_H |
bwang | 1:1f58bdcf2956 | 3 | |
bwang | 1:1f58bdcf2956 | 4 | #include "includes.h" |
bwang | 1:1f58bdcf2956 | 5 | |
nki | 33:e7b132029bae | 6 | class CurrentSensor { |
bwang | 28:af9d43bcb371 | 7 | public: |
nki | 33:e7b132029bae | 8 | virtual float GetCurrent() {return 0.0f;} |
nki | 33:e7b132029bae | 9 | virtual void Zero() {} |
bwang | 1:1f58bdcf2956 | 10 | }; |
bwang | 1:1f58bdcf2956 | 11 | |
bwang | 1:1f58bdcf2956 | 12 | class VoltageSensor { |
bwang | 1:1f58bdcf2956 | 13 | public: |
bwang | 1:1f58bdcf2956 | 14 | virtual float GetVoltage() {return 0.0f;} |
bwang | 1:1f58bdcf2956 | 15 | virtual void Zero(){} |
bwang | 1:1f58bdcf2956 | 16 | }; |
bwang | 1:1f58bdcf2956 | 17 | |
bwang | 1:1f58bdcf2956 | 18 | class PositionSensor { |
bwang | 1:1f58bdcf2956 | 19 | public: |
bwang | 1:1f58bdcf2956 | 20 | virtual float GetPosition() {return 0.0f;} |
bwang | 1:1f58bdcf2956 | 21 | }; |
bwang | 1:1f58bdcf2956 | 22 | |
bwang | 1:1f58bdcf2956 | 23 | class TempSensor { |
bwang | 1:1f58bdcf2956 | 24 | public: |
bwang | 1:1f58bdcf2956 | 25 | virtual float GetTemp() {return 0.0f;} |
bwang | 1:1f58bdcf2956 | 26 | }; |
bwang | 1:1f58bdcf2956 | 27 | |
nki | 33:e7b132029bae | 28 | class AnalogCurrentSensor: public CurrentSensor { |
nki | 33:e7b132029bae | 29 | public: |
nki | 33:e7b132029bae | 30 | AnalogCurrentSensor(PinName pin, float volts_per_amp); |
nki | 33:e7b132029bae | 31 | virtual void Zero(); |
nki | 33:e7b132029bae | 32 | virtual float GetCurrent(); |
nki | 33:e7b132029bae | 33 | private: |
nki | 33:e7b132029bae | 34 | float _zero_level, _volts_per_amp; |
nki | 33:e7b132029bae | 35 | AnalogIn *_in; |
nki | 33:e7b132029bae | 36 | }; |
nki | 33:e7b132029bae | 37 | |
bwang | 1:1f58bdcf2956 | 38 | class AnalogVoltageSensor: public VoltageSensor { |
bwang | 1:1f58bdcf2956 | 39 | public: |
bwang | 1:1f58bdcf2956 | 40 | AnalogVoltageSensor(PinName pin, float scale); |
bwang | 1:1f58bdcf2956 | 41 | virtual void Zero(); |
bwang | 1:1f58bdcf2956 | 42 | virtual float GetVoltage(); |
bwang | 1:1f58bdcf2956 | 43 | private: |
bwang | 1:1f58bdcf2956 | 44 | float _zero_level, _scale; |
nki | 33:e7b132029bae | 45 | AnalogIn *_in; |
bwang | 1:1f58bdcf2956 | 46 | }; |
bwang | 1:1f58bdcf2956 | 47 | |
bwang | 1:1f58bdcf2956 | 48 | class AnalogHallPositionSensor: public PositionSensor { |
bwang | 1:1f58bdcf2956 | 49 | public: |
bwang | 1:1f58bdcf2956 | 50 | AnalogHallPositionSensor(PinName pin_a, PinName pin_b, float cal1_a, float cal2_a, |
bwang | 1:1f58bdcf2956 | 51 | float cal1_b, float cal2_b, float offset); |
bwang | 1:1f58bdcf2956 | 52 | virtual float GetPosition(); |
bwang | 1:1f58bdcf2956 | 53 | private: |
bwang | 1:1f58bdcf2956 | 54 | float _cal1_a, _cal2_a; |
bwang | 1:1f58bdcf2956 | 55 | float _cal1_b, _cal2_b; |
bwang | 1:1f58bdcf2956 | 56 | float _offset; |
nki | 33:e7b132029bae | 57 | AnalogIn *_in_a, *_in_b; |
bwang | 1:1f58bdcf2956 | 58 | }; |
bwang | 1:1f58bdcf2956 | 59 | |
bwang | 1:1f58bdcf2956 | 60 | class NtcTempSensor: public TempSensor { |
bwang | 1:1f58bdcf2956 | 61 | public: |
bwang | 1:1f58bdcf2956 | 62 | NtcTempSensor(PinName pin, float r_25, float ntc_b, float r_divider); |
bwang | 1:1f58bdcf2956 | 63 | virtual float GetTemp(); |
bwang | 1:1f58bdcf2956 | 64 | private: |
bwang | 1:1f58bdcf2956 | 65 | float _ntc_a, _ntc_b, _r_divider; |
nki | 33:e7b132029bae | 66 | AnalogIn *_in; |
bwang | 1:1f58bdcf2956 | 67 | }; |
bwang | 1:1f58bdcf2956 | 68 | |
bwang | 1:1f58bdcf2956 | 69 | class Throttle { |
bwang | 1:1f58bdcf2956 | 70 | public: |
bwang | 1:1f58bdcf2956 | 71 | Throttle(PinName pin, float min, float max); |
bwang | 1:1f58bdcf2956 | 72 | float GetThrottle(); |
bwang | 1:1f58bdcf2956 | 73 | private: |
bwang | 1:1f58bdcf2956 | 74 | float _min, _max; |
bwang | 1:1f58bdcf2956 | 75 | VoltageSensor *_in; |
bwang | 1:1f58bdcf2956 | 76 | }; |
bwang | 1:1f58bdcf2956 | 77 | |
bwang | 1:1f58bdcf2956 | 78 | #endif |