more comments for freewheeling settings

This commit is contained in:
interfisch 2021-05-13 12:18:47 +02:00
parent fea152adc8
commit 6a755d42cc
1 changed files with 37 additions and 35 deletions

View File

@ -452,51 +452,53 @@ void failChecks() {
}
void sendCMD() {
int16_t cmdreduce_constant=map(brake_pos,0,1000,0,10); //reduce cmd value every cycle
#define MAXBREAKCURRENT 5
float brakepedal_current_multiplier=MAXBREAKCURRENT/1000.0; //how much breaking (in Ampere) for unit of brake_pos (0<=brake_pos<=1000)
#define BREAK_CMDREDUCE_CONSTANT 500 //cmd gets reduced by an amount proportional to brake position (ignores freewheeling). cmd_new-=BREAK_CMDREDUCE_CONSTANT / second @ full brake. with BREAK_CMDREDUCE_CONSTANT=1000 car would stop with full brake at least after a second (ignoring influence of brake current control/freewheeling)
int16_t cmdreduce_constant=map(brake_pos,0,1000,0,(int16_t)(BREAK_CMDREDUCE_CONSTANT*SENDPERIOD/1000)); //reduce cmd value every cycle
#define STARTBREAKCURRENT 5 //Ampere. at what point to start apply brake, proportional to brake_pos.
#define STARTBREAKCURRENT_OFFSET 0.1 //offset start point for breaking, because of reading fluctuations around 0A
float brakepedal_current_multiplier=STARTBREAKCURRENT/1000.0; //how much breaking (in Ampere) for unit of brake_pos (0<=brake_pos<=1000)
float freewheel_current=0.1+brake_pos*brakepedal_current_multiplier; //above which driving current cmd send will be reduced more. increase value to decrease breaking. values <0 increases breaking above freewheeling
float freewheel_break_factor=500.0; //speed cmd units per amp per second. 1A over freewheel_current decreases cmd speed by this amount (in average)
motorparamsFront.filtered_curL=filterMedian(motorparamsFront.curL_DC)/50.0; //in Amps
motorparamsFront.filtered_curR=filterMedian(motorparamsFront.curR_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
float freewheel_current=STARTBREAKCURRENT_OFFSET+brake_pos*brakepedal_current_multiplier; //above which driving current cmd send will be reduced more. increase value to decrease breaking. values <0 increases breaking above freewheeling
float freewheel_break_factor=500.0; //speed cmd units per amp per second. 1A over freewheel_current decreases cmd speed by this amount (on average)
motorparamsFront.filtered_curL=filterMedian(motorparamsFront.curL_DC)/50.0; //in Amps
motorparamsFront.filtered_curR=filterMedian(motorparamsFront.curR_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
float filtered_currentFront=max(motorparamsFront.filtered_curL,motorparamsFront.filtered_curR);
float filtered_currentRear=max(motorparamsRear.filtered_curL,motorparamsRear.filtered_curR);
float filtered_currentFront=max(motorparamsFront.filtered_curL,motorparamsFront.filtered_curR);
float filtered_currentRear=max(motorparamsRear.filtered_curL,motorparamsRear.filtered_curR);
filtered_currentAll=max(filtered_currentFront,filtered_currentRear);
filtered_currentAll=max(filtered_currentFront,filtered_currentRear);
if (throttle_pos>=last_cmd_send) { //accelerating
cmd_send = throttle_pos; //if throttle higher than apply throttle directly
}else{ //freewheeling or braking
if (filtered_currentAll<freewheel_current) { //drive current too high
cmd_send-= max(0, (-filtered_currentAll+freewheel_current)*freewheel_break_factor*(SENDPERIOD/1000.0)); //how much current over freewheel current, multiplied by factor. reduces cmd_send value
}
cmd_send-=max(1,cmdreduce_constant); //reduce slowly anyways
cmd_send=constrain(cmd_send,0,1000);
if (throttle_pos>=last_cmd_send) { //accelerating
cmd_send = throttle_pos; //if throttle higher than last applied value, apply throttle directly
}else{ //freewheeling or braking
if (filtered_currentAll<freewheel_current) { //drive current too high
cmd_send-= max(0, (-filtered_currentAll+freewheel_current)*freewheel_break_factor*(SENDPERIOD/1000.0)); //how much current over freewheel current, multiplied by factor. reduces cmd_send value
}
cmd_send-=max(1,cmdreduce_constant); //reduce slowly anyways
cmd_send=constrain(cmd_send,0,1000);
}
if (!controllers_connected) { //controllers not connected
cmd_send=0; //safety off
}
if (!controllers_connected) { //controllers not connected
cmd_send=0; //safety off
}
last_cmd_send=cmd_send;
last_cmd_send=cmd_send;
//apply throttle command to all motors
motorparamsFront.cmdL=cmd_send;
motorparamsFront.cmdR=cmd_send;
motorparamsRear.cmdL=cmd_send;
motorparamsRear.cmdR=cmd_send;
//apply throttle command to all motors
motorparamsFront.cmdL=cmd_send;
motorparamsFront.cmdR=cmd_send;
motorparamsRear.cmdL=cmd_send;
motorparamsRear.cmdR=cmd_send;
if (controllers_connected) {
SendSerial(CommandFront,motorparamsFront.cmdL,motorparamsFront.cmdR,Serial2);
SendSerial(CommandRear,motorparamsRear.cmdL,motorparamsRear.cmdR,Serial3);
if (controllers_connected) {
SendSerial(CommandFront,motorparamsFront.cmdL,motorparamsFront.cmdR,Serial2);
SendSerial(CommandRear,motorparamsRear.cmdL,motorparamsRear.cmdR,Serial3);
log_update=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()
}
log_update=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()
}
}