deca_range_tables.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*! ----------------------------------------------------------------------------
  2. * @file deca_range_tables.c
  3. * @brief DW1000 range correction tables
  4. *
  5. * @attention
  6. *
  7. * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
  8. *
  9. * All rights reserved.
  10. *
  11. */
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include "deca_device_api.h"
  15. #include "deca_param_types.h"
  16. #define NUM_16M_OFFSET (37)
  17. #define NUM_16M_OFFSETWB (68)
  18. #define NUM_64M_OFFSET (26)
  19. #define NUM_64M_OFFSETWB (59)
  20. const uint8_t chan_idxnb[NUM_CH_SUPPORTED] = {0, 0, 1, 2, 0, 3, 0, 0}; //only channels 1,2,3 and 5 are in the narrow band tables
  21. const uint8_t chan_idxwb[NUM_CH_SUPPORTED] = {0, 0, 0, 0, 0, 0, 0, 1}; //only channels 4 and 7 are in in the wide band tables
  22. //---------------------------------------------------------------------------------------------------------------------------
  23. // Range Bias Correction TABLES of range values in integer units of 25 CM, for 8-bit unsigned storage, MUST END IN 255 !!!!!!
  24. //---------------------------------------------------------------------------------------------------------------------------
  25. // offsets to nearest centimeter for index 0, all rest are +1 cm per value
  26. #define CM_OFFSET_16M_NB (-23) // for normal band channels at 16 MHz PRF
  27. #define CM_OFFSET_16M_WB (-28) // for wider band channels at 16 MHz PRF
  28. #define CM_OFFSET_64M_NB (-17) // for normal band channels at 64 MHz PRF
  29. #define CM_OFFSET_64M_WB (-30) // for wider band channels at 64 MHz PRF
  30. //---------------------------------------------------------------------------------------------------------------------------
  31. // range25cm16PRFnb: Range Bias Correction table for narrow band channels at 16 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
  32. //---------------------------------------------------------------------------------------------------------------------------
  33. const uint8_t range25cm16PRFnb[4][NUM_16M_OFFSET] =
  34. {
  35. // ch 1 - range25cm16PRFnb
  36. {
  37. 1,
  38. 3,
  39. 4,
  40. 5,
  41. 7,
  42. 9,
  43. 11,
  44. 12,
  45. 13,
  46. 15,
  47. 18,
  48. 20,
  49. 23,
  50. 25,
  51. 28,
  52. 30,
  53. 33,
  54. 36,
  55. 40,
  56. 43,
  57. 47,
  58. 50,
  59. 54,
  60. 58,
  61. 63,
  62. 66,
  63. 71,
  64. 76,
  65. 82,
  66. 89,
  67. 98,
  68. 109,
  69. 127,
  70. 155,
  71. 222,
  72. 255,
  73. 255
  74. },
  75. // ch 2 - range25cm16PRFnb
  76. {
  77. 1,
  78. 2,
  79. 4,
  80. 5,
  81. 6,
  82. 8,
  83. 9,
  84. 10,
  85. 12,
  86. 13,
  87. 15,
  88. 18,
  89. 20,
  90. 22,
  91. 24,
  92. 27,
  93. 29,
  94. 32,
  95. 35,
  96. 38,
  97. 41,
  98. 44,
  99. 47,
  100. 51,
  101. 55,
  102. 58,
  103. 62,
  104. 66,
  105. 71,
  106. 78,
  107. 85,
  108. 96,
  109. 111,
  110. 135,
  111. 194,
  112. 240,
  113. 255
  114. },
  115. // ch 3 - range25cm16PRFnb
  116. {
  117. 1,
  118. 2,
  119. 3,
  120. 4,
  121. 5,
  122. 7,
  123. 8,
  124. 9,
  125. 10,
  126. 12,
  127. 14,
  128. 16,
  129. 18,
  130. 20,
  131. 22,
  132. 24,
  133. 26,
  134. 28,
  135. 31,
  136. 33,
  137. 36,
  138. 39,
  139. 42,
  140. 45,
  141. 49,
  142. 52,
  143. 55,
  144. 59,
  145. 63,
  146. 69,
  147. 76,
  148. 85,
  149. 98,
  150. 120,
  151. 173,
  152. 213,
  153. 255
  154. },
  155. // ch 5 - range25cm16PRFnb
  156. {
  157. 1,
  158. 1,
  159. 2,
  160. 3,
  161. 4,
  162. 5,
  163. 6,
  164. 6,
  165. 7,
  166. 8,
  167. 9,
  168. 11,
  169. 12,
  170. 14,
  171. 15,
  172. 16,
  173. 18,
  174. 20,
  175. 21,
  176. 23,
  177. 25,
  178. 27,
  179. 29,
  180. 31,
  181. 34,
  182. 36,
  183. 38,
  184. 41,
  185. 44,
  186. 48,
  187. 53,
  188. 59,
  189. 68,
  190. 83,
  191. 120,
  192. 148,
  193. 255
  194. }
  195. }; // end range25cm16PRFnb
  196. //---------------------------------------------------------------------------------------------------------------------------
  197. // range25cm16PRFwb: Range Bias Correction table for wide band channels at 16 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
  198. //---------------------------------------------------------------------------------------------------------------------------
  199. const uint8_t range25cm16PRFwb[2][NUM_16M_OFFSETWB] =
  200. {
  201. // ch 4 - range25cm16PRFwb
  202. {
  203. 7,
  204. 7,
  205. 8,
  206. 9,
  207. 9,
  208. 10,
  209. 11,
  210. 11,
  211. 12,
  212. 13,
  213. 14,
  214. 15,
  215. 16,
  216. 17,
  217. 18,
  218. 19,
  219. 20,
  220. 21,
  221. 22,
  222. 23,
  223. 24,
  224. 26,
  225. 27,
  226. 28,
  227. 30,
  228. 31,
  229. 32,
  230. 34,
  231. 36,
  232. 38,
  233. 40,
  234. 42,
  235. 44,
  236. 46,
  237. 48,
  238. 50,
  239. 52,
  240. 55,
  241. 57,
  242. 59,
  243. 61,
  244. 63,
  245. 66,
  246. 68,
  247. 71,
  248. 74,
  249. 78,
  250. 81,
  251. 85,
  252. 89,
  253. 94,
  254. 99,
  255. 104,
  256. 110,
  257. 116,
  258. 123,
  259. 130,
  260. 139,
  261. 150,
  262. 164,
  263. 182,
  264. 207,
  265. 238,
  266. 255,
  267. 255,
  268. 255,
  269. 255,
  270. 255
  271. },
  272. // ch 7 - range25cm16PRFwb
  273. {
  274. 4,
  275. 5,
  276. 5,
  277. 5,
  278. 6,
  279. 6,
  280. 7,
  281. 7,
  282. 7,
  283. 8,
  284. 9,
  285. 9,
  286. 10,
  287. 10,
  288. 11,
  289. 11,
  290. 12,
  291. 13,
  292. 13,
  293. 14,
  294. 15,
  295. 16,
  296. 17,
  297. 17,
  298. 18,
  299. 19,
  300. 20,
  301. 21,
  302. 22,
  303. 23,
  304. 25,
  305. 26,
  306. 27,
  307. 29,
  308. 30,
  309. 31,
  310. 32,
  311. 34,
  312. 35,
  313. 36,
  314. 38,
  315. 39,
  316. 40,
  317. 42,
  318. 44,
  319. 46,
  320. 48,
  321. 50,
  322. 52,
  323. 55,
  324. 58,
  325. 61,
  326. 64,
  327. 68,
  328. 72,
  329. 75,
  330. 80,
  331. 85,
  332. 92,
  333. 101,
  334. 112,
  335. 127,
  336. 147,
  337. 168,
  338. 182,
  339. 194,
  340. 205,
  341. 255
  342. }
  343. }; // end range25cm16PRFwb
  344. //---------------------------------------------------------------------------------------------------------------------------
  345. // range25cm64PRFnb: Range Bias Correction table for narrow band channels at 64 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
  346. //---------------------------------------------------------------------------------------------------------------------------
  347. const uint8_t range25cm64PRFnb[4][NUM_64M_OFFSET] =
  348. {
  349. // ch 1 - range25cm64PRFnb
  350. {
  351. 1,
  352. 2,
  353. 2,
  354. 3,
  355. 4,
  356. 5,
  357. 7,
  358. 10,
  359. 13,
  360. 16,
  361. 19,
  362. 22,
  363. 24,
  364. 27,
  365. 30,
  366. 32,
  367. 35,
  368. 38,
  369. 43,
  370. 48,
  371. 56,
  372. 78,
  373. 101,
  374. 120,
  375. 157,
  376. 255
  377. },
  378. // ch 2 - range25cm64PRFnb
  379. {
  380. 1,
  381. 2,
  382. 2,
  383. 3,
  384. 4,
  385. 4,
  386. 6,
  387. 9,
  388. 12,
  389. 14,
  390. 17,
  391. 19,
  392. 21,
  393. 24,
  394. 26,
  395. 28,
  396. 31,
  397. 33,
  398. 37,
  399. 42,
  400. 49,
  401. 68,
  402. 89,
  403. 105,
  404. 138,
  405. 255
  406. },
  407. // ch 3 - range25cm64PRFnb
  408. {
  409. 1,
  410. 1,
  411. 2,
  412. 3,
  413. 3,
  414. 4,
  415. 5,
  416. 8,
  417. 10,
  418. 13,
  419. 15,
  420. 17,
  421. 19,
  422. 21,
  423. 23,
  424. 25,
  425. 27,
  426. 30,
  427. 33,
  428. 37,
  429. 44,
  430. 60,
  431. 79,
  432. 93,
  433. 122,
  434. 255
  435. },
  436. // ch 5 - range25cm64PRFnb
  437. {
  438. 1,
  439. 1,
  440. 1,
  441. 2,
  442. 2,
  443. 3,
  444. 4,
  445. 6,
  446. 7,
  447. 9,
  448. 10,
  449. 12,
  450. 13,
  451. 15,
  452. 16,
  453. 17,
  454. 19,
  455. 21,
  456. 23,
  457. 26,
  458. 30,
  459. 42,
  460. 55,
  461. 65,
  462. 85,
  463. 255
  464. }
  465. }; // end range25cm64PRFnb
  466. //---------------------------------------------------------------------------------------------------------------------------
  467. // range25cm64PRFwb: Range Bias Correction table for wide band channels at 64 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
  468. //---------------------------------------------------------------------------------------------------------------------------
  469. const uint8_t range25cm64PRFwb[2][NUM_64M_OFFSETWB] =
  470. {
  471. // ch 4 - range25cm64PRFwb
  472. {
  473. 7,
  474. 8,
  475. 8,
  476. 9,
  477. 9,
  478. 10,
  479. 11,
  480. 12,
  481. 13,
  482. 13,
  483. 14,
  484. 15,
  485. 16,
  486. 16,
  487. 17,
  488. 18,
  489. 19,
  490. 19,
  491. 20,
  492. 21,
  493. 22,
  494. 24,
  495. 25,
  496. 27,
  497. 28,
  498. 29,
  499. 30,
  500. 32,
  501. 33,
  502. 34,
  503. 35,
  504. 37,
  505. 39,
  506. 41,
  507. 43,
  508. 45,
  509. 48,
  510. 50,
  511. 53,
  512. 56,
  513. 60,
  514. 64,
  515. 68,
  516. 74,
  517. 81,
  518. 89,
  519. 98,
  520. 109,
  521. 122,
  522. 136,
  523. 146,
  524. 154,
  525. 162,
  526. 178,
  527. 220,
  528. 249,
  529. 255,
  530. 255,
  531. 255
  532. },
  533. // ch 7 - range25cm64PRFwb
  534. {
  535. 4,
  536. 5,
  537. 5,
  538. 5,
  539. 6,
  540. 6,
  541. 7,
  542. 7,
  543. 8,
  544. 8,
  545. 9,
  546. 9,
  547. 10,
  548. 10,
  549. 10,
  550. 11,
  551. 11,
  552. 12,
  553. 13,
  554. 13,
  555. 14,
  556. 15,
  557. 16,
  558. 16,
  559. 17,
  560. 18,
  561. 19,
  562. 19,
  563. 20,
  564. 21,
  565. 22,
  566. 23,
  567. 24,
  568. 25,
  569. 26,
  570. 28,
  571. 29,
  572. 31,
  573. 33,
  574. 35,
  575. 37,
  576. 39,
  577. 42,
  578. 46,
  579. 50,
  580. 54,
  581. 60,
  582. 67,
  583. 75,
  584. 83,
  585. 90,
  586. 95,
  587. 100,
  588. 110,
  589. 135,
  590. 153,
  591. 172,
  592. 192,
  593. 255
  594. }
  595. }; // end range25cm64PRFwb
  596. /*! ------------------------------------------------------------------------------------------------------------------
  597. * Function: dwt_getrangebias()
  598. *
  599. * Description: This function is used to return the range bias correction need for TWR with DW1000 units.
  600. *
  601. * input parameters:
  602. * @param chan - specifies the operating channel (e.g. 1, 2, 3, 4, 5, 6 or 7)
  603. * @param range - the calculated distance before correction
  604. * @param prf - this is the PRF e.g. DWT_PRF_16M or DWT_PRF_64M
  605. *
  606. * output parameters
  607. *
  608. * returns correction needed in meters
  609. */
  610. double dwt_getrangebias(uint8_t chan, float range, uint8_t prf)
  611. {
  612. //first get the lookup index that corresponds to given range for a particular channel at 16M PRF
  613. int i = 0 ;
  614. int chanIdx ;
  615. int cmoffseti ; // integer number of CM offset
  616. double mOffset ; // final offset result in metres
  617. // NB: note we may get some small negitive values e.g. up to -50 cm.
  618. int rangeint25cm = (int) (range * 4.00) ; // convert range to integer number of 25cm values.
  619. if (rangeint25cm > 255) rangeint25cm = 255 ; // make sure it matches largest value in table (all tables end in 255 !!!!)
  620. if (prf == DWT_PRF_16M)
  621. {
  622. switch(chan)
  623. {
  624. case 4:
  625. case 7:
  626. {
  627. chanIdx = chan_idxwb[chan];
  628. while (rangeint25cm > range25cm16PRFwb[chanIdx][i]) i++ ; // find index in table corresponding to range
  629. cmoffseti = i + CM_OFFSET_16M_WB ; // nearest centimeter correction
  630. }
  631. break;
  632. default:
  633. {
  634. chanIdx = chan_idxnb[chan];
  635. while (rangeint25cm > range25cm16PRFnb[chanIdx][i]) i++ ; // find index in table corresponding to range
  636. cmoffseti = i + CM_OFFSET_16M_NB ; // nearest centimeter correction
  637. }
  638. }//end of switch
  639. }
  640. else // 64M PRF
  641. {
  642. switch(chan)
  643. {
  644. case 4:
  645. case 7:
  646. {
  647. chanIdx = chan_idxwb[chan];
  648. while (rangeint25cm > range25cm64PRFwb[chanIdx][i]) i++ ; // find index in table corresponding to range
  649. cmoffseti = i + CM_OFFSET_64M_WB ; // nearest centimeter correction
  650. }
  651. break;
  652. default:
  653. {
  654. chanIdx = chan_idxnb[chan];
  655. while (rangeint25cm > range25cm64PRFnb[chanIdx][i]) i++ ; // find index in table corresponding to range
  656. cmoffseti = i + CM_OFFSET_64M_NB ; // nearest centimeter correction
  657. }
  658. }//end of switch
  659. } // end else
  660. mOffset = (float) cmoffseti ; // offset result in centimmetres
  661. mOffset *= 0.01 ; // convert to metres
  662. return (mOffset) ;
  663. }