implement brake ducking
This commit is contained in:
parent
44c5d35a15
commit
3c00060a4e
|
@ -34,7 +34,7 @@ bool controllerRear_connected=false;
|
|||
bool controllers_connected=false;
|
||||
|
||||
#define PIN_THROTTLE A7
|
||||
const uint16_t calib_throttle_min = 400; //better a bit too high than too low
|
||||
const uint16_t calib_throttle_min = 420; //better a bit too high than too low
|
||||
const uint16_t calib_throttle_max = 790;
|
||||
const uint16_t failsafe_throttle_min = 20; //if adc value falls below this failsafe is triggered
|
||||
const uint16_t failsafe_throttle_max = 1000; //if adc value goes above this failsafe is triggered
|
||||
|
@ -66,8 +66,8 @@ float currentConsumed=0; //Ah
|
|||
|
||||
//Driving parameters
|
||||
int16_t minimum_constant_cmd_reduce=1; //reduce cmd every loop by this constant amount when freewheeling/braking
|
||||
int16_t brake_cmdreduce_proportional=100; //cmd gets reduced by an amount proportional to brake position (ignores freewheeling). cmd_new-=brake_cmdreduce_proportional / 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)
|
||||
float startbrakecurrent=3; //Ampere. "targeted brake current @full brake". at what point to start apply brake proportional to brake_pos. for everything above that cmd is reduced by freewheel_break_factor
|
||||
int16_t brake_cmdreduce_proportional=200; //cmd gets reduced by an amount proportional to brake position (ignores freewheeling). cmd_new-=brake_cmdreduce_proportional / 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)
|
||||
float startbrakecurrent=2; //Ampere. "targeted brake current @full brake". at what point to start apply brake proportional to brake_pos. for everything above that cmd is reduced by freewheel_break_factor
|
||||
float startbrakecurrent_offset=0.1; //offset start point for breaking, because of reading fluctuations around 0A. set this slightly above idle current reading
|
||||
|
||||
|
||||
|
@ -366,6 +366,7 @@ void writeLogHeader(HardwareSerial &SerialRef) {
|
|||
SerialRef.print("rpm_FrontL,rpm_FrontR,rpm_RearL,rpm_RearR,");
|
||||
SerialRef.print("temp_Front,temp_Rear,vbat_Front,vbat_Rear,");
|
||||
SerialRef.println("currentAll,throttle,brake,speed,trip,currentConsumed");
|
||||
SerialRef.println("Reduced ducking. More phase advance");
|
||||
}
|
||||
|
||||
void writeLog(HardwareSerial &SerialRef, unsigned long time, MotorParameter &mpfront, MotorParameter &mprear, SerialFeedback &fbfront, SerialFeedback &fbrear, float currentAll, int16_t throttle, int16_t brake)
|
||||
|
@ -415,6 +416,7 @@ void readADC() {
|
|||
throttle_pos=max(0,min(1000,map(throttle_raw,calib_throttle_min,calib_throttle_max,0,1000))); //map and constrain
|
||||
brake_raw = analogRead(PIN_BRAKE);
|
||||
brake_pos=max(0,min(1000,map(brake_raw,calib_brake_min,calib_brake_max,0,1000))); //map and constrain
|
||||
//brake_pos = (int16_t)(pow((brake_pos/1000.0),2)*1000);
|
||||
|
||||
int16_t throttlebreak_pos = throttle_pos-brake_pos*2; //reduce throttle_when applying brake
|
||||
throttle_pos=constrain(throttlebreak_pos,0,1000);
|
||||
|
@ -506,12 +508,13 @@ void sendCMD() {
|
|||
float startbrakecurrent=3; //Ampere. "targeted brake current @full brake". at what point to start apply brake proportional to brake_pos. for everything above that cmd is reduced by freewheel_break_factor
|
||||
float startbrakecurrent_offset=0.1; //offset start point for breaking, because of reading fluctuations around 0A. set this slightly above idle current reading
|
||||
*/
|
||||
int16_t brake_pos_expo = (int16_t)(pow((brake_pos/1000.0),2)*1000);
|
||||
|
||||
float brakepedal_current_multiplier=startbrakecurrent/1000.0; //how much breaking (in Ampere) for unit of brake_pos (0<=brake_pos<=1000)
|
||||
|
||||
int16_t cmdreduce_constant=map(brake_pos,0,1000,0,(int16_t)(brake_cmdreduce_proportional*SENDPERIOD/1000)); //reduce cmd value every cycle
|
||||
int16_t cmdreduce_constant=map(brake_pos_expo,0,1000,0,(int16_t)(brake_cmdreduce_proportional*SENDPERIOD/1000)); //reduce cmd value every cycle
|
||||
|
||||
float freewheel_current=startbrakecurrent_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_current=startbrakecurrent_offset-brake_pos_expo*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
|
||||
|
@ -530,20 +533,26 @@ void sendCMD() {
|
|||
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(minimum_constant_cmd_reduce,cmdreduce_constant); //reduce slowly anyways
|
||||
cmd_send=constrain(cmd_send,0,1000);
|
||||
|
||||
}
|
||||
|
||||
if (!controllers_connected || !armed) { //controllers not connected or not armed
|
||||
cmd_send=0; //safety off
|
||||
}
|
||||
|
||||
cmd_send=constrain(cmd_send,0,1000);
|
||||
|
||||
last_cmd_send=cmd_send;
|
||||
|
||||
int16_t cmd_send_toMotor=constrain(cmd_send-(brake_pos*0.2),0,1000);
|
||||
|
||||
|
||||
|
||||
//apply throttle command to all motors
|
||||
motorparamsFront.cmdL=cmd_send;
|
||||
motorparamsFront.cmdR=cmd_send;
|
||||
motorparamsRear.cmdL=cmd_send;
|
||||
motorparamsRear.cmdR=cmd_send;
|
||||
motorparamsFront.cmdL=cmd_send_toMotor;
|
||||
motorparamsFront.cmdR=cmd_send_toMotor;
|
||||
motorparamsRear.cmdL=cmd_send_toMotor;
|
||||
motorparamsRear.cmdR=cmd_send_toMotor;
|
||||
|
||||
if (controllers_connected) {
|
||||
SendSerial(CommandFront,motorparamsFront.cmdL,motorparamsFront.cmdR,Serial2);
|
||||
|
|
Loading…
Reference in New Issue