From fc8ce7d2f3d454ca71d6f92832acc85a907ad23c Mon Sep 17 00:00:00 2001 From: Fisch Date: Mon, 14 Jun 2021 20:56:28 +0200 Subject: [PATCH] fix wrong consumed current. increase current filter --- controller_teensy/src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/controller_teensy/src/main.cpp b/controller_teensy/src/main.cpp index e368439..5a432bd 100644 --- a/controller_teensy/src/main.cpp +++ b/controller_teensy/src/main.cpp @@ -151,8 +151,8 @@ SerialFeedback NewFeedbackFront; SerialFeedback FeedbackRear; SerialFeedback NewFeedbackRear; -#define CURRENT_FILTER_SIZE 40 //latency is about CURRENT_FILTER_SIZE/2*MEASURE_INTERVAL (measure interval is defined by hoverboard controller) -#define CURRENT_MEANVALUECOUNT 10 //0<= meanvaluecount < CURRENT_FILTER_SIZE/2. how many values will be used from sorted weight array from the center region. abour double this values reading are used +#define CURRENT_FILTER_SIZE 60 //latency is about CURRENT_FILTER_SIZE/2*MEASURE_INTERVAL (measure interval is defined by hoverboard controller) +#define CURRENT_MEANVALUECOUNT 20 //0<= meanvaluecount < CURRENT_FILTER_SIZE/2. how many values will be used from sorted weight array from the center region. abour double this values reading are used typedef struct{ int16_t curL_DC[CURRENT_FILTER_SIZE] = {0}; //current will be inverted for this so positive value means consumed current int16_t curR_DC[CURRENT_FILTER_SIZE] = {0}; @@ -328,7 +328,7 @@ void loop() { trip+=abs(meanSpeedms)* (SENDPERIOD/1000.0); //mah consumed - currentConsumed += filtered_currentAll* (SENDPERIOD/1000.0)/3600.0; //amp hours + currentConsumed += (motorparamsFront.filtered_curL+motorparamsFront.filtered_curR+motorparamsRear.filtered_curL+motorparamsRear.filtered_curR)* (SENDPERIOD/1000.0)/3600.0; //amp hours } //If needed write log to serial port @@ -384,7 +384,7 @@ void writeLog(HardwareSerial &SerialRef, unsigned long time, MotorParameter &mpf SerialRef.print(mprear.cmdL); SerialRef.print(","); SerialRef.print(mprear.cmdR); SerialRef.print(","); - SerialRef.print(mpfront.filtered_curL,3); SerialRef.print(","); //invert. positive current is drive current + SerialRef.print(mpfront.filtered_curL,3); SerialRef.print(","); SerialRef.print(mpfront.filtered_curR,3); SerialRef.print(","); SerialRef.print(mprear.filtered_curL,3); SerialRef.print(","); SerialRef.print(mprear.filtered_curR,3); SerialRef.print(","); @@ -399,7 +399,7 @@ void writeLog(HardwareSerial &SerialRef, unsigned long time, MotorParameter &mpf SerialRef.print(fbfront.batVoltage/100.0); SerialRef.print(","); //in V SerialRef.print(fbrear.batVoltage/100.0); SerialRef.print(","); //in V - SerialRef.print(currentAll,3); SerialRef.print(","); //invert. positive current is drive current + SerialRef.print(currentAll,3); SerialRef.print(","); SerialRef.print(throttle); SerialRef.print(","); SerialRef.print(brake); SerialRef.print(","); SerialRef.print(meanSpeedms); SerialRef.print(","); // m/s