diff --git a/controller_teensy/src/main.cpp b/controller_teensy/src/main.cpp index edbace6..bb91f09 100644 --- a/controller_teensy/src/main.cpp +++ b/controller_teensy/src/main.cpp @@ -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=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