a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Committer:
nki
Date:
Thu May 21 02:19:25 2015 +0000
Revision:
55:f102d271e808
Parent:
54:e8d9bc885723
still testing;

Who changed what in which revision?

UserRevisionLine numberNew 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 54:e8d9bc885723 5 #include "filters.h"
bwang 1:1f58bdcf2956 6
nki 33:e7b132029bae 7 class CurrentSensor {
bwang 28:af9d43bcb371 8 public:
nki 33:e7b132029bae 9 virtual float GetCurrent() {return 0.0f;}
nki 33:e7b132029bae 10 virtual void Zero() {}
bwang 1:1f58bdcf2956 11 };
bwang 1:1f58bdcf2956 12
bwang 1:1f58bdcf2956 13 class VoltageSensor {
bwang 1:1f58bdcf2956 14 public:
bwang 1:1f58bdcf2956 15 virtual float GetVoltage() {return 0.0f;}
bwang 1:1f58bdcf2956 16 virtual void Zero(){}
bwang 1:1f58bdcf2956 17 };
bwang 1:1f58bdcf2956 18
bwang 1:1f58bdcf2956 19 class PositionSensor {
bwang 1:1f58bdcf2956 20 public:
bwang 1:1f58bdcf2956 21 virtual float GetPosition() {return 0.0f;}
bwang 54:e8d9bc885723 22 virtual float GetSpeed() {return 0.0f;}
bwang 1:1f58bdcf2956 23 };
bwang 1:1f58bdcf2956 24
bwang 1:1f58bdcf2956 25 class TempSensor {
bwang 1:1f58bdcf2956 26 public:
bwang 1:1f58bdcf2956 27 virtual float GetTemp() {return 0.0f;}
bwang 1:1f58bdcf2956 28 };
bwang 1:1f58bdcf2956 29
nki 33:e7b132029bae 30 class AnalogCurrentSensor: public CurrentSensor {
nki 33:e7b132029bae 31 public:
nki 33:e7b132029bae 32 AnalogCurrentSensor(PinName pin, float volts_per_amp);
nki 33:e7b132029bae 33 virtual void Zero();
nki 33:e7b132029bae 34 virtual float GetCurrent();
nki 33:e7b132029bae 35 private:
nki 33:e7b132029bae 36 float _zero_level, _volts_per_amp;
nki 33:e7b132029bae 37 AnalogIn *_in;
nki 33:e7b132029bae 38 };
nki 33:e7b132029bae 39
bwang 1:1f58bdcf2956 40 class AnalogVoltageSensor: public VoltageSensor {
bwang 1:1f58bdcf2956 41 public:
bwang 1:1f58bdcf2956 42 AnalogVoltageSensor(PinName pin, float scale);
bwang 1:1f58bdcf2956 43 virtual void Zero();
bwang 1:1f58bdcf2956 44 virtual float GetVoltage();
bwang 1:1f58bdcf2956 45 private:
bwang 1:1f58bdcf2956 46 float _zero_level, _scale;
nki 33:e7b132029bae 47 AnalogIn *_in;
bwang 1:1f58bdcf2956 48 };
bwang 1:1f58bdcf2956 49
bwang 1:1f58bdcf2956 50 class AnalogHallPositionSensor: public PositionSensor {
bwang 1:1f58bdcf2956 51 public:
bwang 1:1f58bdcf2956 52 AnalogHallPositionSensor(PinName pin_a, PinName pin_b, float cal1_a, float cal2_a,
bwang 1:1f58bdcf2956 53 float cal1_b, float cal2_b, float offset);
bwang 1:1f58bdcf2956 54 virtual float GetPosition();
bwang 54:e8d9bc885723 55 virtual float GetSpeed() {return _speed * 1000000.0f / 360.0f;}
bwang 1:1f58bdcf2956 56 private:
bwang 54:e8d9bc885723 57 void upd_function() {_time += 50;}
bwang 1:1f58bdcf2956 58 float _cal1_a, _cal2_a;
bwang 1:1f58bdcf2956 59 float _cal1_b, _cal2_b;
bwang 1:1f58bdcf2956 60 float _offset;
nki 33:e7b132029bae 61 AnalogIn *_in_a, *_in_b;
bwang 54:e8d9bc885723 62 private:
bwang 54:e8d9bc885723 63 Ticker *_time_upd_ticker;
bwang 54:e8d9bc885723 64 unsigned long _time;
bwang 54:e8d9bc885723 65 float _last_time, _last_position, _speed;
bwang 1:1f58bdcf2956 66 };
bwang 1:1f58bdcf2956 67
bwang 1:1f58bdcf2956 68 class NtcTempSensor: public TempSensor {
bwang 1:1f58bdcf2956 69 public:
bwang 1:1f58bdcf2956 70 NtcTempSensor(PinName pin, float r_25, float ntc_b, float r_divider);
bwang 1:1f58bdcf2956 71 virtual float GetTemp();
bwang 1:1f58bdcf2956 72 private:
bwang 1:1f58bdcf2956 73 float _ntc_a, _ntc_b, _r_divider;
nki 33:e7b132029bae 74 AnalogIn *_in;
bwang 1:1f58bdcf2956 75 };
bwang 1:1f58bdcf2956 76
bwang 1:1f58bdcf2956 77 class Throttle {
bwang 1:1f58bdcf2956 78 public:
bwang 1:1f58bdcf2956 79 Throttle(PinName pin, float min, float max);
bwang 1:1f58bdcf2956 80 float GetThrottle();
bwang 1:1f58bdcf2956 81 private:
bwang 1:1f58bdcf2956 82 float _min, _max;
bwang 1:1f58bdcf2956 83 VoltageSensor *_in;
bwang 1:1f58bdcf2956 84 };
bwang 1:1f58bdcf2956 85
bwang 1:1f58bdcf2956 86 #endif