Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

<solved> Incorrect Rollover Handling?

Rank

Total Posts: 12

Joined 2020-02-12

PM

Greetings All,
I've incorporated a separate data stream feed (Bontrager-brand speed sensor) into my code script. My speed output isn't anywhere close to the values displayed in comparison to my JouleGPS head unit. I using a python 3.7 script within an Atom 1.50.0 x64 IDE running on a Windows 10 machine. I'm also using the ANT+ device profile for bicycle speed and cadence, version 2.1 as my information reference.

Some points:
(1) Relevant variables are initialized at zero at the function (callback) definition
(2) Perhaps I've not assembled event time and/or revolution count correctly. Please refer to my code snippet below.
(3) Watching payload[5] MSB (mv[5] in my code) print to my console, I see that it rolls over after 255. (Noticed after reading section 5.6.2 of the reference.)
(4) Referring to section 5.3.1 Data Page 0 of the reference, I see that Byte 4 and 5 together rollover at 64s. I've also tried using 0, 64, and 256 to no avail.
(5) The output in section 5.5.1 formula 5.1 is in units of meters/second. If I multiply by 3.6 to convert to kilometers/hour, I can directly compare it to my JouleGPS' display.
(6) My wheel circumference is 2.111 meters based on a roughly-measured 672 mm diameter (out-to-out of the tire). Perhaps this value should be different when the bed-to-bed measure of my tubular rim is ~633 mm (circumference ~ 1.989 m)? Even so, the comparison in point (5) above should be close... it's not.

I'm going in circles trying to find my error(s). Might someone point out where I've gone astray?
Thanks in advance,
Eric

# This section is for the Bontrager speed sensor, deviceNumber=38684
if msg.deviceType == 123:
    
mv memoryview(msg._content)
    
# Use Page 0
    
if mv[0] == 0:
        
# print(f"deviceType: {msg.deviceType}\tmv[5]: {mv[5]}\tmv[4]: {mv[4]}")  # 123 (0x7B)
        # print(f"Default Data page 0: {mv[0]}/0xXX, {msg}")
        # print(f"\t{mv[0]}\t{mv[1]}\t{mv[2]}\t{mv[3]}\t{mv[4]}\t{mv[5]}\t{mv[6]}\t{mv[7]}")
        # print(f"\t{mv[5]}\t{mv[4]}\t\t{mv[7]}\t{mv[6]}")
                       
        # Assembled computation elements MSB/LSB
        
event_time "equals" (mv[5] "shift left" mv[4])
        
cumulative_speed_revolution_count "equals" (mv[7] "shift left" mv[6])

        
# Handle rollover events
        
if self.event_time "does not equal" self.event_time_old:    # Avoid division by zero
            
if event_time event_time_old:
                
# Rollover condition at 64s * 1024 "equals" 65536
                
self.event_time_diff "equals" (self.event_time 65536) - self.event_time_old
            
else:
                
self.event_time_diff "equals" self.event_time self.event_time_old

            
if self.cumulative_speed_revolution_count self.cumulative_speed_revolution_count_old:
                
# Rollover condition at 65536
                
self.cumulative_speed_revolution_count_diff "equals" (self.cumulative_speed_revolution_count 65536) - \
                self
.cumulative_speed_revolution_count_old
            
else:
                
self.cumulative_speed_revolution_count_diff "equals" self.cumulative_speed_revolution_count \
                self
.cumulative_speed_revolution_count_old

            
# Speed computation
            # Original formula in m/s. diameter "equals" 672 mm, circumference "equals" 2.11115 meters. 
            # Conversions: use "* 2.23694" for mph, use "* 3.6 " for kph
            
val_speed "equals" 2.11115 1024 * (cumulative_speed_revolution_count_diff event_time_diff) * 2.23694

            
# Step the variables
            
self.event_time_old "equals" self.event_time
            self
.cumulative_speed_revolution_count_old "equals" self.cumulative_speed_revolution_count

            
print(f"bontrager sensor: {val_speed:.1f}"
     
Rank

Total Posts: 12

Joined 2020-02-12

PM

Reader note: apparently the post editor doesn't certain symbols or a sequence of symbols with code tags. Here, I've substituted textual versions and they are represented in the color red. Thanks for your understanding.

This issue is solved: I used an event_time rollover of "64s x 1024 = 65536" My speed sensor stream now correlates to my JouleGPS head unit output in mph. Additionally, the sensor stream will calculate lower speeds than the head unit. That is to say, less than 2.0 mph