Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

You are here: Forum Home → ANT+ Forums → ANT+ Fitness Equipment → Thread

   

Fitness Equipment Bike Trainer Speed

Rank

Total Posts: 8

Joined 2019-10-22

PM

Hello i am working on getting a bike trainer ant+ information into a unity game. The issue i seem to have is i am only receiving the data at a very slow rate.. I get data from the trainer at 1 second intervals and the bike speed will change at every 5 seconds.

Is this correct with ant or am i doing something wrong in my implementation      
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

What are you using as a receiver?

When you say you get data at 1 second intervals, do you mean any data or specifically speed? You should be receiving a page approximately every 0.25 seconds. Note that some may be lost due to poor RF conditions. If you are receiving fewer that 4 pages per second, I recommend moving your receiver closer to the trainer.

Section 8.3 of the profile document deals with suggested transmission patterns, and 10.1.1 the minimum transmission rate. You can see from table 10-1 that some devices may only be transmitting speed at approximately 1 second intervals.

If the speed is only updated once every 5 seconds it is likely dictated by the manufacturers implementation.

I recommend using SimulANT+ to confirm the transmission pattern and update rate used by your trainer. You can also use SimulANT+ to simulate a trainer to test your implementation.

Ian

     

Signature

Ian Haigh

Rank

Total Posts: 8

Joined 2019-10-22

PM

I am receiving a page every .25 seconds but it looks like its page 26 not the page that has speed.

Darius      
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

Ah yes that makes sense as a possible transmission pattern. Note that from page 26 you can get speed if you have the user configure wheel size (see section 8.10.2). See section 8.6.8.5 for details on the speed calculation. Note that this speed may vary slightly from the value in page 16.

Ian      

Signature

Ian Haigh

Rank

Total Posts: 8

Joined 2019-10-22

PM

So i took your advice from the sections above. My code looks like the following the issue i have is my calculated speed values(see below).

Code
if(data[0] == 26)
{
currentUpdatedEventCount = data[1];
currentWheelPeriod = data[4];

calculatedSpeed = (3600 / 1000) * ((2.075f * (currentUpdatedEventCount - lastUpdatedEventCount)) / ((currentWheelPeriod - lastWheelPeriod) / 2048));

lastWheelPeriod = currentWheelPeriod;
lastUpdatedEventCount = currentUpdatedEventCount;

Debug.Log("Calculated Speed :: " + calculatedSpeed);

}

My calculated speed will showed

149.9859
910.6286
-52.24918
1158.982



     
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

You are missing a byte for wheel period.

The fact that you got a negative value leads me to believe you are not handling the rollover of event count properly.

Additionally, (3600 / 1000) is likely evaluating to 3 assuming you are using unsigned integer types. Similar integer division issue may apply to division by 2048.

Ian      

Signature

Ian Haigh

Rank

Total Posts: 8

Joined 2019-10-22

PM

isnt
currentWheelPeriod = data[4];
the byte for the wheel period?

It also looks like my event count is only changing on a wheel spin. If it is not spinning the event count stays the same
     
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

Wheel period is 2 bytes in size.

Ian      

Signature

Ian Haigh

Rank

Total Posts: 8

Joined 2019-10-22

PM

combine data[3] and data[4] ?

It also looks like my event count is only changing on a wheel spin. If it is not spinning the event count stays the same      
Rank

Total Posts: 8

Joined 2019-10-22

PM

what format is the 2 bytes for the wheel period? is it an int float double... Trying to figure out what BitConverter I should use

wheelPeriodArray[0] = data[4];
wheelPeriodArray[1] = data[3];

currentWheelPeriod = System.BitConverter.ToInt16(wheelPeriodArray, 0);      
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

See 8.6.8.3.1 for notes on the case where the wheel isn't rotating. You should be switching to 0 speed based on data page 16 while event count is unchanging.

16 bit unsigned integer for wheel period. data[3] is the lsb and data[4] is the msb.

Ian      

Signature

Ian Haigh

Rank

Total Posts: 8

Joined 2019-10-22

PM

ok
so i changed my code to now read below. Something still seems way off. is there an email address i could send you a video so you can see what my log is reading.

currentUpdatedEventCount = data[1];

wheelPeriodArray[0] = data[4];
wheelPeriodArray[1] = data[3];

currentWheelPeriod = System.BitConverter.ToUInt16(wheelPeriodArray, 0);

Debug.Log(currentWheelPeriod);

calculatedSpeed = (3600.0f / 1000.0f) * ((2.075f * (currentUpdatedEventCount - lastUpdatedEventCount)) / ((currentWheelPeriod - lastWheelPeriod) / 2048.0f));

calSpeedText.text = calculatedSpeed.ToString();

lastWheelPeriod = currentWheelPeriod;
lastUpdatedEventCount = currentUpdatedEventCount;


     
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

based on https://docs.microsoft.com/en-us/dotnet/api/system.bitconverter.touint16?view=netframework-4.8 you need to swap wheelPeriodArray[0] and [1]. [0] should be data[3]

Ian      

Signature

Ian Haigh

Rank

Total Posts: 8

Joined 2019-10-22

PM

oh gotcha,

That works great. The last issue i have if it drops somewhere below something like 6 the slow reading speed from the slow pages will read 6 but the new calculated speed will just show up as NaN