Decawave / uwb-apps

Apache License 2.0
33 stars 31 forks source link

LOS, VRSSI and more insights statistics on NRNG_TAG/NRNG_NODE example #14

Closed EpsilonZ closed 3 years ago

EpsilonZ commented 3 years ago

Hi!

I've been testing with the NRNG_TAG / NRNG_NODE examples and everything is working really good but I would need to add statistics to debug and mitigate in case a Hard-NLOS is found. I've tried to modify the code in many ways together with amend paramers but can not find the way to get them correctly.

I've tried to amend this parameters:

NRNG_VERBOSE: 2
TWR_DS_EXT_NRNG_ENABLED: 1
RNG_VERBOSE: 2
RNG_STATS: 2
NRNG_STATS: 2
UWBCFG_DEF_RX_DIAG_EN: '"1"'

But seems like none of them work. I've also debugged and found out that all statistic values are always set to 0 so it seems like these amend parameters do not work properly.

EpsilonZ commented 3 years ago

That's what I ended up doing.

In nrng_encode.c I changed the json filling part to this: (you need to add these parameters in the json struct too)

uint16_t j=0;
for (uint16_t i=0; i < 16; i++){
    if (valid_mask & 1UL << i){
        uint16_t idx = BitIndex(nrng->slot_mask, 1UL << i, SLOT_POSITION);
        nrng_frame_t * frame = nrng->frames[(base + idx)%nrng->nframes];
        struct _twr_data_t * twr_data = (struct _twr_data_t * ) frame->payload;
        if (frame->code == UWB_DATA_CODE_SS_TWR_NRNG_FINAL && frame->seq_num == seq_num){
            json.rng[j] = (dpl_float64_t) uwb_rng_tof_to_meters(nrng_twr_to_tof_frames(nrng->dev_inst, frame, frame));
            json.ouid[j] = frame->dst_address;
            json.rssi[j] = twr_data->rssi; 
            json.fppl[j] = twr_data->fppl;
            json.los[j] = uwb_estimate_los(nrng->dev_inst,json.rssi[j],json.fppl[j]);
            j++;
        }
    }
}

Originally, the twr_ss does not add the RSSI and FPPL data into the twr_data thus you need to modify the twr_nrng_ss.c too:

Within the case UWB_DATA_CODE_SS_TWR_NRNG_T1:

            frame->fppl = uwb_get_fppl(nrng->dev_inst);
            frame->rssi = uwb_get_rssi(nrng->dev_inst);

And you'll have the signal data of each twr available!