|
@@ -92,6 +92,7 @@ static double MAXACC = 3.0;
|
|
static int64_t gnLastAccUptime = 0;
|
|
static int64_t gnLastAccUptime = 0;
|
|
static bool gbUsePID = true;
|
|
static bool gbUsePID = true;
|
|
static bool gbPrintPIDOut = true;
|
|
static bool gbPrintPIDOut = true;
|
|
|
|
+static double TorqueRatio = 1.4;
|
|
|
|
|
|
static double gfVehAcc = 0.0;
|
|
static double gfVehAcc = 0.0;
|
|
|
|
|
|
@@ -116,7 +117,7 @@ double PIDTorque(double torque)
|
|
{
|
|
{
|
|
if(gbUsePID == false)return torque;
|
|
if(gbUsePID == false)return torque;
|
|
|
|
|
|
- int nnow = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
|
|
|
+ int64_t nnow = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
|
|
|
if((nnow - gnLastAccUptime)>1e9)return torque;
|
|
if((nnow - gnLastAccUptime)>1e9)return torque;
|
|
|
|
|
|
@@ -127,6 +128,7 @@ double PIDTorque(double torque)
|
|
const double fRatio = 2.5;
|
|
const double fRatio = 2.5;
|
|
double accAim = (torque * fRatio - fRollForce)/fVehWeight;
|
|
double accAim = (torque * fRatio - fRollForce)/fVehWeight;
|
|
|
|
|
|
|
|
+ static bool bPrintTitle = false;
|
|
|
|
|
|
|
|
|
|
double error = accAim - gfVehAcc;
|
|
double error = accAim - gfVehAcc;
|
|
@@ -143,13 +145,19 @@ double PIDTorque(double torque)
|
|
|
|
|
|
error_previous = error;
|
|
error_previous = error;
|
|
|
|
|
|
|
|
+ if(bPrintTitle == false)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"Time\t"<<"Speed(km/h)\t"<<"RealAcc(m/s2)\t"<<"AimAcc(m/s2)\t"<<"AjustAcc(m/s2)\t"<<"Error(m/s2)\t"<<"RawTorque\t"<<"AjustTorque"<<std::endl;
|
|
|
|
+ bPrintTitle = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
if(gbPrintPIDOut)
|
|
if(gbPrintPIDOut)
|
|
{
|
|
{
|
|
int64_t timesecond = nnow/1e9;
|
|
int64_t timesecond = nnow/1e9;
|
|
int64_t timepart = nnow - timesecond * 1e9;
|
|
int64_t timepart = nnow - timesecond * 1e9;
|
|
double fnow = timepart; fnow = fnow/1e9;
|
|
double fnow = timepart; fnow = fnow/1e9;
|
|
fnow = fnow + timesecond;
|
|
fnow = fnow + timesecond;
|
|
- std::cout<<fnow<<"\t"<<gfVehSpd<<"\t"<<accAim<<"\t"<<fAccAjust<<"\t"<<error<<"\t"<<torque<<"\t"<<ftorqueAjust<<std::endl;
|
|
|
|
|
|
+ std::cout<<fnow<<"\t"<<gfVehSpd<<"\t"<<gfVehAcc<<accAim<<"\t"<<fAccAjust<<"\t"<<error<<"\t"<<torque<<"\t"<<ftorqueAjust<<std::endl;
|
|
}
|
|
}
|
|
|
|
|
|
return ftorqueAjust;
|
|
return ftorqueAjust;
|
|
@@ -173,7 +181,7 @@ void executeDecition(const iv::brain::decition &decition)
|
|
if(fwheel<-430)fwheel = 430;
|
|
if(fwheel<-430)fwheel = 430;
|
|
if(fwheel>380)fwheel = 380;
|
|
if(fwheel>380)fwheel = 380;
|
|
|
|
|
|
- double ftorque = decition.torque();
|
|
|
|
|
|
+ double ftorque = decition.torque() * TorqueRatio;
|
|
double fbrake = decition.brake();
|
|
double fbrake = decition.brake();
|
|
|
|
|
|
#ifdef PIDTEST
|
|
#ifdef PIDTEST
|
|
@@ -193,6 +201,8 @@ void executeDecition(const iv::brain::decition &decition)
|
|
ftorque = PIDTorque(acctotorque(fpidtestacc));
|
|
ftorque = PIDTorque(acctotorque(fpidtestacc));
|
|
fbrake = 0;
|
|
fbrake = 0;
|
|
}
|
|
}
|
|
|
|
+#else
|
|
|
|
+ ftorque = PIDTorque(ftorque);
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
@@ -797,6 +807,7 @@ void Listencanrecv0()
|
|
double facc = value;
|
|
double facc = value;
|
|
facc = facc * 0.001 - 2.0;
|
|
facc = facc * 0.001 - 2.0;
|
|
gfVehAcc = facc*9.8;
|
|
gfVehAcc = facc*9.8;
|
|
|
|
+ gnLastAccUptime = std::chrono::system_clock::now().time_since_epoch().count();
|
|
// std::cout<<" acc : "<<gfVehAcc<<std::endl;
|
|
// std::cout<<" acc : "<<gfVehAcc<<std::endl;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -896,6 +907,13 @@ int main(int argc, char *argv[])
|
|
gstrmemdecition = xp.GetParam("dection","deciton");
|
|
gstrmemdecition = xp.GetParam("dection","deciton");
|
|
gstrmemchassis = xp.GetParam("chassismsgname","chassis");
|
|
gstrmemchassis = xp.GetParam("chassismsgname","chassis");
|
|
|
|
|
|
|
|
+ kp = xp.GetParam("kp",0.5);
|
|
|
|
+ ki = xp.GetParam("ki",0.3);
|
|
|
|
+ kd = xp.GetParam("kd",0.01);
|
|
|
|
+ gbPrintPIDOut = xp.GetParam("PringtPIDOut",false);
|
|
|
|
+ TorqueRatio = xp.GetParam("TorqueRatio",1.4);
|
|
|
|
+
|
|
|
|
+
|
|
gpacansend = iv::modulecomm::RegisterSend(gstrmemcansend.data(),10000,1);
|
|
gpacansend = iv::modulecomm::RegisterSend(gstrmemcansend.data(),10000,1);
|
|
gpadecition = iv::modulecomm::RegisterRecv(gstrmemdecition.data(),ListenDeciton);
|
|
gpadecition = iv::modulecomm::RegisterRecv(gstrmemdecition.data(),ListenDeciton);
|
|
gpachassis = iv::modulecomm::RegisterRecv(gstrmemchassis.data(),UpdateChassis);
|
|
gpachassis = iv::modulecomm::RegisterRecv(gstrmemchassis.data(),UpdateChassis);
|