Pages: [1]   Go Down
Author Topic: help for motorbike gear indicator  (Read 1680 times)
0 Members and 1 Guest are viewing this topic.
italy
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!  
« Last Edit: January 20, 2011, 10:26:37 am by monsterfactory » Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For any given gear, there should only be one actual ratio.  Why do you have a min and max ratio for each gear?
Logged


italy
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


italy
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok thanks I'll try this way!
Logged

Pages: [1]   Go Up
Jump to: