ndt.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /***************************************************************************
  2. * Copyright (C) 2005 by TAKEUCHI Eijiro,,, *
  3. * *
  4. * This program is free software; you can redistribute it and/or modify *
  5. * it under the terms of the GNU General Public License as published by *
  6. * the Free Software Foundation; either version 2 of the License, or *
  7. * (at your option) any later version. *
  8. * *
  9. * This program is distributed in the hope that it will be useful, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. ***************************************************************************/
  19. #ifndef __NDT_TKU__
  20. #define __NDT_TKU__
  21. #include <GL/glut.h>
  22. /*root cell size*/
  23. /*
  24. #define MAP_CELLSIZE 0.2 //m
  25. #define MAP_X 128
  26. #define MAP_Y 80
  27. #define MAP_Z 48
  28. */
  29. //#define MAP_CELLSIZE 1.0 //m
  30. #define MAX_ND_NUM (20000000)
  31. // map origin//
  32. // meidai_map
  33. #if 0
  34. #define MAP_CENTER_X (-18407.4 + 215)
  35. #define MAP_CENTER_Y (-93444.9 - 400)
  36. #define MAP_CENTER_Z 33
  37. #define MAP_ROTATION 0.0
  38. //map size
  39. #define MAP_X 1600
  40. #define MAP_Y 1600
  41. #define MAP_Z 200
  42. #endif
  43. // meidai_map_all
  44. #if 0
  45. #define MAP_CENTER_X (-18500)
  46. #define MAP_CENTER_Y (-93800)
  47. #define MAP_CENTER_Z 33
  48. #define MAP_ROTATION 0.0
  49. //map size
  50. #define MAP_X 2200
  51. #define MAP_Y 2600
  52. #define MAP_Z 200
  53. #endif
  54. // moriyama_map
  55. #if 0
  56. #define MAP_CENTER_X -15741
  57. #define MAP_CENTER_Y -85697
  58. #define MAP_CENTER_Z 70
  59. #define MAP_ROTATION 0.7
  60. //map size
  61. #define MAP_X 1600
  62. #define MAP_Y 1600
  63. #define MAP_Z 200
  64. #endif
  65. // tctslc map
  66. #if 0
  67. #define MAP_CENTER_X 3702
  68. #define MAP_CENTER_Y -99430
  69. #define MAP_CENTER_Z 85
  70. #define MAP_ROTATION 0
  71. //map size
  72. #define MAP_X 1600
  73. #define MAP_Y 1600
  74. #define MAP_Z 200
  75. #endif
  76. #if 0
  77. //map offset
  78. #define MAP_CENTER_X 0
  79. #define MAP_CENTER_Y 0
  80. #define MAP_CENTER_Z 0
  81. #define MAP_ROTATION 0
  82. //map size
  83. #define MAP_X 1600
  84. #define MAP_Y 1600
  85. #define MAP_Z 200
  86. #endif
  87. // initial position
  88. // meidai IB (141117_run01,run02)
  89. #if 0
  90. #define INITIAL_X -18354.1
  91. #define INITIAL_Y -93693.4
  92. #define INITIAL_Z 43
  93. #define INITIAL_ROLL 0
  94. #define INITIAL_PITCH 0
  95. #define INITIAL_YAW -0.5
  96. #endif
  97. // meidai (141205_outdoor1)
  98. #if 0
  99. #define INITIAL_X -18526.5
  100. #define INITIAL_Y -93646.0
  101. #define INITIAL_Z 39
  102. #define INITIAL_ROLL 0
  103. #define INITIAL_PITCH 0.03
  104. #define INITIAL_YAW -0.45
  105. #endif
  106. // incubation(0826)
  107. #if 0
  108. #define INITIAL_X (-18407.4 + 215 - 215 + 0.6)
  109. #define INITIAL_Y (-93444.9 - 400 + 400 + 0.65)
  110. #define INITIAL_Z 33
  111. #define INITIAL_ROLL 0
  112. #define INITIAL_PITCH -0.063
  113. #define INITIAL_YAW -1.976
  114. #endif
  115. // incubation parking(1224)
  116. #if 0
  117. #define INITIAL_X (-18389.8)
  118. #define INITIAL_Y (-93499.1)
  119. #define INITIAL_Z 33
  120. #define INITIAL_ROLL 0
  121. #define INITIAL_PITCH 0
  122. #define INITIAL_YAW 1.107
  123. #endif
  124. // moriyama
  125. #if 0
  126. #define INITIAL_X -14771
  127. #define INITIAL_Y -84757
  128. #define INITIAL_Z (39.8)
  129. #define INITIAL_ROLL 0
  130. #define INITIAL_PITCH 0
  131. //#define INITIAL_YAW 0
  132. #define INITIAL_YAW 2.324
  133. #endif
  134. // tctslc
  135. #if 0
  136. #define INITIAL_X 3702
  137. #define INITIAL_Y -99430 // matsu
  138. //#define INITIAL_Y -99426 //zmp
  139. #define INITIAL_Z 87
  140. #define INITIAL_ROLL 0
  141. #define INITIAL_PITCH 0
  142. #define INITIAL_YAW 0 // matsu
  143. //#define INITIAL_YAW 3.14 //zmp
  144. #endif
  145. // no map
  146. #if 0
  147. #define INITIAL_X 0
  148. #define INITIAL_Y 0
  149. #define INITIAL_Z 0
  150. #define INITIAL_ROLL 0
  151. #define INITIAL_PITCH 0
  152. #define INITIAL_YAW 0
  153. #endif
  154. // x=-14763
  155. // y=-84780
  156. // q=-2.34
  157. #define LAYER_NUM 2 // 0.2 0.4 0.8 1.6 3.2(128*80*48)
  158. #define ND_MIN 40
  159. //#define CELL_X (MAP_X*(1<<LAYER_NUM))
  160. //#define CELL_Y (MAP_Y*(1<<LAYER_NUM))
  161. //#define CELL_Z (MAP_Z*(1<<LAYER_NUM))
  162. /*point*/
  163. typedef struct point_type *PointPtr;
  164. typedef struct point_type
  165. {
  166. double x;
  167. double y;
  168. double z;
  169. } Point;
  170. /*point*/
  171. typedef struct postuer_type *PosturePtr;
  172. typedef struct postuer_type
  173. {
  174. double x;
  175. double y;
  176. double z;
  177. double theta;
  178. double theta2;
  179. double theta3;
  180. } Posture;
  181. /*Normal Distribution data type*/
  182. typedef struct Normaldistribution *NDPtr;
  183. typedef struct Normaldistribution
  184. {
  185. /*covariances*/
  186. Point mean;
  187. double covariance[3][3];
  188. double inv_covariance[3][3];
  189. /*for calcurate covariances*/
  190. int flag; /*is updated*/
  191. int sign;
  192. int num; /*data num*/
  193. double m_x; /*mean*/
  194. double m_y;
  195. double m_z;
  196. double c_xx; /*covariance*/
  197. double c_yy;
  198. double c_zz;
  199. double c_xy;
  200. double c_yz;
  201. double c_zx;
  202. double x;
  203. double y;
  204. double z;
  205. double w;
  206. double l[3]; /*eigen value*/
  207. int is_source; /**/
  208. // NDPtr child[8]; /*upper level layer*/
  209. } NormalDistribution;
  210. typedef struct nd_map *NDMapPtr;
  211. typedef struct nd_map
  212. {
  213. NDPtr *nd;
  214. int layer;
  215. int x;
  216. int y;
  217. int z;
  218. int to_x;
  219. int to_y;
  220. double size;
  221. char name[30];
  222. NDMapPtr next;
  223. } NDMap;
  224. typedef struct nd_data *NDDatPtr;
  225. typedef struct nd_data
  226. {
  227. NormalDistribution nd;
  228. int x;
  229. int y;
  230. int z;
  231. int layer;
  232. } NDData;
  233. int add_point_covariance(NDPtr nd, PointPtr p);
  234. int update_covariance(NDPtr nd);
  235. int add_point_map(NDMapPtr ndmap, PointPtr point);
  236. int get_ND(NDMapPtr ndmap, PointPtr point, NDPtr *nd, int mode);
  237. NDMapPtr initialize_NDmap(void);
  238. NDMapPtr initialize_NDmap_layer(int layer, NDMapPtr parent);
  239. int round_covariance(NDPtr nd);
  240. int print_ellipse(FILE *output_file, double mat[3][3], double cx, double cy);
  241. int print_ellipse_nd(FILE *output_file, NDPtr nd);
  242. void glstart(int argc, char *argv[]);
  243. void DrawString(GLfloat x, GLfloat y, double size_x, double size_y, void *font, char *string);
  244. void DrawLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
  245. void display(void);
  246. void reshape(int w, int h);
  247. void draw_all(void);
  248. void draw_map(void);
  249. void keyfunc(unsigned char key, int x, int y);
  250. void mousefunc(int button, int status, int x, int y);
  251. void motionfunc(int x, int y);
  252. void idle(void);
  253. void draw_cell(NDPtr nd);
  254. double probability_on_ND(NDPtr nd, double x, double y, double z);
  255. // void add_ND(NDPtr);
  256. NDPtr add_ND(void);
  257. double calc_summand2d(PointPtr p, NDPtr nd, PosturePtr pose, double *g, double H[3][3]);
  258. int adjust2d(PointPtr scan, int num, PosturePtr initial);
  259. double calc_summand3d(PointPtr p, NDPtr nd, PosturePtr pose, double *g, double H[6][6], double qd3[6][3], double dist);
  260. double adjust3d(PointPtr scan, int num, PosturePtr initial, int target);
  261. void set_sincos2(double a, double b, double g, double sc[3][3]);
  262. void scan_transrate(PointPtr src, PointPtr dst, PosturePtr pose, int num);
  263. // values
  264. extern int g_map_x, g_map_y, g_map_z;
  265. extern double g_map_cellsize;
  266. #endif