Go Down

Topic: help for motorbike gear indicator (Read 2300 times)previous topic - next topic

monsterfactory

Jan 20, 2011, 04:25 pmLast Edit: Jan 20, 2011, 04:26 pm by monsterfactory Reason: 1
hello I'm making a gear indicator for my motorbike.
the ratio is engine pulses / wheel sensor pulses.
so I have 2 arrays, minratio[gear] and maxratio[gear],they hold the min and max values of the ratio for the gears. for example for the 1st gear minratio[1] = 10, maxratio[1] = 13 ,2nd gear minratio[2] = 13, maxratio [2] = 15 and so on.
I thought to do something like: if (ratio < maxratio[1] && ratio > minratio[1] ){gear =1;}.... but it seems (it's) a sloppy way of coding...any hints are really welcome!thanks in advance!

#1
Jan 20, 2011, 05:39 pm
For any given gear, there should only be one actual ratio.  Why do you have a min and max ratio for each gear?

monsterfactory

#2
Jan 20, 2011, 07:23 pm
yes it's true, but due to the gears play, i get different values of ratio every update. I read how many wheel pulses i get, when the engine reaches 100 pulses, and then do the ratio math. the number of wheel pulses are slightly different for the same gear, but they are in a restricted range.

#3
Jan 20, 2011, 07:28 pm
So, store the "expected/ideal" gear ratio in your array.

Take your actual reading, calculate it's adsolute deviation from each of your ideal gear ratios, and select the one with the smallest deviation as the gear you are in.  So long as there is no overlap, the smallest deviation will always be the gear you are in.

monsterfactory

#4
Jan 21, 2011, 08:02 am
ok thanks I'll try this way!

Go Up

Please enter a valid email to subscribe