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

Parents
  • Hello,

    The distance function looks to be correct, so I think 'rev_cnt ' must be wrong.

  • Hi Vidar,if 'rev_cnt' must be wrong, which variable should I use for calculating distance based on tyre size and tyre revolution  ?

    Complete function I see from main.c

    static uint32_t calculate_speed(int32_t rev_cnt, int32_t evt_time)
    {
        static uint32_t computed_speed   = 0;
         //distance = (rev_cnt * (WHEEL_CIRCUMFERENCE/1000)); //divide by 1000 for per metre
    			
        if (rev_cnt != m_speed_calc_data.prev_rev_cnt)
        {
            m_speed_calc_data.acc_rev_cnt  += rev_cnt - m_speed_calc_data.prev_rev_cnt;
            m_speed_calc_data.acc_evt_time += evt_time - m_speed_calc_data.prev_evt_time;
    
            /* Process rollover */
            if (m_speed_calc_data.prev_rev_cnt > rev_cnt)
            {
                m_speed_calc_data.acc_rev_cnt += UINT16_MAX + 1;
            }
            if (m_speed_calc_data.prev_evt_time > evt_time)
            {
                m_speed_calc_data.acc_evt_time += UINT16_MAX + 1;
            }
    
            m_speed_calc_data.prev_rev_cnt  = rev_cnt;
            m_speed_calc_data.prev_evt_time = evt_time;
    
            computed_speed = SPEED_COEFFICIENT *
                             (m_speed_calc_data.acc_rev_cnt  - m_speed_calc_data.prev_acc_rev_cnt) /
                             (m_speed_calc_data.acc_evt_time - m_speed_calc_data.prev_acc_evt_time);
    
            m_speed_calc_data.prev_acc_rev_cnt  = m_speed_calc_data.acc_rev_cnt;
            m_speed_calc_data.prev_acc_evt_time = m_speed_calc_data.acc_evt_time;
        }
    
        return (uint32_t)computed_speed;
    }

    Thanks

  • Hi,

    I meant to say that the 'rev_cnt' input value had to be wrong as you didn't get the expected result. I'd suggest you try to test with fixed inputs to verify the function. E.g., check if you get the distance to be ~2000 m if you pass rev_cnt=1000 to calculate_speed()

  • I used this equation : 

     distance = ((rev_cnt * (WHEEL_CIRCUMFERENCE/1000)))/135; //divide by 1000 for per metre
                                                                    //135 is the coefficient to m distance

    and it looks like more accurate comparing wth my Garmin Edge,

    app: Computed distance value: 685 m

    in Garmin Edge is 627 m

    How do you reckon ? thanks

  • 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

Reply
  • 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

Children
Related