invert current

This commit is contained in:
interfisch 2021-03-31 20:46:24 +02:00
parent aaabdb3a80
commit 82fbc8234e
1 changed files with 14 additions and 14 deletions

View File

@ -92,7 +92,7 @@ typedef struct{
int16_t speedR_meas; //right speed is positive when driving forward int16_t speedR_meas; //right speed is positive when driving forward
int16_t batVoltage; int16_t batVoltage;
int16_t boardTemp; int16_t boardTemp;
int16_t curL_DC; //negative values are current drawn. positive values mean generated current int16_t curL_DC; //negative values are current consumed. positive values mean generated current
int16_t curR_DC; int16_t curR_DC;
uint16_t cmdLed; uint16_t cmdLed;
uint16_t checksum; uint16_t checksum;
@ -105,7 +105,7 @@ SerialFeedback NewFeedbackRear;
#define CURRENT_FILTER_SIZE 100 //latency is about CURRENT_FILTER_SIZE/2*MEASURE_INTERVAL (measure interval is defined by hoverboard controller) #define CURRENT_FILTER_SIZE 100 //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_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
typedef struct{ typedef struct{
int16_t curL_DC[CURRENT_FILTER_SIZE] = {0}; 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}; int16_t curR_DC[CURRENT_FILTER_SIZE] = {0};
uint8_t cur_pos=0; uint8_t cur_pos=0;
int16_t cmdL=0; int16_t cmdL=0;
@ -283,16 +283,16 @@ void loop() {
if (newData2) { if (newData2) {
motorparamsFront.cur_pos++; motorparamsFront.cur_pos++;
motorparamsFront.cur_pos%=CURRENT_FILTER_SIZE; motorparamsFront.cur_pos%=CURRENT_FILTER_SIZE;
motorparamsFront.curL_DC[motorparamsFront.cur_pos] = FeedbackFront.curL_DC; motorparamsFront.curL_DC[motorparamsFront.cur_pos] = -FeedbackFront.curL_DC; //invert so positive current is consumed current. negative then means regenerated
motorparamsFront.curR_DC[motorparamsFront.cur_pos] = FeedbackFront.curR_DC; motorparamsFront.curR_DC[motorparamsFront.cur_pos] = -FeedbackFront.curR_DC;
motorparamsFront.millis=loopmillis; motorparamsFront.millis=loopmillis;
log_update=true; log_update=true;
} }
if (newData3) { if (newData3) {
motorparamsRear.cur_pos++; motorparamsRear.cur_pos++;
motorparamsRear.cur_pos%=CURRENT_FILTER_SIZE; motorparamsRear.cur_pos%=CURRENT_FILTER_SIZE;
motorparamsRear.curL_DC[motorparamsRear.cur_pos] = FeedbackRear.curL_DC; motorparamsRear.curL_DC[motorparamsRear.cur_pos] = -FeedbackRear.curL_DC;
motorparamsRear.curR_DC[motorparamsRear.cur_pos] = FeedbackRear.curR_DC; motorparamsRear.curR_DC[motorparamsRear.cur_pos] = -FeedbackRear.curR_DC;
motorparamsRear.millis=loopmillis; motorparamsRear.millis=loopmillis;
log_update=true; log_update=true;
} }
@ -312,10 +312,10 @@ void loop() {
motorparamsRear.filtered_curL=filterMedian(motorparamsRear.curL_DC)/50.0; //in Amps motorparamsRear.filtered_curL=filterMedian(motorparamsRear.curL_DC)/50.0; //in Amps
motorparamsRear.filtered_curR=filterMedian(motorparamsRear.curR_DC)/50.0; //in Amps motorparamsRear.filtered_curR=filterMedian(motorparamsRear.curR_DC)/50.0; //in Amps
float filtered_currentFront=min(motorparamsFront.filtered_curL,motorparamsFront.filtered_curR); float filtered_currentFront=max(motorparamsFront.filtered_curL,motorparamsFront.filtered_curR);
float filtered_currentRear=min(motorparamsRear.filtered_curL,motorparamsRear.filtered_curR); float filtered_currentRear=max(motorparamsRear.filtered_curL,motorparamsRear.filtered_curR);
filtered_currentAll=min(filtered_currentFront,filtered_currentRear); filtered_currentAll=max(filtered_currentFront,filtered_currentRear);
if (throttle_pos>=last_cmd_send) { //accelerating if (throttle_pos>=last_cmd_send) { //accelerating
cmd_send = throttle_pos; //if throttle higher than apply throttle directly cmd_send = throttle_pos; //if throttle higher than apply throttle directly
@ -406,10 +406,10 @@ void writeLog(HardwareSerial &SerialRef, unsigned long time, MotorParameter &mpf
SerialRef.print(mprear.cmdL); SerialRef.print(","); SerialRef.print(mprear.cmdL); SerialRef.print(",");
SerialRef.print(mprear.cmdR); 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(","); //invert. positive current is drive current
SerialRef.print(-mpfront.filtered_curR,3); SerialRef.print(","); SerialRef.print(mpfront.filtered_curR,3); SerialRef.print(",");
SerialRef.print(-mprear.filtered_curL,3); SerialRef.print(","); SerialRef.print(mprear.filtered_curL,3); SerialRef.print(",");
SerialRef.print(-mprear.filtered_curR,3); SerialRef.print(","); SerialRef.print(mprear.filtered_curR,3); SerialRef.print(",");
SerialRef.print(-fbfront.speedL_meas); SerialRef.print(","); //invert speed, because left wheels are negated SerialRef.print(-fbfront.speedL_meas); SerialRef.print(","); //invert speed, because left wheels are negated
SerialRef.print(fbfront.speedR_meas); SerialRef.print(","); SerialRef.print(fbfront.speedR_meas); SerialRef.print(",");
@ -421,7 +421,7 @@ void writeLog(HardwareSerial &SerialRef, unsigned long time, MotorParameter &mpf
SerialRef.print(fbfront.batVoltage/100.0); SerialRef.print(","); //in V SerialRef.print(fbfront.batVoltage/100.0); SerialRef.print(","); //in V
SerialRef.print(fbrear.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(","); //invert. positive current is drive current
SerialRef.print(throttle); SerialRef.print(","); SerialRef.print(throttle); SerialRef.print(",");
SerialRef.print(brake); SerialRef.println(); SerialRef.print(brake); SerialRef.println();
} }