Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

You are here: Forum Home → ANT+ Forums → ANT+ Bike Power → Thread

   

SRM Power decoding

Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

The decoding of "Crank Torque Frequency - 0x20" messages seems to be off.
I used the code inside "antplus_bike_power_v1.3.0"
I have user reporting wrong power reading with their SRM units, telling me it's almost the double of the correct value.

Is there a value that needs to be set (depending on the unit) in the decoding or is it generic?
Thanks in advance!


stCalculatedStdCTFData.ulCTFAverageCadence = (ULONG)(((ulCTFEventCountDiff<<6)*1875)/ulCTFTimeStampDiff);
stCalculatedStdCTFData.ulCTFTorqueFrequency = (ULONG)((((ulCTFTorqueTickStampDiff<<4)*125)/ulCTFTimeStampDiff) - usCTFOffset);
stCalculatedStdCTFData.ulCTFAverageTorque = (ULONG)((10*stCalculatedStdCTFData.ulCTFTorqueFrequency)/pstPage32Data.usCTFSlope);
stCalculatedStdCTFData.ulCTFAveragePower = (ULONG)(((stCalculatedStdCTFData.ulCTFAverageTorque*stCalculatedStdCTFData.ulCTFAverageCadence*BPS_PI_CONSTANT)/15)>>9);
ucCTFEventCountPrev pstPage32Data.ucCTFEventCount;
usCTFTimeStampPrev pstPage32Data.usCTFTimeStamp;
usCTFTorqueTickStampPrev pstPage32Data.usCTFTorqueTickStamp
     

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com

Avatar
RankRankRankRank

Total Posts: 235

Joined 2012-08-31

PM

Hi blaisminator,

Yes, you'll need to make sure you have the correct current slope and offset values. Take a look at the section in the device profile describing calibration for a CTF sensor.

The profile also describes all the calculations needed.

Thanks,

Kat      
Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

Thanks for your reply Kat

I have read page 39-42 of the profile "D00001086_-_ANT+_Device_Profile_-_Bicycle_Power_-_Rev4.1.pdf"
I don't see where the offset is mentioned. I take the slope in consideration though. The offset is not being send in every message like the slope?

Here is my full code,
also inspired largely by Golden Cheetah code:
Thanks a lot for your help on this, it's the only sensor type I'm having problem with.


case ANT_CRANKSRM_POWER:  //0x20 - crank torque (SRM)
    
{

        
/// --- Decode ------------------
        
currentMessage_page0x20.eventCount stMessage.aucData[2];
        
currentMessage_page0x20.slope stMessage.aucData[4] + (stMessage.aucData[3]<<8); // bigendian
        
currentMessage_page0x20.period stMessage.aucData[6] + (stMessage.aucData[5]<<8); // bigendian
        
currentMessage_page0x20.torque stMessage.aucData[8] + (stMessage.aucData[7]<<8); // bigendian

        
if (!firstMessage0x20{
            
/// ----------calculate with last message ---------------
            
uint16_t period currentMessage_page0x20.period lastMessage_page0x20.period;
            
uint16_t torque currentMessage_page0x20.torque lastMessage_page0x20.torque;
            
float time = (float)period / (float)2000.00;

            if (
time && currentMessage_page0x20.slope && period{

                nullCount_page0x20 
0;
                
float torque_freq torque time 420/*srm_offset*/;
                
float nm_torque 10.0 torque_freq currentMessage_page0x20.slope;
                
float cadence 2000.0 60 * (currentMessage_page0x20.eventCount lastMessage_page0x20.eventCount) / period;
                
float power 3.14159 nm_torque cadence 30;
             
}
         }
     
...
    

     

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com

Avatar
RankRankRankRank

Total Posts: 296

Joined 0

PM

To my best knowledge the offset is only sent in response to a calibration request message (see chap. 6.4 of the profile). So the display unit has to cache the received offset value for later use.
OMB      
Avatar
RankRankRankRank

Total Posts: 235

Joined 2012-08-31

PM

Thanks OMB! That's correct.      
Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

Ohh thanks I think I get it now.

The offset is received from time to time from this type of sensor. So I think i'd have to replace the "420" with the actual offset received from the calibration response.
I'll reread the pdf bible to make sure,
Thanks a lot for your kind help,
Max

float torque_freq torque time 420/*srm_offset*/;
//replace with
 
float torque_freq torque time srm_offset 
     

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com

Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

I was able to decode the calibration response of the CTF sensor.

My question is : The CTF sensor responds with 40 messages (for 10 seconds) with an offset value.
Can we take any of theses value as the offset or do we need to average it?

Also opened another thread of the data type used on the offset storage:
http://www.thisisant.com/forum/viewthread/4590/
Would be nice that the code used cross-platform variable (e.g: uint16_t instead of USHORT)

Thanks,
Max      

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com

Avatar
RankRankRankRank

Total Posts: 235

Joined 2012-08-31

PM

Handling this stream of values is described in the device profile, but isn't completely clear, so I'm copying/pasting the answer below that I recently gave to someone else. It should have all the info you need. Also, you are welcome to modify the code as you see fit in your application. I'll bear your comment in mind when creating any new reference designs. Thanks!
_________________

When you receive a zero offset from the CTF sensor you get a stream of values, which may all be slightly different. When you get 5 in a row that have a standard deviation (among themselves) of 4 Hz or less, then compare the average of these 5 samples with the currently saved value.

If the difference between the average value and the currently saved value is less than 200Hz, then accept the average as the new value.

Note that if there is a risk that the bike may be resting on the crank then the value should be ignored – this is generally done by assuming that spontaneous calibration results (typically transmitted when coasting) are only accepted when the speed is at least 5km/h. If the user requested the calibration then you can assume the bike is upright.
     
Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

I read that part but got lost a bit with the "Hz", my value is a standard INT, so I need to check if 5 following received offset values are in the same range (+- 4) If so, compare the average of theses 5 values with the previous saved value and and see if the difference if less than 200 before accepting it as the new value.

One thing I can see causing problem, for the first time setting the offset in the software, the saved value can be 200 and more with this average.

As of right now i'm just setting the offset with the last received value, i'll need to change that
I was thinking of doing an average on the offset values received instead of just using 5 values.
I much prefer the other sensor that are more simple!

Thanks for your explanation hopefully I can fix this SRM problem,

     

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com

Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

SRM problem fixed, the code in the ANT+ profile had some error decoding the offset.

Here is the code in question :

//code causing wrong offset decoding
//NB BIG ENDIAN
pstPage1Data.stBPSCalibrationData.stBPSPage1_CID16_CTFID1_Data.usCID16_CTFID1_OffsetData |= (USHORT)(stMessage.aucData[ucDataOffset+6]<<8);
pstPage1Data.stBPSCalibrationData.stBPSPage1_CID16_CTFID1_Data.usCID16_CTFID1_OffsetData = (USHORT)stMessage.aucData[ucDataOffset+7];
USHORT usCTFOffset pstPage1Data.stBPSCalibrationData.stBPSPage1_CID16_CTFID1_Data.usCID16_CTFID1_OffsetData;
        
//good code        
uint16_t zeroOffset stMessage.aucData[8] + (stMessage.aucData[7]<<8); 


You may want to review
"antplus_bike_power_v1.3.0\antplus_bps_rx\display\bps\bps_rx.c" line 886-887
Thanks
     

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com

Avatar
RankRankRankRank

Total Posts: 745

Joined 2012-09-14

PM

Thanks for the input!