N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
sensors.h@1:1f58bdcf2956, 2015-03-01 (annotated)
- Committer:
- bwang
- Date:
- Sun Mar 01 10:51:28 2015 +0000
- Revision:
- 1:1f58bdcf2956
moar
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 | |
bwang | 1:1f58bdcf2956 | 6 | class CurrentSensor { |
bwang | 1:1f58bdcf2956 | 7 | public: |
bwang | 1:1f58bdcf2956 | 8 | virtual float GetCurrent() {return 0.0f;} |
bwang | 1:1f58bdcf2956 | 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 | |
bwang | 1:1f58bdcf2956 | 28 | class AnalogCurrentSensor: public CurrentSensor { |
bwang | 1:1f58bdcf2956 | 29 | public: |
bwang | 1:1f58bdcf2956 | 30 | AnalogCurrentSensor(PinName pin, float volts_per_amp); |
bwang | 1:1f58bdcf2956 | 31 | virtual void Zero(); |
bwang | 1:1f58bdcf2956 | 32 | virtual float GetCurrent(); |
bwang | 1:1f58bdcf2956 | 33 | private: |
bwang | 1:1f58bdcf2956 | 34 | float _zero_level, _volts_per_amp; |
bwang | 1:1f58bdcf2956 | 35 | AnalogIn *_in; |
bwang | 1:1f58bdcf2956 | 36 | }; |
bwang | 1:1f58bdcf2956 | 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; |
bwang | 1:1f58bdcf2956 | 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; |
bwang | 1:1f58bdcf2956 | 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; |
bwang | 1:1f58bdcf2956 | 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 |