get functions for feedback

This commit is contained in:
interfisch 2022-04-12 16:28:13 +02:00
parent 214fecdce4
commit c2eba898ac
2 changed files with 67 additions and 1 deletions

View File

@ -51,15 +51,22 @@ bool ESCSerialComm::update(long millis) //returns true if something was sent or
if (loopmillis - last_send > SENDPERIOD) { //Calculate motor stuff and send to motor controllers if (loopmillis - last_send > SENDPERIOD) { //Calculate motor stuff and send to motor controllers
last_send=loopmillis; last_send=loopmillis;
Motorparams.filtered_curL=filterMedian(Motorparams.curL_DC)/50.0; //in Amps
Motorparams.filtered_curR=filterMedian(Motorparams.curR_DC)/50.0; //in Amps
if (controller_connected) { if (controller_connected) {
SendSerial(Motorparams.cmdL,Motorparams.cmdR); SendSerial(Motorparams.cmdL,Motorparams.cmdR);
flag_sent=true; flag_sent=true;
//Serial.print(cmd_send); Serial.print(", "); Serial.print(throttle_pos); Serial.print(", "); Serial.print(filtered_curFL*1000); Serial.print(", "); Serial.print(filtered_curFR*1000); Serial.print(", "); Serial.print(filtered_currentAll*1000); Serial.println() //Serial.print(cmd_send); Serial.print(", "); Serial.print(throttle_pos); Serial.print(", "); Serial.print(filtered_curFL*1000); Serial.print(", "); Serial.print(filtered_curFR*1000); Serial.print(", "); Serial.print(filtered_currentAll*1000); Serial.println()
} }
//Update speed and trip //Update speed and trip
float _meanRPM=(Feedback.speedL_meas-Feedback.speedR_meas)/2.0; float _meanRPM=(Feedback.speedL_meas-Feedback.speedR_meas)/2.0;
meanSpeedms=_meanRPM*wheelcircumference/60.0; // Units: 1/min * m / 60s meanSpeedms=_meanRPM*wheelcircumference/60.0; // Units: 1/min * m / 60s
@ -188,3 +195,46 @@ float filterMedian(int16_t* values) {
return mean; return mean;
} }
int16_t ESCSerialComm::getFeedback_cmd1() {
return Feedback.cmd1;
}
int16_t ESCSerialComm::getFeedback_cmd2() {
return Feedback.cmd2;
}
int16_t ESCSerialComm::getFeedback_speedL_meas() {
return Feedback.speedL_meas;
}
int16_t ESCSerialComm::getFeedback_speedR_meas() {
return Feedback.speedR_meas;
}
float ESCSerialComm::getFeedback_batVoltage() {
return Feedback.batVoltage/100.0;
}
float ESCSerialComm::getFeedback_boardTemp() {
return Feedback.boardTemp/10.0;
}
float ESCSerialComm::getFeedback_curL_DC() {
return Feedback.curL_DC/50.0;
}
float ESCSerialComm::getFeedback_curR_DC() {
return Feedback.curR_DC/50.0;
}
float ESCSerialComm::getFiltered_curL() {
return Motorparams.filtered_curL;
}
float ESCSerialComm::getFiltered_curR() {
return Motorparams.filtered_curR;
}
float ESCSerialComm::getCurrentConsumed() {
return currentConsumed;
}
float ESCSerialComm::getTrip() {
return trip;
}

View File

@ -52,6 +52,7 @@ typedef struct{ //match this struct to hoverboard-firmware SerialFeedback struct
uint16_t checksum; uint16_t checksum;
} SerialFeedback; } SerialFeedback;
#define CURRENT_FILTER_SIZE 60 //latency is about CURRENT_FILTER_SIZE/2*MEASURE_INTERVAL (measure interval is defined by hoverboard controller) #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 #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
@ -81,6 +82,20 @@ class ESCSerialComm
int16_t getCmdR(); int16_t getCmdR();
bool sendPending(long millis); bool sendPending(long millis);
int16_t getFeedback_cmd1();
int16_t getFeedback_cmd2();
int16_t getFeedback_speedL_meas();
int16_t getFeedback_speedR_meas();
float getFeedback_batVoltage();
float getFeedback_boardTemp();
float getFeedback_curL_DC();
float getFeedback_curR_DC();
float getFiltered_curL();
float getFiltered_curR();
float getCurrentConsumed();
float getTrip();
private: private:
unsigned long loopmillis; unsigned long loopmillis;
@ -118,3 +133,4 @@ class ESCSerialComm
bool ReceiveSerial(); bool ReceiveSerial();
}; };
#endif #endif