test current graph output

This commit is contained in:
interfisch 2021-03-09 19:45:36 +01:00
parent 649daaa25e
commit 3becfe30b1
1 changed files with 14 additions and 3 deletions

View File

@ -20,6 +20,9 @@ int16_t out_speedRR=0;
unsigned long last_send = 0; unsigned long last_send = 0;
unsigned long last_receive = 0; unsigned long last_receive = 0;
float avg_currentL=0;
float avg_currentR=0;
// Global variables for serial communication // Global variables for serial communication
typedef struct{ typedef struct{
@ -168,6 +171,7 @@ void loop() {
if (newData) { if (newData) {
float _current = (FeedbackFront.curL_DC+FeedbackFront.curR_DC)/2.0 / 50; float _current = (FeedbackFront.curL_DC+FeedbackFront.curR_DC)/2.0 / 50;
/*
Serial.print(FeedbackFront.curL_DC); Serial.print(", "); Serial.print(FeedbackFront.curL_DC); Serial.print(", ");
Serial.print(FeedbackFront.curR_DC); Serial.print(", "); Serial.print(FeedbackFront.curR_DC); Serial.print(", ");
@ -176,17 +180,24 @@ void loop() {
Serial.print(FeedbackFront.cmd1); Serial.print(", "); Serial.print(FeedbackFront.cmd1); Serial.print(", ");
Serial.print(FeedbackFront.cmd2); Serial.print(", "); Serial.print(FeedbackFront.cmd2); Serial.print(", ");
Serial.println(); Serial.println();
*/
#define CURRENTFILTER 0.95
avg_currentL=avg_currentL*CURRENTFILTER+FeedbackFront.curL_DC*(1-CURRENTFILTER);
avg_currentR=avg_currentR*CURRENTFILTER+FeedbackFront.curR_DC*(1-CURRENTFILTER);
} }
if (loopmillis - last_send > SENDPERIOD) { if (loopmillis - last_send > SENDPERIOD) {
last_send=loopmillis; last_send=loopmillis;
uint16_t throttle_raw = analogRead(PIN_THROTTLE); uint16_t throttle_raw = analogRead(PIN_THROTTLE);
Serial.print("Analog: "); Serial.print(throttle_raw); //Serial.print("Analog: "); Serial.print(throttle_raw);
out_speedFL=max(0,min(1000,map(throttle_raw,calib_throttle_min,calib_throttle_max,0,1000))); out_speedFR=max(0,min(1000,map(throttle_raw,calib_throttle_min,calib_throttle_max,0,1000)));
Serial.print(", Send: "); Serial.println(out_speedFL); //Serial.print(", Send: "); Serial.println(out_speedFL);
SendSerial(CommandFront,out_speedFL,out_speedFR,Serial2); SendSerial(CommandFront,out_speedFL,out_speedFR,Serial2);
Serial.print(out_speedFL); Serial.print(", "); Serial.print(out_speedFR); Serial.print(", "); Serial.print(avg_currentR); Serial.print(", "); Serial.println(avg_currentL);
} }
} }