Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of priustroller_2 by
sensors.h
00001 #ifndef __SENSORS_H 00002 #define __SENSORS_H 00003 00004 #include "includes.h" 00005 #include "filters.h" 00006 00007 class CurrentSensor { 00008 public: 00009 virtual float GetCurrent() {return 0.0f;} 00010 virtual void Zero() {} 00011 }; 00012 00013 class VoltageSensor { 00014 public: 00015 virtual float GetVoltage() {return 0.0f;} 00016 virtual void Zero(){} 00017 }; 00018 00019 class PositionSensor { 00020 public: 00021 virtual float GetPosition() {return 0.0f;} 00022 virtual float GetSpeed() {return 0.0f;} 00023 }; 00024 00025 class TempSensor { 00026 public: 00027 virtual float GetTemp() {return 0.0f;} 00028 }; 00029 00030 class AnalogCurrentSensor: public CurrentSensor { 00031 public: 00032 AnalogCurrentSensor(PinName pin, float volts_per_amp); 00033 virtual void Zero(); 00034 virtual float GetCurrent(); 00035 private: 00036 float _zero_level, _volts_per_amp; 00037 AnalogIn *_in; 00038 }; 00039 00040 class AnalogVoltageSensor: public VoltageSensor { 00041 public: 00042 AnalogVoltageSensor(PinName pin, float scale); 00043 virtual void Zero(); 00044 virtual float GetVoltage(); 00045 private: 00046 float _zero_level, _scale; 00047 AnalogIn *_in; 00048 }; 00049 00050 class AnalogHallPositionSensor: public PositionSensor { 00051 public: 00052 AnalogHallPositionSensor(PinName pin_a, PinName pin_b, float cal1_a, float cal2_a, 00053 float cal1_b, float cal2_b, float offset); 00054 virtual float GetPosition(); 00055 virtual float GetSpeed() {return _speed * 1000000.0f / 360.0f;} 00056 private: 00057 void upd_function() {_time += 50;} 00058 float _cal1_a, _cal2_a; 00059 float _cal1_b, _cal2_b; 00060 float _offset; 00061 AnalogIn *_in_a, *_in_b; 00062 private: 00063 Ticker *_time_upd_ticker; 00064 unsigned long _time; 00065 float _last_time, _last_position, _speed; 00066 }; 00067 00068 class NtcTempSensor: public TempSensor { 00069 public: 00070 NtcTempSensor(PinName pin, float r_25, float ntc_b, float r_divider); 00071 virtual float GetTemp(); 00072 private: 00073 float _ntc_a, _ntc_b, _r_divider; 00074 AnalogIn *_in; 00075 }; 00076 00077 class Throttle { 00078 public: 00079 Throttle(PinName pin, float min, float max); 00080 float GetThrottle(); 00081 private: 00082 float _min, _max; 00083 VoltageSensor *_in; 00084 }; 00085 00086 #endif
Generated on Tue Jul 12 2022 18:31:15 by
1.7.2
