This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Calculating distance ?

Dear Member,

I want to calculate distance I have traveled,

I saw variables as

#define WHEEL_CIRCUMFERENCE         2070                                                            /**< Bike wheel circumference [mm] */

static uint32_t calculate_speed(int32_t rev_cnt, int32_t evt_time)

distance = rev_cnt * (WHEEL_CIRCUMFERENCE/1000); //divide by 1000 for per metre

but the output doesn't make sense


nfo> app: Computed distance value: 52052 m
                         

any clues ? Do I need to add any coefficient ? which coefficient ?

is this variable BSC_PROFILE_speed_rev_count equal to wheel rotation speed ?

thanks

  •  Is  m_speed_calc_data.acc_rev_cnt  += rev_cnt - m_speed_calc_data.prev_rev_cnt; equal to this ?

  • From my observation :

    nfo> app: Computed distance raw: 93984 m                                                      <===

    nfo> app: Computed distance raw: 94048                                                          <===

    nfo> app: Computed distance value: 64 m                                                     <=== this is right

    nfo> app: Computed distance raw: 94048                                                              <===

    nfo> app: Computed distance raw: 94100                                                              <===

    nfo> app: Computed distance value: 52 m                                                                 <=== this is right 94100 - 94048 but total distance suppose to be 64m + 52m .....

    code :
    distance = (m_speed_calc_data.acc_rev_cnt  - m_speed_calc_data.prev_acc_rev_cnt)*(WHEEL_CIRCUMFERENCE/1000);

    total_distance = distance[0]+distance[n] ?

    Any clues ? thanks

  • I'm afraid this is something you have to debug yourself. total_distance = distance[0]+distance[n]  is supposed to be 64m + 52m, right? In that case, I'd suggest you start by checking what happens to distance[0]. Maybe it's always getting overwritten by the current distance..

Related