Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Combined speed and cadence sensor issues

Rank

Total Posts: 5

Joined 2021-02-01

PM

I've just started to fiddle with ANT+ and I'm using the static library for Mac, ANT_LIB.

My goal is to broadcast data such as bike speed, cadence and power by using an ANT USB-stick.

By using the example code as a template, I successfully implemented a simulation that's broadcasting power data (according to the power profile documentation) which I can receive at my Garmin device.

Then I added another channel that are about to simulate and broadcast speed and cadence data, and now my issues begin.

I open up the channel, which my Garmin device finds and can connect to, and tries to broadcast data according to the speed and cadence documentation. But then it seems like my Garmin device can't receive/interpret the data I send while also dropping the connection every 5th second (approximate).

I have used the following formulas to convert a simulated speed (20km/h) and cadence (20rpm):
Speed = (Circumference*(RevCount_N-RevCount_{N-1})*1024)/(MeasTime_N-MeasTime_{N-1})
Cadence = (60*(RevCount_N-RevCount_{N-1})*1024)/(MeasTime_N-MeasTime_{N-1})
Where I have set the Circumference to be 2100mm.

This ends up in the following transmitted data (10 first packets):

Tx[00],[0c],[01],[00],[83],[01],[01],[00]
Tx
[00],[18],[02],[00],[06],[03],[02],[00]
Tx
[00],[24],[03],[00],[89],[04],[03],[00]
Tx
[00],[30],[04],[00],[0c],[06],[04],[00]
Tx
[00],[3c],[05],[00],[8f],[07],[05],[00]
Tx
[00],[48],[06],[00],[12],[09],[06],[00]
Tx
[00],[54],[07],[00],[95],[0a],[07],[00]
Tx
[00],[60],[08],[00],[18],[0c],[08],[00]
Tx
[00],[6c],[09],[00],[9b],[0d],[09],[00]
Tx
[00],[78],[0a],[00],[1e],[0f],[0a],[00] 


Which, by calculating by hand, seems like they are following the documentation.
What could I be doing wrong?      
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

Your cadence event times do not seem sane. You have a rotation occurring every message by the counter, which is ~4 Hz or ~240 rpm, and your timestamps say there is 3 seconds between each message.      

Signature

Ian Haigh

RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

ie your timestamps are correct for 20 rpm, but don't agree with the revolution counter.      

Signature

Ian Haigh

Rank

Total Posts: 5

Joined 2021-02-01

PM

Thank you for your reply!

I will receive a number of a cadence/speed that's in rpm/km/h, and not revolution and time, which I want to transmit.

I made some (maybe naive) assumptions during my calculation.
My thought was just to reverse the formulas, for example cadence using the two first packets:
Cadence = (60*(RevCount_N-RevCount_{N-1})*1024)/(MeasTime_N-MeasTime_{N-1})
= (60*(2 - 1) * 1024)/(6144 - 3072)
= 20
As both revolution count and time event were unknown variables I put revolution count to increase with 1 as this will make RevCount_N-RevCount_{N-1} be equal to 1.

But then I guess this is wrong.
So how do I convert my fixed rpm or km/h to revolutions and time events to send appropriate packets?

     
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

You need to write software that converts rpm to correct timestamp and counter increments by waiting to update the page data until after the next event.

For example:
1) Receive initial RPM, or assume one, and convert to period.
2) Start timer
3) Check timer each ant tx event (when you encode next page)
4) When time - last rotation event time >= rotation period, update page encoding and last rotation event time

You will need to have the same logic for speed where you convert km/h to period using the wheel size.      

Signature

Ian Haigh

Rank

Total Posts: 5

Joined 2021-02-01

PM

Thank you again for your reply.

I believe that I'm writing the packets according to your instructions, which gives me the following when having a fixed cadence of 80rpm and a fixed speed of 20km/h with a wheel circumference of 2100mm:
Tx[00],[03],[01],[00],[83],[01],[01],[00]
Tx
[00],[03],[01],[00],[83],[01],[01],[00]
Tx
[00],[03],[01],[00],[06],[03],[02],[00]
Tx
[00],[03],[01],[00],[06],[03],[02],[00]
Tx
[00],[06],[02],[00],[06],[03],[02],[00]
Tx
[00],[06],[02],[00],[89],[04],[03],[00]
Tx
[00],[06],[02],[00],[89],[04],[03],[00]
Tx
[00],[06],[02],[00],[89],[04],[03],[00]
Tx
[00],[06],[02],[00],[0c],[06],[04],[00]
Tx
[00],[09],[03],[00],[0c],[06],[04],[00]
Tx
[00],[09],[03],[00],[0c],[06],[04],[00]
Tx
[00],[09],[03],[00],[0c],[06],[04],[00]
Tx
[00],[09],[03],[00],[8f],[07],[05],[00]
Tx
[00],[09],[03],[00],[8f],[07],[05],[00]
Tx
[00],[0c],[04],[00],[8f],[07],[05],[00]
Tx
[00],[0c],[04],[00],[8f],[07],[05],[00]
Tx
[00],[0c],[04],[00],[8f],[07],[05],[00] 

Are these packets correct according to your instructions?
It still doesn't show up any data on my Garmin device and the "sensor" is disconnected each 2-4 seconds, so I guess I'm still doing something wrong..


When I gave it a second look I noticed that it's not correct.
My transmission logic is wrapped around the EVENT_TX event id when processing a message.
I assumed that when transmitting a message after this event will ensure that the messages are transmitted with ~4Hz, is this the case?

Now when I've fiddled with the timer it seems like it occurs more often than each 250ms.      
Rank

Total Posts: 5

Joined 2021-02-01

PM

Ok, now I've changed the logic that transmits so that the rev count should be accurate (I hope) for both the speed and cadence, resulting in these packets for cadence 80rpm and speed 20km/h with wheel size 2100mm:

Tx[00],[03],[01],[00],[83],[01],[01],[00]
Tx
[00],[03],[01],[00],[83],[01],[01],[00]
Tx
[00],[03],[01],[00],[06],[03],[02],[00]
Tx
[00],[06],[02],[00],[06],[03],[02],[00]
Tx
[00],[06],[02],[00],[89],[04],[03],[00]
Tx
[00],[06],[02],[00],[89],[04],[03],[00]
Tx
[00],[09],[03],[00],[0c],[06],[04],[00]
Tx
[00],[09],[03],[00],[0c],[06],[04],[00]
Tx
[00],[09],[03],[00],[8f],[07],[05],[00]
Tx
[00],[0c],[04],[00],[8f],[07],[05],[00]
Tx
[00],[0c],[04],[00],[12],[09],[06],[00]
Tx
[00],[0c],[04],[00],[12],[09],[06],[00]
Tx
[00],[0f],[05],[00],[95],[0a],[07],[00]
Tx
[00],[0f],[05],[00],[95],[0a],[07],[00]
Tx
[00],[0f],[05],[00],[18],[0c],[08],[00] 


Does this seem more sane? Using the formulas for speed and cadence I at least get the actual values (20km/h and 80rpm).
I'm still having issues with seeing any data though, and I can't understand why..      
Rank

Total Posts: 5

Joined 2021-02-01

PM


...
Now when I've fiddled with the timer it seems like it occurs more often than each 250ms.
...


This led me to my error: I didn't set the channel period.
Now everything seems to work, for now.      
Rank

Total Posts: 6

Joined 2023-04-12

PM

JLovgren - 18 March 2021 07:49 AM

...
Now when I've fiddled with the timer it seems like it occurs more often than each 250ms.redactle
...


This led me to my error: I didn't set the channel period.
Now everything seems to work, for now.

Did it just suddenly work or did you solve it yourself?