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

@ -50,9 +50,14 @@ 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;
@ -60,6 +65,8 @@ bool ESCSerialComm::update(long millis) //returns true if something was sent or
} }
//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
@ -187,4 +194,47 @@ float filterMedian(int16_t* values) {
mean/=(1+CURRENT_MEANVALUECOUNT*2); mean/=(1+CURRENT_MEANVALUECOUNT*2);
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;
@ -117,4 +132,5 @@ class ESCSerialComm
void SendSerial(int16_t uSpeedLeft, int16_t uSpeedRight); void SendSerial(int16_t uSpeedLeft, int16_t uSpeedRight);
bool ReceiveSerial(); bool ReceiveSerial();
}; };
#endif #endif