|
@@ -0,0 +1,122 @@
|
|
|
+#include "obs_mobieye.h"
|
|
|
+
|
|
|
+#include <math.h>
|
|
|
+
|
|
|
+obs_mobieye::obs_mobieye()
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void obs_mobieye::UpdateMobieyeObs(iv::mobileye::mobileye &pmobieye)
|
|
|
+{
|
|
|
+ mMutex.lock();
|
|
|
+ mmobieye.CopyFrom(pmobieye);
|
|
|
+ mnUpdateTime = QDateTime::currentMSecsSinceEpoch();
|
|
|
+ mMutex.unlock();
|
|
|
+}
|
|
|
+
|
|
|
+void obs_mobieye::InterpolationTrace(std::vector<iv::Point2D> *pgpsTrace, std::vector<iv::Point2D> &xgpstrace)
|
|
|
+{
|
|
|
+ xgpstrace = *pgpsTrace;
|
|
|
+ unsigned int k;
|
|
|
+ for(k=0;k<(xgpstrace.size()-1);k++)
|
|
|
+ {
|
|
|
+ double fdis;
|
|
|
+ fdis = sqrt(pow(xgpstrace[k].x - xgpstrace[k+1].x,2)
|
|
|
+ +pow(xgpstrace[k].y - xgpstrace[k+1].y,2));
|
|
|
+ if(fdis > 0.3)
|
|
|
+ {
|
|
|
+ qDebug("fdis %f is big, insert a point2d ",fdis);
|
|
|
+ iv::Point2D xpoint;
|
|
|
+ xpoint.x = (xgpstrace[k].x + xgpstrace[k+1].x)/2.0;
|
|
|
+ xpoint.y = (xgpstrace[k].y + xgpstrace[k+1].y)/2.0;
|
|
|
+
|
|
|
+ xgpstrace.insert((xgpstrace.begin() +k+1),xpoint);
|
|
|
+ if(k>0)k = k-1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int obs_mobieye::GetCandidataObs(std::vector<iv::Point2D> &xgpstrace, iv::mobileye::mobileye &xmobieye,
|
|
|
+ const double fveh_width,std::vector<iv::mobieyeobstotrace> & xvectoroptobs)
|
|
|
+{
|
|
|
+ unsigned int i;
|
|
|
+ unsigned int nobjsize = xmobieye.xobj_size();
|
|
|
+ ;
|
|
|
+ for(i=0;i<nobjsize;i++)
|
|
|
+ {
|
|
|
+ iv::mobileye::obs * pobs = xmobieye.mutable_xobj(i);
|
|
|
+
|
|
|
+
|
|
|
+ unsigned int j;
|
|
|
+ unsigned int ntracecount = xgpstrace.size();
|
|
|
+ double fdismin = 1000.0;
|
|
|
+ int index = -1;
|
|
|
+ for(j=0;j<ntracecount;j++)
|
|
|
+ {
|
|
|
+ if(fabs(pobs->pos_x() - xgpstrace[j].y) > 10.0)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(fabs(pobs->pos_x() - xgpstrace[j].x) > 10.0)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ double fdis = sqrt(pow(xgpstrace[j].x - pobs->pos_y(),2)
|
|
|
+ +pow(xgpstrace[j].y - pobs->pos_x(),2));
|
|
|
+ if(fdis<fdismin)
|
|
|
+ {
|
|
|
+ fdismin = fdis;
|
|
|
+ index = j;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(fdismin < (fveh_width + pobs->obswidth()/2.0))
|
|
|
+ {
|
|
|
+ iv::mobieyeobstotrace xmt;
|
|
|
+ xmt.obsindex = i;
|
|
|
+ xmt.traceindex = index;
|
|
|
+ xvectoroptobs.push_back(xmt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+int obs_mobieye::GetObsFromMobieye(std::vector<iv::Point2D> *pgpsTrace,
|
|
|
+ double &xobsdis, double &xobsspeed, double &xttc, double &xobsid,const double fveh_width)
|
|
|
+{
|
|
|
+ xobsdis = -1;
|
|
|
+ xobsspeed = 0;
|
|
|
+ xttc = 300;
|
|
|
+ xobsid = -1;
|
|
|
+ if(pgpsTrace->size()<1)return -1;
|
|
|
+ iv::mobileye::mobileye xmobieye;
|
|
|
+ if((QDateTime::currentMSecsSinceEpoch() - mnUpdateTime) > 3000)
|
|
|
+ {
|
|
|
+ qDebug("more than 3 secons no mobieye data.");
|
|
|
+ return -2;
|
|
|
+ }
|
|
|
+
|
|
|
+ mMutex.lock();
|
|
|
+ xmobieye.CopyFrom(mmobieye);
|
|
|
+ mMutex.unlock();
|
|
|
+
|
|
|
+
|
|
|
+ std::vector<iv::Point2D> xgpstrace;
|
|
|
+
|
|
|
+ InterpolationTrace(pgpsTrace,xgpstrace);
|
|
|
+
|
|
|
+
|
|
|
+ std::vector<iv::mobieyeobstotrace> xvectoroptobs;
|
|
|
+
|
|
|
+ GetCandidataObs(xgpstrace,xmobieye,fveh_width,xvectoroptobs);
|
|
|
+
|
|
|
+ if(xvectoroptobs.size() < 1)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+
|
|
|
+}
|