| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698 |
- /*! ----------------------------------------------------------------------------
- * @file deca_range_tables.c
- * @brief DW1000 range correction tables
- *
- * @attention
- *
- * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
- *
- * All rights reserved.
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "deca_device_api.h"
- #include "deca_param_types.h"
- #define NUM_16M_OFFSET (37)
- #define NUM_16M_OFFSETWB (68)
- #define NUM_64M_OFFSET (26)
- #define NUM_64M_OFFSETWB (59)
- 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
- 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
- //---------------------------------------------------------------------------------------------------------------------------
- // Range Bias Correction TABLES of range values in integer units of 25 CM, for 8-bit unsigned storage, MUST END IN 255 !!!!!!
- //---------------------------------------------------------------------------------------------------------------------------
- // offsets to nearest centimeter for index 0, all rest are +1 cm per value
- #define CM_OFFSET_16M_NB (-23) // for normal band channels at 16 MHz PRF
- #define CM_OFFSET_16M_WB (-28) // for wider band channels at 16 MHz PRF
- #define CM_OFFSET_64M_NB (-17) // for normal band channels at 64 MHz PRF
- #define CM_OFFSET_64M_WB (-30) // for wider band channels at 64 MHz PRF
- //---------------------------------------------------------------------------------------------------------------------------
- // range25cm16PRFnb: Range Bias Correction table for narrow band channels at 16 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
- //---------------------------------------------------------------------------------------------------------------------------
- const uint8_t range25cm16PRFnb[4][NUM_16M_OFFSET] =
- {
- // ch 1 - range25cm16PRFnb
- {
- 1,
- 3,
- 4,
- 5,
- 7,
- 9,
- 11,
- 12,
- 13,
- 15,
- 18,
- 20,
- 23,
- 25,
- 28,
- 30,
- 33,
- 36,
- 40,
- 43,
- 47,
- 50,
- 54,
- 58,
- 63,
- 66,
- 71,
- 76,
- 82,
- 89,
- 98,
- 109,
- 127,
- 155,
- 222,
- 255,
- 255
- },
- // ch 2 - range25cm16PRFnb
- {
- 1,
- 2,
- 4,
- 5,
- 6,
- 8,
- 9,
- 10,
- 12,
- 13,
- 15,
- 18,
- 20,
- 22,
- 24,
- 27,
- 29,
- 32,
- 35,
- 38,
- 41,
- 44,
- 47,
- 51,
- 55,
- 58,
- 62,
- 66,
- 71,
- 78,
- 85,
- 96,
- 111,
- 135,
- 194,
- 240,
- 255
- },
- // ch 3 - range25cm16PRFnb
- {
- 1,
- 2,
- 3,
- 4,
- 5,
- 7,
- 8,
- 9,
- 10,
- 12,
- 14,
- 16,
- 18,
- 20,
- 22,
- 24,
- 26,
- 28,
- 31,
- 33,
- 36,
- 39,
- 42,
- 45,
- 49,
- 52,
- 55,
- 59,
- 63,
- 69,
- 76,
- 85,
- 98,
- 120,
- 173,
- 213,
- 255
- },
- // ch 5 - range25cm16PRFnb
- {
- 1,
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 6,
- 7,
- 8,
- 9,
- 11,
- 12,
- 14,
- 15,
- 16,
- 18,
- 20,
- 21,
- 23,
- 25,
- 27,
- 29,
- 31,
- 34,
- 36,
- 38,
- 41,
- 44,
- 48,
- 53,
- 59,
- 68,
- 83,
- 120,
- 148,
- 255
- }
- }; // end range25cm16PRFnb
- //---------------------------------------------------------------------------------------------------------------------------
- // range25cm16PRFwb: Range Bias Correction table for wide band channels at 16 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
- //---------------------------------------------------------------------------------------------------------------------------
- const uint8_t range25cm16PRFwb[2][NUM_16M_OFFSETWB] =
- {
- // ch 4 - range25cm16PRFwb
- {
- 7,
- 7,
- 8,
- 9,
- 9,
- 10,
- 11,
- 11,
- 12,
- 13,
- 14,
- 15,
- 16,
- 17,
- 18,
- 19,
- 20,
- 21,
- 22,
- 23,
- 24,
- 26,
- 27,
- 28,
- 30,
- 31,
- 32,
- 34,
- 36,
- 38,
- 40,
- 42,
- 44,
- 46,
- 48,
- 50,
- 52,
- 55,
- 57,
- 59,
- 61,
- 63,
- 66,
- 68,
- 71,
- 74,
- 78,
- 81,
- 85,
- 89,
- 94,
- 99,
- 104,
- 110,
- 116,
- 123,
- 130,
- 139,
- 150,
- 164,
- 182,
- 207,
- 238,
- 255,
- 255,
- 255,
- 255,
- 255
- },
- // ch 7 - range25cm16PRFwb
- {
- 4,
- 5,
- 5,
- 5,
- 6,
- 6,
- 7,
- 7,
- 7,
- 8,
- 9,
- 9,
- 10,
- 10,
- 11,
- 11,
- 12,
- 13,
- 13,
- 14,
- 15,
- 16,
- 17,
- 17,
- 18,
- 19,
- 20,
- 21,
- 22,
- 23,
- 25,
- 26,
- 27,
- 29,
- 30,
- 31,
- 32,
- 34,
- 35,
- 36,
- 38,
- 39,
- 40,
- 42,
- 44,
- 46,
- 48,
- 50,
- 52,
- 55,
- 58,
- 61,
- 64,
- 68,
- 72,
- 75,
- 80,
- 85,
- 92,
- 101,
- 112,
- 127,
- 147,
- 168,
- 182,
- 194,
- 205,
- 255
- }
- }; // end range25cm16PRFwb
- //---------------------------------------------------------------------------------------------------------------------------
- // range25cm64PRFnb: Range Bias Correction table for narrow band channels at 64 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
- //---------------------------------------------------------------------------------------------------------------------------
- const uint8_t range25cm64PRFnb[4][NUM_64M_OFFSET] =
- {
- // ch 1 - range25cm64PRFnb
- {
- 1,
- 2,
- 2,
- 3,
- 4,
- 5,
- 7,
- 10,
- 13,
- 16,
- 19,
- 22,
- 24,
- 27,
- 30,
- 32,
- 35,
- 38,
- 43,
- 48,
- 56,
- 78,
- 101,
- 120,
- 157,
- 255
- },
- // ch 2 - range25cm64PRFnb
- {
- 1,
- 2,
- 2,
- 3,
- 4,
- 4,
- 6,
- 9,
- 12,
- 14,
- 17,
- 19,
- 21,
- 24,
- 26,
- 28,
- 31,
- 33,
- 37,
- 42,
- 49,
- 68,
- 89,
- 105,
- 138,
- 255
- },
- // ch 3 - range25cm64PRFnb
- {
- 1,
- 1,
- 2,
- 3,
- 3,
- 4,
- 5,
- 8,
- 10,
- 13,
- 15,
- 17,
- 19,
- 21,
- 23,
- 25,
- 27,
- 30,
- 33,
- 37,
- 44,
- 60,
- 79,
- 93,
- 122,
- 255
- },
- // ch 5 - range25cm64PRFnb
- {
- 1,
- 1,
- 1,
- 2,
- 2,
- 3,
- 4,
- 6,
- 7,
- 9,
- 10,
- 12,
- 13,
- 15,
- 16,
- 17,
- 19,
- 21,
- 23,
- 26,
- 30,
- 42,
- 55,
- 65,
- 85,
- 255
- }
- }; // end range25cm64PRFnb
- //---------------------------------------------------------------------------------------------------------------------------
- // range25cm64PRFwb: Range Bias Correction table for wide band channels at 64 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
- //---------------------------------------------------------------------------------------------------------------------------
- const uint8_t range25cm64PRFwb[2][NUM_64M_OFFSETWB] =
- {
- // ch 4 - range25cm64PRFwb
- {
- 7,
- 8,
- 8,
- 9,
- 9,
- 10,
- 11,
- 12,
- 13,
- 13,
- 14,
- 15,
- 16,
- 16,
- 17,
- 18,
- 19,
- 19,
- 20,
- 21,
- 22,
- 24,
- 25,
- 27,
- 28,
- 29,
- 30,
- 32,
- 33,
- 34,
- 35,
- 37,
- 39,
- 41,
- 43,
- 45,
- 48,
- 50,
- 53,
- 56,
- 60,
- 64,
- 68,
- 74,
- 81,
- 89,
- 98,
- 109,
- 122,
- 136,
- 146,
- 154,
- 162,
- 178,
- 220,
- 249,
- 255,
- 255,
- 255
- },
- // ch 7 - range25cm64PRFwb
- {
- 4,
- 5,
- 5,
- 5,
- 6,
- 6,
- 7,
- 7,
- 8,
- 8,
- 9,
- 9,
- 10,
- 10,
- 10,
- 11,
- 11,
- 12,
- 13,
- 13,
- 14,
- 15,
- 16,
- 16,
- 17,
- 18,
- 19,
- 19,
- 20,
- 21,
- 22,
- 23,
- 24,
- 25,
- 26,
- 28,
- 29,
- 31,
- 33,
- 35,
- 37,
- 39,
- 42,
- 46,
- 50,
- 54,
- 60,
- 67,
- 75,
- 83,
- 90,
- 95,
- 100,
- 110,
- 135,
- 153,
- 172,
- 192,
- 255
- }
- }; // end range25cm64PRFwb
- /*! ------------------------------------------------------------------------------------------------------------------
- * Function: dwt_getrangebias()
- *
- * Description: This function is used to return the range bias correction need for TWR with DW1000 units.
- *
- * input parameters:
- * @param chan - specifies the operating channel (e.g. 1, 2, 3, 4, 5, 6 or 7)
- * @param range - the calculated distance before correction
- * @param prf - this is the PRF e.g. DWT_PRF_16M or DWT_PRF_64M
- *
- * output parameters
- *
- * returns correction needed in meters
- */
- double dwt_getrangebias(uint8_t chan, float range, uint8_t prf)
- {
- //first get the lookup index that corresponds to given range for a particular channel at 16M PRF
- int i = 0 ;
- int chanIdx ;
- int cmoffseti ; // integer number of CM offset
- double mOffset ; // final offset result in metres
- // NB: note we may get some small negitive values e.g. up to -50 cm.
- int rangeint25cm = (int) (range * 4.00) ; // convert range to integer number of 25cm values.
- if (rangeint25cm > 255) rangeint25cm = 255 ; // make sure it matches largest value in table (all tables end in 255 !!!!)
- if (prf == DWT_PRF_16M)
- {
- switch(chan)
- {
- case 4:
- case 7:
- {
- chanIdx = chan_idxwb[chan];
- while (rangeint25cm > range25cm16PRFwb[chanIdx][i]) i++ ; // find index in table corresponding to range
- cmoffseti = i + CM_OFFSET_16M_WB ; // nearest centimeter correction
- }
- break;
- default:
- {
- chanIdx = chan_idxnb[chan];
- while (rangeint25cm > range25cm16PRFnb[chanIdx][i]) i++ ; // find index in table corresponding to range
- cmoffseti = i + CM_OFFSET_16M_NB ; // nearest centimeter correction
- }
- }//end of switch
- }
- else // 64M PRF
- {
- switch(chan)
- {
- case 4:
- case 7:
- {
- chanIdx = chan_idxwb[chan];
- while (rangeint25cm > range25cm64PRFwb[chanIdx][i]) i++ ; // find index in table corresponding to range
- cmoffseti = i + CM_OFFSET_64M_WB ; // nearest centimeter correction
- }
- break;
- default:
- {
- chanIdx = chan_idxnb[chan];
- while (rangeint25cm > range25cm64PRFnb[chanIdx][i]) i++ ; // find index in table corresponding to range
- cmoffseti = i + CM_OFFSET_64M_NB ; // nearest centimeter correction
- }
- }//end of switch
- } // end else
- mOffset = (float) cmoffseti ; // offset result in centimmetres
- mOffset *= 0.01 ; // convert to metres
- return (mOffset) ;
- }
|