base_data_struct.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #ifndef BASE_DATA_STRUCT_H
  2. #define BASE_DATA_STRUCT_H
  3. #include <memory>
  4. #include <unordered_map>
  5. namespace algorithm{
  6. namespace base{
  7. // 分站接收数据结构体
  8. struct ReceiveData{
  9. unsigned int reader_id; // 分站号
  10. unsigned short antenna_id; // 天线号
  11. long long rec_time_stamp; // 分站接收时间,一个7字节的无符号数
  12. int special;
  13. double x; //分站的x坐标
  14. double y; //分站的y坐标
  15. double z; //分站的z坐标
  16. ReceiveData(){
  17. reader_id = 0;
  18. antenna_id = 0;
  19. rec_time_stamp = 0;
  20. x = y = z = 0.0;
  21. special = 0;
  22. };
  23. };
  24. typedef unordered_map<unsigned long long ,std::shared_ptr<ReceiveData>> ReceiveDataUnorderedMap;
  25. template<typename _Scalar, int NX = Eigen::Dynamic, int NY = Eigen::Dynamic>
  26. class Functor
  27. {
  28. private:
  29. int m_inputs, m_values;
  30. public:
  31. typedef _Scalar Scalar;
  32. enum {
  33. InputsAtCompileTime = NX,
  34. ValuesAtCompileTime = NY
  35. };
  36. typedef Eigen::Matrix<Scalar,InputsAtCompileTime,1> InputType;
  37. typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,1> ValueType;
  38. typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,InputsAtCompileTime> JacobianType;
  39. Functor() : m_inputs(InputsAtCompileTime), m_values(ValuesAtCompileTime) {}
  40. Functor(int inputs, int values) : m_inputs(inputs), m_values(values) {}
  41. int inputs() const { return m_inputs; }
  42. int values() const { return m_values; }
  43. };
  44. class TDOAFunctor : public Functor<double>
  45. {
  46. private:
  47. Eigen::MatrixXd _data, _pos;
  48. public:
  49. TDOAFunctor(const Eigen::MatrixXd &data,const Eigen::MatrixXd &pos): Functor<double>(3,3),_data(data),_pos(pos) {}
  50. int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const
  51. {
  52. for (int i = 0; i < values(); i++)
  53. {
  54. fvec(i) = sqrt(pow(_data(i,0) - x(0),2) + pow(_data(i,1) - x(1),2) + pow(_data(i,2) - x(2),2))
  55. - sqrt(pow(_pos(0) - x(0),2) + pow(_pos(1) - x(1),2) + pow(_pos(2) - x(2),2))
  56. - _data(i,3);
  57. }
  58. return 0;
  59. }
  60. };
  61. };
  62. const int MAX_READER_TDOA_PATH_NUMS = 10; //主要是因为拐弯处可能存在多解的原因
  63. const double INVALID_COORDINATE = -1000.0;
  64. enum DIMENSION{
  65. _1D = 1,
  66. _2D,
  67. _3D
  68. };
  69. enum ALGO_LOC_TYPE{
  70. ALGO_LOC_SUCCESSED = 0, //算法定位成功
  71. ALGO_FAILED_CONDITION_1, //同步序号相差大于5
  72. ALGO_FAILED_CONDITION_2, //相同卡序列号,时间同步序号却相差大于5
  73. ALGO_FAILED_CONDITION_3, //时间同步戳值存在异常
  74. ALGO_FAILED_CONDITION_4, //卡的上次时间戳大于卡的本次时间戳
  75. ALGO_FAILED_CONDITION_5, //人卡加速度超限
  76. ALGO_FAILED_CONDITION_6, //车卡加速度超限
  77. ALGO_FAILED_CONDITION_7, //车卡速度超限
  78. ALGO_FAILED_CONDITION_8, //卡尔曼连续2s定位失败等
  79. ALGO_FAILED_CONDITION_9, //分站时间戳的距离差值大于分站之间的距离
  80. ALGO_FAILED_CONDITION_10, //分站之间无地图集
  81. ALGO_FAILED_CONDITION_11, //定位无解or解的个数为0
  82. ALGO_FAILED_CONDITION_12, //分站附近(小于4m),分站不是特殊分站
  83. ALGO_FAILED_CONDITION_13, //解与无地图集两分站之间的距离差(大于10m)
  84. ALGO_FAILED_CONDITION_14, //定位结果距离定位分站之间的距离差大于4
  85. ALGO_FAILED_CONDITION_15, //参与定位的数据条数小于2
  86. ALGO_LOC_TOTAL
  87. };
  88. struct POS{
  89. double posx; // 以米为单位坐标
  90. double posy;
  91. double posz;
  92. //误差范围
  93. double pos_radius;
  94. //以像素为单位的坐标,米/地图比例尺 = 像素
  95. double cx;
  96. double cy;
  97. double cz;
  98. //三个方向的速度
  99. double cvx;
  100. double cvy;
  101. double cvz;
  102. //加速度
  103. double av;
  104. //保存定位结果的两个分站信息
  105. int nFirstReader;
  106. int nSecondReader;
  107. //精度参考
  108. double dDiff[MAX_READER_TDOA_PATH_NUMS];
  109. double dis_diff;
  110. //定位失败的状态
  111. int reason;
  112. int status;
  113. int dimension;
  114. unsigned long long card_count; //卡的ct号
  115. unsigned short card_timestamp;
  116. bool update; //是否需要保存到同步队列中
  117. bool is_back;
  118. bool is_fit; //是否是拟合数据
  119. //当前分站同步序号与参考数据的分站同步序号时间差值
  120. double diff_reader_sync_num;
  121. double delta_time; //时间差
  122. //参考数据的定位坐标
  123. double ref_x;
  124. double ref_y;
  125. double ref_z;
  126. double origin_speed; //原始定位结果算的速度
  127. double sumVariance; // 保存各定位解之间差值的和
  128. POS(){
  129. card_timestamp = 0;
  130. nFirstReader = 0;
  131. nSecondReader = 0;
  132. pos_radius = 999999.9;
  133. posx = posy = posz = INVALID_COORDINATE;
  134. cx = cy = cz = cvx = cvy = cvz = 0.0;
  135. av = 0.0;
  136. status = 0;
  137. card_count = 0;
  138. for (int i=0;i<MAX_READER_TDOA_PATH_NUMS;i++)
  139. {
  140. dDiff[i] = 0;
  141. }
  142. dis_diff = 999999.9;
  143. update = false;
  144. is_fit = false;
  145. is_back = false;
  146. origin_speed = 0;
  147. sumVariance = 0;
  148. diff_reader_sync_num = 0;
  149. delta_time = 0.0;
  150. ref_x = ref_y = ref_z = 0.0;
  151. dimension = _1D;
  152. reason = ALGO_LOC_SUCCESSED;
  153. }
  154. POS& operator=(POS& tmp){
  155. this->card_count = tmp.card_count;
  156. this->card_timestamp = tmp.card_timestamp;
  157. nFirstReader = tmp.nFirstReader;
  158. nSecondReader = tmp.nSecondReader;
  159. posx = tmp.posx;
  160. posy = tmp.posy;
  161. posz = tmp.posz;
  162. cx = tmp.cx;
  163. cy = tmp.cy;
  164. cz = tmp.cz;
  165. cvx = tmp.cvx;
  166. cvy = tmp.cvy;
  167. cvz = tmp.cvz;
  168. av = tmp.av;
  169. update = tmp.update;
  170. origin_speed = tmp.origin_speed;
  171. status = tmp.status;
  172. is_back = tmp.is_back;
  173. diff_reader_sync_num = tmp.diff_reader_sync_num;
  174. delta_time = tmp.delta_time;
  175. dis_diff = tmp.dis_diff;
  176. ref_x = tmp.ref_x;
  177. ref_y = tmp.ref_y;
  178. ref_z = tmp.ref_z;
  179. sumVariance = tmp.sumVariance;
  180. for (int i=0;i<MAX_READER_TDOA_PATH_NUMS;i++)
  181. {
  182. dDiff[i] = tmp.dDiff[i];
  183. }
  184. pos_radius = tmp.pos_radius;
  185. reason = ALGO_LOC_SUCCESSED;
  186. dimension = tmp.dimension;
  187. return *this;
  188. }
  189. };
  190. // 定位坐标
  191. struct _coordinate{
  192. _coordinate(){
  193. t = 0;
  194. reader_id = 0;
  195. tt = 0;
  196. d = 0.0;
  197. sync_num = 0;
  198. x = 0.0;
  199. y = 0.0;
  200. z = 0.0;
  201. a = 0.0;
  202. v = 0.0;
  203. antenna_id = 0;
  204. d_offset = 0.0;
  205. special = 0;
  206. acceleration = 0;
  207. acce_state = 0;
  208. acce_state_last = 0;
  209. ins_direction = 0;
  210. rangingtype = 1; // 0 tof,1 toda
  211. cur_time = time(NULL);
  212. ins_request_check = 0;
  213. dimension = _1D;
  214. strength = 0;
  215. }
  216. int t; // 定位时间戳
  217. int reader_id; // 分站编号
  218. unsigned long long syncRootId; // tdoa主节点
  219. unsigned long long tt; // 分站接收的时间,为同步及线性插值后的时间
  220. double d; // 距离
  221. double x; // x坐标
  222. double y; // y坐标
  223. double z; // z坐标
  224. double a; // 平面角度
  225. double v; // 速度
  226. int antenna_id;
  227. int sync_num; //同步序号
  228. int acce_state; //加速度状态
  229. int acce_state_last; //加速度计上一次状态
  230. int ins_direction; //惯导方向
  231. int special; //分站是否属于特殊分站,0属于特殊分站,1普通分站
  232. int rangingtype;
  233. int reason;
  234. int ins_request_check;
  235. int dimension; //指定一维,二维,三维的类型
  236. int strength;
  237. double acceleration; //加速度
  238. double d_offset; // 与显示距离的偏移,用来修正单基站的情况
  239. double recv_signal_power; //接收信号功率,计算值
  240. time_t cur_time;
  241. _coordinate& operator=(_coordinate &tmp){
  242. t = tmp.t;
  243. reader_id = tmp.reader_id;
  244. tt = tmp.tt;
  245. d = tmp.d;
  246. sync_num = tmp.sync_num;
  247. x = tmp.x;
  248. y = tmp.y;
  249. z = tmp.z;
  250. a = tmp.a;
  251. v = tmp.v;
  252. antenna_id = tmp.antenna_id;
  253. d_offset = tmp.d_offset;
  254. special = tmp.special;
  255. acceleration = tmp.acceleration;
  256. acce_state = tmp.acce_state;
  257. acce_state_last = tmp.acce_state_last;
  258. ins_direction = tmp.ins_direction;
  259. rangingtype = tmp.rangingtype;
  260. reason = ALGO_LOC_SUCCESSED;
  261. cur_time = tmp.cur_time;
  262. ins_request_check = tmp.ins_request_check;
  263. dimension = tmp.dimension;
  264. strength = tmp.strength;
  265. return *this;
  266. }
  267. bool operator==(_coordinate &tmp)
  268. {
  269. if (x == tmp.x && y == tmp.y)
  270. {
  271. return true;
  272. }
  273. return false;
  274. }
  275. };
  276. };
  277. #endif