fix wheel direction for rpm feedback functions

This commit is contained in:
interfisch 2023-06-02 19:17:45 +02:00
parent 00b432942f
commit 8d180debf7
2 changed files with 11 additions and 7 deletions

View File

@ -34,17 +34,19 @@ bool ESCSerialComm::update(unsigned long loopmillis) //returns true if something
updateMotorparams(loopmillis); updateMotorparams(loopmillis);
} }
#define TRIP_UPDATE_INTERVAL 100 #define TRIP_UPDATE_INTERVAL 100
static unsigned long last_update_trip;
if ( loopmillis > last_update_trip+TRIP_UPDATE_INTERVAL) { if ( loopmillis > last_update_trip+TRIP_UPDATE_INTERVAL) {
last_update_trip=loopmillis; unsigned long trip_update_interval_real=loopmillis-last_update_trip;
last_update_trip=loopmillis;
double _meanRPM=(-Feedback.speedL_meas+Feedback.speedR_meas)/2.0; //double _meanRPM=(-Feedback.speedL_meas+Feedback.speedR_meas)/2.0;
double _meanRPM=(getFeedback_speedL_meas()+getFeedback_speedR_meas())/2.0;
meanSpeedms=_meanRPM*wheelcircumference/60.0; // Units: 1/min * m / 60s meanSpeedms=_meanRPM*wheelcircumference/60.0; // Units: 1/min * m / 60s
trip+=abs(meanSpeedms)* ((TRIP_UPDATE_INTERVAL)/1000.0); trip+=abs(meanSpeedms)* ((trip_update_interval_real)/1000.0);
//mah consumed //mah consumed
currentConsumed += (Motorparams.filtered_curL+Motorparams.filtered_curR)* (TRIP_UPDATE_INTERVAL/1000.0)/3600.0; //amp hours currentConsumed += (Motorparams.filtered_curL+Motorparams.filtered_curR)* (trip_update_interval_real/1000.0)/3600.0; //amp hours
} }
@ -229,7 +231,7 @@ int16_t ESCSerialComm::getFeedback_speedL_meas() {
return Feedback.speedL_meas; return Feedback.speedL_meas;
} }
int16_t ESCSerialComm::getFeedback_speedR_meas() { int16_t ESCSerialComm::getFeedback_speedR_meas() {
return Feedback.speedR_meas; return -Feedback.speedR_meas; //negate rpm, so that positive rpm means driving forward
} }
float ESCSerialComm::getFeedback_batVoltage() { float ESCSerialComm::getFeedback_batVoltage() {
return Feedback.batVoltage/100.0; return Feedback.batVoltage/100.0;

View File

@ -142,6 +142,8 @@ class ESCSerialComm
unsigned long feedback_interval_timed; unsigned long feedback_interval_timed;
unsigned long last_update_trip;
SerialCommand Command; SerialCommand Command;
SerialRead SRead; SerialRead SRead;