add throttle adc filter
This commit is contained in:
parent
e2dd5de510
commit
5931a5dbbc
|
@ -52,6 +52,7 @@ int16_t brake_pos=0;
|
||||||
unsigned long last_adcread=0;
|
unsigned long last_adcread=0;
|
||||||
#define ADCREADPERIOD 10
|
#define ADCREADPERIOD 10
|
||||||
uint16_t throttle_raw=0;
|
uint16_t throttle_raw=0;
|
||||||
|
#define THROTTLE_ADC_FILTER 0.1 //higher value = faster response
|
||||||
uint16_t brake_raw=0;
|
uint16_t brake_raw=0;
|
||||||
#define ADC_OUTOFRANGE_TIME 100
|
#define ADC_OUTOFRANGE_TIME 100
|
||||||
unsigned long throttle_ok_time=0;
|
unsigned long throttle_ok_time=0;
|
||||||
|
@ -446,7 +447,10 @@ void writeLogComment(HardwareSerial &SerialRef, unsigned long time, String msg)
|
||||||
|
|
||||||
|
|
||||||
void readADC() {
|
void readADC() {
|
||||||
throttle_raw = analogRead(PIN_THROTTLE);
|
|
||||||
|
uint16_t new_throttle_raw = analogRead(PIN_THROTTLE);
|
||||||
|
throttle_raw = new_throttle_raw*THROTTLE_ADC_FILTER + throttle_raw*(1-THROTTLE_ADC_FILTER); //apply filter
|
||||||
|
|
||||||
//maps throttle curve to be linear
|
//maps throttle curve to be linear
|
||||||
throttle_pos=max(0,min(1000,linearizeThrottle(throttle_raw))); //map and constrain
|
throttle_pos=max(0,min(1000,linearizeThrottle(throttle_raw))); //map and constrain
|
||||||
brake_raw = analogRead(PIN_BRAKE);
|
brake_raw = analogRead(PIN_BRAKE);
|
||||||
|
|
Loading…
Reference in New Issue