|
@@ -143,6 +143,15 @@ double ADS_3_ACCSts = 0;
|
|
|
|
|
|
static bool gbSendBrake = false;
|
|
|
|
|
|
+
|
|
|
+static double kp = 0.1;
|
|
|
+static double ki = 0.0;
|
|
|
+static double kd = 0.0;
|
|
|
+static double MAXACC = 3.0;
|
|
|
+static int64_t gnLastAccUptime = 0;
|
|
|
+static bool gbUsePID = true;
|
|
|
+static bool gbPrintPIDOut = true;
|
|
|
+
|
|
|
static double gfVehAcc = 0.0;
|
|
|
|
|
|
|
|
@@ -181,6 +190,47 @@ void set_ADSCOM2_Signal(std::string strsigname,double value){
|
|
|
|
|
|
void ExecSend();
|
|
|
|
|
|
+double PIDTorque(double torque)
|
|
|
+{
|
|
|
+ if(gbUsePID == false)return torque;
|
|
|
+
|
|
|
+ int nnow = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
+
|
|
|
+ if((nnow - gnLastAccUptime)>1e9)return torque;
|
|
|
+
|
|
|
+ static double error_previous = 0.0;
|
|
|
+ double fVehWeight = 1800;
|
|
|
+ double fRollForce = 50;
|
|
|
+ const double fRatio = 2.5;
|
|
|
+ double accAim = (torque * fRatio - fRollForce)/fVehWeight;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ double error = accAim - gfVehAcc;
|
|
|
+ double dt = 0.01; //10ms
|
|
|
+ double diff = (error - error_previous)/dt;
|
|
|
+ double integral = integral + error * dt * ki;
|
|
|
+ double output = error * kp + integral + diff * kd;
|
|
|
+
|
|
|
+ double fAccAjust = accAim + output;
|
|
|
+ if(fAccAjust>MAXACC)fAccAjust = MAXACC;
|
|
|
+ if(fAccAjust<=0)fAccAjust = 0.0;
|
|
|
+
|
|
|
+ double fNeed = fRollForce + fVehWeight*fAccAjust;
|
|
|
+ double ftorqueAjust = fNeed/fRatio;
|
|
|
+
|
|
|
+ if(gbPrintPIDOut)
|
|
|
+ {
|
|
|
+ int64_t timesecond = nnow/1e9;
|
|
|
+ int64_t timepart = nnow - timesecond * 1e9;
|
|
|
+ double fnow = timepart; fnow = fnow/1e9;
|
|
|
+ fnow = fnow + timesecond;
|
|
|
+ std::cout<<fnow<<"\t"<<accAim<<"\t"<<fAccAjust<<"\t"<<error<<"\t"<<torque<<"\t"<<ftorqueAjust<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ftorqueAjust;
|
|
|
+}
|
|
|
+
|
|
|
int testnum = 0;
|
|
|
|
|
|
int testwheel = 0;
|