|
@@ -80,7 +80,11 @@ Card::Card( string cardid, int cardtype, double z_offset, double offset_x /*= 12
|
|
|
origin_locate.x = origin_locate.y = origin_locate.z = origin_locate.v = 0.0;
|
|
|
last_vx = last_vy = 0.0;
|
|
|
v = 0.0;
|
|
|
- ins_weight = uwb_weight = weight = 0;
|
|
|
+ ins_weight = INS_WEIGHT;
|
|
|
+ uwb_weight = UWB_WEIGHT;
|
|
|
+ weight = 0;
|
|
|
+ acce_cur_state = 0;
|
|
|
+ acce_last_state = 0;
|
|
|
|
|
|
time_stamp_last = 0;
|
|
|
reader_id_last = 0;
|
|
@@ -141,232 +145,50 @@ void Card::set_reader_path(TDOAReaderPathMap* trpm)
|
|
|
this->pTdoaReaderPathMap = trpm;
|
|
|
}
|
|
|
|
|
|
-bool Card::is_pos_state_changed( int nval ) // 考勤
|
|
|
-{
|
|
|
- if(this->pos_state == this->pos_state_old){
|
|
|
- if(this->pos_state_count < nval){
|
|
|
- this->pos_state_count++;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
- //if(this->pos_state_count < nval ){ // 未达到确认次数
|
|
|
- // this->pos_state_count++;
|
|
|
- // return false;
|
|
|
- //}
|
|
|
- this->pos_state_old = this->pos_state;
|
|
|
- this->pos_state_count = 1;
|
|
|
- return true;
|
|
|
- //if(last_area_type_id != cur_area_type_id){
|
|
|
- // if(0 ==last_area_type_id || 0==cur_area_type_id){
|
|
|
- // return true;
|
|
|
- // }
|
|
|
- //}
|
|
|
- //return false;
|
|
|
- //return (this->last_area_type_id != this->cur_area_type_id && 0 == (this->cur_area_type_id & this->last_area_type_id));
|
|
|
-}
|
|
|
-
|
|
|
-void Card::add_dist(_coordinate* dist)
|
|
|
-{
|
|
|
- EnterCriticalSection(&m_csCard);
|
|
|
- string s = concat(dist->reader_id, dist->antenna_id);
|
|
|
-
|
|
|
- int idx = FindDistMap(dist->t);
|
|
|
-
|
|
|
- if(-1 == idx){
|
|
|
- DistQueMapItem dq;
|
|
|
- dq.cardstamp = dist->t;
|
|
|
- dq.distmap[s] = dist;
|
|
|
- _dists.push_back(dq);
|
|
|
- }else{
|
|
|
- _dists[idx].distmap[s] = dist;
|
|
|
- }
|
|
|
-
|
|
|
- if(_dists.size() >= MAX_DIST_CACHE){ // 超过缓存数量限制
|
|
|
- // 计算并删除第一个
|
|
|
- get_coordinate();
|
|
|
- remove_dist_head();
|
|
|
- }
|
|
|
- LeaveCriticalSection(&m_csCard);
|
|
|
-}
|
|
|
-
|
|
|
-time_t Card::get_working_time()
|
|
|
-{
|
|
|
- //return (card_type == CT_VEHICLE) ? leave_park_time : down_time;
|
|
|
- return down_time;
|
|
|
-}
|
|
|
-
|
|
|
-int Card::get_effictive_dist_count( int offset /*= 0*/ )
|
|
|
-{
|
|
|
- if(0 == _dists.size()) return 0;
|
|
|
- time_stamp_cal = _dists.front().cardstamp;
|
|
|
- return (_dists.front().distmap.size());
|
|
|
-
|
|
|
- //int nTimeStamp;
|
|
|
- //if(time_stamp_max == 0 && offset != 0){
|
|
|
- // nTimeStamp = 0xFFFF;
|
|
|
- //}else{
|
|
|
- // nTimeStamp = time_stamp_max - offset;
|
|
|
- //}
|
|
|
- //int ret = 0, tmp = -1;
|
|
|
- //for(int i = 0; i < DIST_COUNT; i++){
|
|
|
- // if(NULL == p_dists[i]) break;
|
|
|
- // if(p_dists[i]->t == nTimeStamp){
|
|
|
- // ret++;
|
|
|
- // }
|
|
|
- //}
|
|
|
- //return ret;
|
|
|
-}
|
|
|
-
|
|
|
-Card::~Card(void)
|
|
|
-{
|
|
|
- if(m_pKalmanFilter){
|
|
|
- delete m_pKalmanFilter;
|
|
|
- m_pKalmanFilter = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- for(int i = 0;i<DIST_COUNT;i++){
|
|
|
- delete p_dists[i];
|
|
|
- p_dists[i] = NULL;
|
|
|
- delete p_dists_locate[i];
|
|
|
- p_dists_locate[i] = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- if(p_dists){
|
|
|
- delete[] p_dists;
|
|
|
- p_dists = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- if(p_dists_locate){
|
|
|
- delete[] p_dists_locate;
|
|
|
- p_dists_locate = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- if(p3_anchors){
|
|
|
- delete[] p3_anchors;
|
|
|
- p3_anchors = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- if(cal_location3){
|
|
|
- delete cal_location3;
|
|
|
- }
|
|
|
-
|
|
|
- DeleteCriticalSection(&m_csCard);
|
|
|
-}
|
|
|
-
|
|
|
-void Card::get_coordinate_2d( int cnt )
|
|
|
-{
|
|
|
- //double d_dist[3];
|
|
|
- //Point2 pt2, pt2_1;
|
|
|
- //for(int i = 0; i < cnt; i++){
|
|
|
- // d_dist[i] = p_dists_locate[i]->d;
|
|
|
-
|
|
|
- //}
|
|
|
- //for(int i=0; i< cnt; i++){
|
|
|
- // if(p_dists[i]->reader_id == 1){
|
|
|
- // p2_anchors[0].x = p_dists[i]->x;
|
|
|
- // p2_anchors[0].y = p_dists[i]->y;
|
|
|
- // d_dist[0] = p_dists[i]->d;
|
|
|
- // }else if(p_dists[i]->reader_id == 2){
|
|
|
- // p2_anchors[1].x = p_dists[i]->x;
|
|
|
- // p2_anchors[1].y = p_dists[i]->y;
|
|
|
- // d_dist[1] = p_dists[i]->d;
|
|
|
- // }if(p_dists[i]->reader_id == 3){
|
|
|
- // p2_anchors[2].x = p_dists[i]->x;
|
|
|
- // p2_anchors[2].y = p_dists[i]->y;
|
|
|
- // d_dist[2] = p_dists[i]->d;
|
|
|
- // }
|
|
|
- //}
|
|
|
- //Mat mat(3, 1, d_dist);
|
|
|
-
|
|
|
- //if(is_anchor_changed){
|
|
|
- // cal_location->setAnchors(p2_anchors);
|
|
|
- // pt2 = cal_location->initPos(mat);
|
|
|
- //} else{
|
|
|
- // pt2 = cal_location->estiPos(mat);
|
|
|
- //}
|
|
|
- //pt2_1 = cal_location->getError();
|
|
|
- //x = pt2.x;
|
|
|
- //y = pt2.y;
|
|
|
- //z = 0;
|
|
|
- //x1 = pt2_1.x;
|
|
|
- //y1 = pt2_1.y;
|
|
|
- //z1 = 0;
|
|
|
-}
|
|
|
-
|
|
|
-void Card::get_coordinate_3d( int cnt )
|
|
|
-{
|
|
|
- double d_dist[ANCHOR_COUNT];
|
|
|
- Point3 pt3, pt3_1;
|
|
|
- for(int i = 0; i < cnt; i++){
|
|
|
- d_dist[i] = p_dists_locate[i]->d;
|
|
|
- }
|
|
|
-
|
|
|
- Mat mat(ANCHOR_COUNT, 1, d_dist);
|
|
|
- if(is_anchor_changed){
|
|
|
- set_anchors(cnt);
|
|
|
- pt3 = cal_location3->initPos(mat);
|
|
|
- } else{
|
|
|
- pt3 = cal_location3->estiPos(mat);
|
|
|
- }
|
|
|
- pt3_1 = cal_location3->getError();
|
|
|
-
|
|
|
- x = pt3.x;
|
|
|
- y = pt3.y;
|
|
|
- z = pt3.z;
|
|
|
- x1 = pt3_1.x;
|
|
|
- y1 = pt3_1.y;
|
|
|
- z1 = pt3_1.z;
|
|
|
-}
|
|
|
-
|
|
|
-double Card::get_speed()
|
|
|
-{
|
|
|
- double speed = 0;
|
|
|
- // 计算速度
|
|
|
- return speed;
|
|
|
-}
|
|
|
-
|
|
|
-void Card::set_anchors( int cnt )
|
|
|
-{
|
|
|
- for(int i = 0; i < cnt; i++){
|
|
|
- p3_anchors[i].x = p_dists[i]->x;
|
|
|
- p3_anchors[i].y = p_dists[i]->y;
|
|
|
- p3_anchors[i].z = p_dists[i]->z;
|
|
|
- }
|
|
|
- cal_location3->setAnchors(p3_anchors, ANCHOR_COUNT);
|
|
|
- is_anchor_changed = false;
|
|
|
-}
|
|
|
-
|
|
|
bool operator==(sync_data& a,sync_data&b){
|
|
|
return a.sync_num == b.sync_num;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * 采用TOF或者TDOA算法进行定位计算
|
|
|
+ * 此函数主要判断此坐标是否需要形成json输出给webserver
|
|
|
*
|
|
|
* param
|
|
|
- * cnt ------ _dists数据条数
|
|
|
+ * acce_state 算法中保存的当前加速度计状态
|
|
|
+ * acce_state_last 算法中保存的上一次加速度计状态
|
|
|
*
|
|
|
* return
|
|
|
- * 无返回值
|
|
|
- *
|
|
|
+ * 无
|
|
|
*/
|
|
|
-void Card::get_coordinate( int cnt )
|
|
|
+void Card::inspect_coordinate(int acce_state,int acce_state_last)
|
|
|
+{
|
|
|
+ //如果是静止或者怠速状态,每次的定位坐标不变化,此时要求采集不再将此数据送往webserver
|
|
|
+ if (acce_state == STATE_ACCE_STATIC)
|
|
|
+ {
|
|
|
+ this->isdealed = false;
|
|
|
+ }
|
|
|
+ else if (acce_state == STATE_ACCE_MOTION)
|
|
|
+ {
|
|
|
+ //如果运动状态时,
|
|
|
+ int nSign = 0;
|
|
|
+ int nState = 0;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Card::algo_tof(int cnt)
|
|
|
{
|
|
|
int i = 0, nCount = 0;
|
|
|
POS *p = NULL;
|
|
|
+
|
|
|
POS tmpPos;
|
|
|
tmpPos.posx = 0;
|
|
|
tmpPos.posy = 0;
|
|
|
tmpPos.pos_radius = 0;
|
|
|
-
|
|
|
-#ifdef ALGORITHM_TOF
|
|
|
-// if(cnt < 2) return; // 只有一个测量值,忽略不计算
|
|
|
int difT = 1;
|
|
|
- //int i = 0, nCount = 0;
|
|
|
bool bfound = false;
|
|
|
- DistMap::iterator it = _dists.front()->mp_dist.begin();
|
|
|
+ DistMap::iterator it = _dists.front().distmap.begin();
|
|
|
if(cnt > 2){
|
|
|
- for(; it != _dists.front()->mp_dist.end(); ++it){
|
|
|
+ for(; it != _dists.front().distmap.end(); ++it){
|
|
|
bfound = false;
|
|
|
// 判断是否已经加入到列表
|
|
|
for(int j=0; j < i; j++){
|
|
@@ -382,7 +204,7 @@ void Card::get_coordinate( int cnt )
|
|
|
}
|
|
|
nCount = i;
|
|
|
}else{
|
|
|
- for(; it != _dists.front()->mp_dist.end(); ++it,i++){
|
|
|
+ for(; it != _dists.front().distmap.end(); ++it,i++){
|
|
|
p_dists_locate[i] = it->second;
|
|
|
}
|
|
|
nCount = cnt;
|
|
@@ -401,8 +223,6 @@ void Card::get_coordinate( int cnt )
|
|
|
this->last_z = p_dists_locate[0]->z;
|
|
|
|
|
|
init_postion = true;
|
|
|
-
|
|
|
- //InitStation();
|
|
|
}
|
|
|
|
|
|
int sta_num = 0;
|
|
@@ -416,24 +236,11 @@ void Card::get_coordinate( int cnt )
|
|
|
info_pre.ant = p_dists_locate[0]->antenna_id;
|
|
|
info_pre.dist = p_dists_locate[0]->d;
|
|
|
|
|
|
- /*POS *p = NULL;
|
|
|
- POS tmpPos;
|
|
|
- tmpPos.posx = 0;
|
|
|
- tmpPos.posy = 0;
|
|
|
- tmpPos.pos_radius = 0;*/
|
|
|
-
|
|
|
- if(info_pre.t == 5){
|
|
|
- int sss = 0;
|
|
|
- sss = info_pre.t;
|
|
|
- }
|
|
|
- //this->p_reader->readerCoveragePath
|
|
|
for(int i = 1;i < nCount;i++){
|
|
|
-
|
|
|
sta_num = p_dists_locate[i]->reader_id - 1;
|
|
|
ant = p_dists_locate[i]->antenna_id;
|
|
|
dist = p_dists_locate[i]->d;
|
|
|
|
|
|
- //p = TOFLocateAlgorithm::Pos(station,sta_num,ant,dist,info_pre);
|
|
|
p = LocateAlgorithm::Pos(*(this->pReaderPathMap),sta_num,ant,dist,info_pre);
|
|
|
|
|
|
if(p == NULL)
|
|
@@ -483,8 +290,10 @@ void Card::get_coordinate( int cnt )
|
|
|
this->v = ((int)(this->last_locate.v*1000))/1000.0;
|
|
|
this->z = 0;
|
|
|
this->a = 0;
|
|
|
+}
|
|
|
|
|
|
-#elif defined ALGORITHM_TYPE_TDOA
|
|
|
+void Card::algo_tdoa(int cnt)
|
|
|
+{
|
|
|
if(cnt < 2){
|
|
|
return;
|
|
|
}
|
|
@@ -503,16 +312,11 @@ void Card::get_coordinate( int cnt )
|
|
|
if(dst >= 5){
|
|
|
bRet = true;
|
|
|
break;
|
|
|
- //continue;
|
|
|
}
|
|
|
}
|
|
|
p_dists_locate[k] = it->second;
|
|
|
}
|
|
|
|
|
|
- this->x = 0;
|
|
|
- this->y = 0;
|
|
|
- this->z = 0;
|
|
|
-
|
|
|
if(bRet){
|
|
|
this->x = this->last_locate.x;
|
|
|
this->y = this->last_locate.y;
|
|
@@ -529,27 +333,30 @@ void Card::get_coordinate( int cnt )
|
|
|
bRet = false;
|
|
|
|
|
|
int maxSyncTimes = 0;
|
|
|
- int acce_state = 2;
|
|
|
+ int acce_state = 0;
|
|
|
+ int acce_state_last = 0;
|
|
|
|
|
|
for(int i=0;i<k;i++){
|
|
|
if(i==0){
|
|
|
maxSyncTimes = p_dists_locate[i]->st;
|
|
|
acce_state = p_dists_locate[i]->acce_state;
|
|
|
+ acce_state_last = p_dists_locate[i]->acce_state_last;
|
|
|
}
|
|
|
else{
|
|
|
if(maxSyncTimes < p_dists_locate[i]->st){
|
|
|
maxSyncTimes = p_dists_locate[i]->st;
|
|
|
acce_state = p_dists_locate[i]->acce_state;
|
|
|
+ acce_state_last = p_dists_locate[i]->acce_state_last;
|
|
|
}
|
|
|
}
|
|
|
ReceiveDataMap::iterator prdm_it = pRdm.find(p_dists_locate[i]->reader_id);
|
|
|
if(prdm_it == pRdm.end()){
|
|
|
-
|
|
|
if(p_dists_locate[i]->tt == LLONG_MAX ){
|
|
|
+ //如果同步时间戳存在异常值,则不走算法定位,直接返回上一次结果值
|
|
|
bRet = true;
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
+ //保存信息用于定位
|
|
|
ReceiveData prd;
|
|
|
prd.reader_id = p_dists_locate[i]->reader_id;
|
|
|
prd.antenna_id = p_dists_locate[i]->antenna_id;
|
|
@@ -562,9 +369,19 @@ void Card::get_coordinate( int cnt )
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- acce_state = 2;
|
|
|
+ //存在异常,直接返回上一次结果值
|
|
|
+ if(bRet){
|
|
|
+ pRdm.clear();
|
|
|
+ this->x = this->last_locate.x;
|
|
|
+ this->y = this->last_locate.y;
|
|
|
+ this->z = INVALID_COORDINATE;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int i = 0, nCount = 0;
|
|
|
+ POS *p = NULL;
|
|
|
bool bOutput = false;
|
|
|
- int nSize = 0;
|
|
|
+ //int nSize = 0;
|
|
|
|
|
|
if(pTdoaReaderPathMap->size() > 0 && pRdm.size() > 1){
|
|
|
this->m_nCalcSyncNum = maxSyncTimes;
|
|
@@ -671,9 +488,9 @@ void Card::get_coordinate( int cnt )
|
|
|
//其他情况,则x2 - x1 > 0 为正
|
|
|
if(cx == sd.x){
|
|
|
if(cy > sd.y){
|
|
|
- nSign = 1;
|
|
|
- }else{
|
|
|
nSign = -1;
|
|
|
+ }else{
|
|
|
+ nSign = 1;
|
|
|
}
|
|
|
}else{
|
|
|
if(cx > sd.x){
|
|
@@ -711,6 +528,13 @@ void Card::get_coordinate( int cnt )
|
|
|
this->last_vx = cvx;
|
|
|
this->last_vy = cvy;
|
|
|
cv = cv*3.6;
|
|
|
+
|
|
|
+ //速度的限制
|
|
|
+ if(cv > 30){
|
|
|
+ this->x = this->last_locate.x;
|
|
|
+ this->y = this->last_locate.y;
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
//删除第一个元素到tmp(含)之间的所有元素
|
|
|
bool bStartDel = false;
|
|
@@ -757,6 +581,12 @@ void Card::get_coordinate( int cnt )
|
|
|
|
|
|
#ifdef ALGORITHM_TYPE_INS
|
|
|
bRet = false;
|
|
|
+ if(acce_state!=acce_state_last){
|
|
|
+ //状态发生了变化
|
|
|
+ acce_state = 4;
|
|
|
+ }else{
|
|
|
+ acce_state = 5;
|
|
|
+ }
|
|
|
switch(acce_state){
|
|
|
case 0: //熄火
|
|
|
case 1: //怠速
|
|
@@ -773,6 +603,26 @@ void Card::get_coordinate( int cnt )
|
|
|
//如果根据加速度状态判断为后退,则取-1
|
|
|
ins_state = -1;
|
|
|
break;
|
|
|
+ case 4: //状态发生了变化
|
|
|
+ bRet = true;
|
|
|
+ ins_state = this->accelerate_state_last;
|
|
|
+ double cweight = 0;
|
|
|
+ cweight = this->ins_weight * ins_state + this->uwb_weight*uwb_state;
|
|
|
+ if(cweight>=INS_WEIGHT*-1&&cweight<=INS_WEIGHT){
|
|
|
+ this->ins_weight = abs(cweight);
|
|
|
+ }else{
|
|
|
+ this->ins_weight = INS_WEIGHT;
|
|
|
+ }
|
|
|
+ if(k*uwb_weight < 0){
|
|
|
+ //状态改变,这一次的状态和上一次的状态不同
|
|
|
+ bUseKalman = false;
|
|
|
+ }else{
|
|
|
+ bUseKalman = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 5: //状态未发生了变化
|
|
|
+ //如果UWB状态发生了变化,则此次定位有问题
|
|
|
+ break;
|
|
|
}
|
|
|
if(!bRet){
|
|
|
double cweight = 0;
|
|
@@ -966,7 +816,7 @@ void Card::get_coordinate( int cnt )
|
|
|
}else{
|
|
|
this->x = this->last_locate.x;
|
|
|
this->y = this->last_locate.y;
|
|
|
- this->z = this->last_locate.z;
|
|
|
+ this->z = -5;//this->last_locate.z
|
|
|
this->v = this->last_locate.v;
|
|
|
}
|
|
|
|
|
@@ -1018,10 +868,224 @@ void Card::get_coordinate( int cnt )
|
|
|
}
|
|
|
|
|
|
pRdm.clear();
|
|
|
+}
|
|
|
|
|
|
-#else
|
|
|
+bool Card::is_pos_state_changed( int nval ) // 考勤
|
|
|
+{
|
|
|
+ if(this->pos_state == this->pos_state_old){
|
|
|
+ if(this->pos_state_count < nval){
|
|
|
+ this->pos_state_count++;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //if(this->pos_state_count < nval ){ // 未达到确认次数
|
|
|
+ // this->pos_state_count++;
|
|
|
+ // return false;
|
|
|
+ //}
|
|
|
+ this->pos_state_old = this->pos_state;
|
|
|
+ this->pos_state_count = 1;
|
|
|
+ return true;
|
|
|
+ //if(last_area_type_id != cur_area_type_id){
|
|
|
+ // if(0 ==last_area_type_id || 0==cur_area_type_id){
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //return false;
|
|
|
+ //return (this->last_area_type_id != this->cur_area_type_id && 0 == (this->cur_area_type_id & this->last_area_type_id));
|
|
|
+}
|
|
|
+
|
|
|
+void Card::add_dist(_coordinate* dist)
|
|
|
+{
|
|
|
+ EnterCriticalSection(&m_csCard);
|
|
|
+ string s = concat(dist->reader_id, dist->antenna_id);
|
|
|
+
|
|
|
+ int idx = FindDistMap(dist->t);
|
|
|
+
|
|
|
+ if(-1 == idx){
|
|
|
+ DistQueMapItem dq;
|
|
|
+ dq.cardstamp = dist->t;
|
|
|
+ dq.distmap[s] = dist;
|
|
|
+ _dists.push_back(dq);
|
|
|
+ }else{
|
|
|
+ _dists[idx].distmap[s] = dist;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_dists.size() >= MAX_DIST_CACHE){ // 超过缓存数量限制
|
|
|
+ // 计算并删除第一个
|
|
|
+ get_coordinate();
|
|
|
+ remove_dist_head();
|
|
|
+ }
|
|
|
+ LeaveCriticalSection(&m_csCard);
|
|
|
+}
|
|
|
+
|
|
|
+time_t Card::get_working_time()
|
|
|
+{
|
|
|
+ //return (card_type == CT_VEHICLE) ? leave_park_time : down_time;
|
|
|
+ return down_time;
|
|
|
+}
|
|
|
+
|
|
|
+int Card::get_effictive_dist_count( int offset /*= 0*/ )
|
|
|
+{
|
|
|
+ if(0 == _dists.size()) return 0;
|
|
|
+ time_stamp_cal = _dists.front().cardstamp;
|
|
|
+ return (_dists.front().distmap.size());
|
|
|
+
|
|
|
+ //int nTimeStamp;
|
|
|
+ //if(time_stamp_max == 0 && offset != 0){
|
|
|
+ // nTimeStamp = 0xFFFF;
|
|
|
+ //}else{
|
|
|
+ // nTimeStamp = time_stamp_max - offset;
|
|
|
+ //}
|
|
|
+ //int ret = 0, tmp = -1;
|
|
|
+ //for(int i = 0; i < DIST_COUNT; i++){
|
|
|
+ // if(NULL == p_dists[i]) break;
|
|
|
+ // if(p_dists[i]->t == nTimeStamp){
|
|
|
+ // ret++;
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //return ret;
|
|
|
+}
|
|
|
+
|
|
|
+Card::~Card(void)
|
|
|
+{
|
|
|
+ if(m_pKalmanFilter){
|
|
|
+ delete m_pKalmanFilter;
|
|
|
+ m_pKalmanFilter = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ for(int i = 0;i<DIST_COUNT;i++){
|
|
|
+ delete p_dists[i];
|
|
|
+ p_dists[i] = NULL;
|
|
|
+ delete p_dists_locate[i];
|
|
|
+ p_dists_locate[i] = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(p_dists){
|
|
|
+ delete[] p_dists;
|
|
|
+ p_dists = NULL;
|
|
|
+ }
|
|
|
|
|
|
+ if(p_dists_locate){
|
|
|
+ delete[] p_dists_locate;
|
|
|
+ p_dists_locate = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(p3_anchors){
|
|
|
+ delete[] p3_anchors;
|
|
|
+ p3_anchors = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cal_location3){
|
|
|
+ delete cal_location3;
|
|
|
+ }
|
|
|
+
|
|
|
+ DeleteCriticalSection(&m_csCard);
|
|
|
+}
|
|
|
+
|
|
|
+void Card::get_coordinate_2d( int cnt )
|
|
|
+{
|
|
|
+ //double d_dist[3];
|
|
|
+ //Point2 pt2, pt2_1;
|
|
|
+ //for(int i = 0; i < cnt; i++){
|
|
|
+ // d_dist[i] = p_dists_locate[i]->d;
|
|
|
+
|
|
|
+ //}
|
|
|
+ //for(int i=0; i< cnt; i++){
|
|
|
+ // if(p_dists[i]->reader_id == 1){
|
|
|
+ // p2_anchors[0].x = p_dists[i]->x;
|
|
|
+ // p2_anchors[0].y = p_dists[i]->y;
|
|
|
+ // d_dist[0] = p_dists[i]->d;
|
|
|
+ // }else if(p_dists[i]->reader_id == 2){
|
|
|
+ // p2_anchors[1].x = p_dists[i]->x;
|
|
|
+ // p2_anchors[1].y = p_dists[i]->y;
|
|
|
+ // d_dist[1] = p_dists[i]->d;
|
|
|
+ // }if(p_dists[i]->reader_id == 3){
|
|
|
+ // p2_anchors[2].x = p_dists[i]->x;
|
|
|
+ // p2_anchors[2].y = p_dists[i]->y;
|
|
|
+ // d_dist[2] = p_dists[i]->d;
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //Mat mat(3, 1, d_dist);
|
|
|
+
|
|
|
+ //if(is_anchor_changed){
|
|
|
+ // cal_location->setAnchors(p2_anchors);
|
|
|
+ // pt2 = cal_location->initPos(mat);
|
|
|
+ //} else{
|
|
|
+ // pt2 = cal_location->estiPos(mat);
|
|
|
+ //}
|
|
|
+ //pt2_1 = cal_location->getError();
|
|
|
+ //x = pt2.x;
|
|
|
+ //y = pt2.y;
|
|
|
+ //z = 0;
|
|
|
+ //x1 = pt2_1.x;
|
|
|
+ //y1 = pt2_1.y;
|
|
|
+ //z1 = 0;
|
|
|
+}
|
|
|
+
|
|
|
+void Card::get_coordinate_3d( int cnt )
|
|
|
+{
|
|
|
+ double d_dist[ANCHOR_COUNT];
|
|
|
+ Point3 pt3, pt3_1;
|
|
|
+ for(int i = 0; i < cnt; i++){
|
|
|
+ d_dist[i] = p_dists_locate[i]->d;
|
|
|
+ }
|
|
|
+
|
|
|
+ Mat mat(ANCHOR_COUNT, 1, d_dist);
|
|
|
+ if(is_anchor_changed){
|
|
|
+ set_anchors(cnt);
|
|
|
+ pt3 = cal_location3->initPos(mat);
|
|
|
+ } else{
|
|
|
+ pt3 = cal_location3->estiPos(mat);
|
|
|
+ }
|
|
|
+ pt3_1 = cal_location3->getError();
|
|
|
+
|
|
|
+ x = pt3.x;
|
|
|
+ y = pt3.y;
|
|
|
+ z = pt3.z;
|
|
|
+ x1 = pt3_1.x;
|
|
|
+ y1 = pt3_1.y;
|
|
|
+ z1 = pt3_1.z;
|
|
|
+}
|
|
|
+
|
|
|
+double Card::get_speed()
|
|
|
+{
|
|
|
+ double speed = 0;
|
|
|
+ // 计算速度
|
|
|
+ return speed;
|
|
|
+}
|
|
|
+
|
|
|
+void Card::set_anchors( int cnt )
|
|
|
+{
|
|
|
+ for(int i = 0; i < cnt; i++){
|
|
|
+ p3_anchors[i].x = p_dists[i]->x;
|
|
|
+ p3_anchors[i].y = p_dists[i]->y;
|
|
|
+ p3_anchors[i].z = p_dists[i]->z;
|
|
|
+ }
|
|
|
+ cal_location3->setAnchors(p3_anchors, ANCHOR_COUNT);
|
|
|
+ is_anchor_changed = false;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * 采用TOF或者TDOA算法进行定位计算
|
|
|
+ *
|
|
|
+ * param
|
|
|
+ * cnt ------ _dists数据条数
|
|
|
+ *
|
|
|
+ * return
|
|
|
+ * 无返回值
|
|
|
+ *
|
|
|
+*/
|
|
|
+void Card::get_coordinate( int cnt )
|
|
|
+{
|
|
|
+#ifdef ALGORITHM_TOF
|
|
|
+ algo_tof(cnt);
|
|
|
+#elif defined ALGORITHM_TYPE_TDOA
|
|
|
+ algo_tdoa(cnt);
|
|
|
+#else
|
|
|
+
|
|
|
#endif
|
|
|
+ inspect_coordinate(this->acce_cur_state,this->acce_last_state);
|
|
|
+
|
|
|
if(_isnan(this->x) || _isnan(this->y) || _isnan(this->z)){
|
|
|
this->x = this->last_x;
|
|
|
this->y = this->last_y;
|