Floats???
lboucher
Posts: 139
Hi All
I am building a backpack GPS system.
To keep cost/weight down i will not be using a tablet PC.
I will probably use this data logger.
http://www.acumeninstruments.com/Products/SDR2-CF/index.shtml
The other side of things is that i want to split the serial coming out of the GPS.
1 will go to the logger, the other i need to monitor to ensure certain variables stay within the right range.
I was thinking i would use an SX, read in the serial, look at the numbers then light up various LED's based upon the results.
The question is.
The data i need to look at is a 4 Byte Float 32.
I need to know when the value is greater than 0.02.
(If it matters, the value will never be less than 0)
Can i do this with the SX???
Thanks
Lucas
I am building a backpack GPS system.
To keep cost/weight down i will not be using a tablet PC.
I will probably use this data logger.
http://www.acumeninstruments.com/Products/SDR2-CF/index.shtml
The other side of things is that i want to split the serial coming out of the GPS.
1 will go to the logger, the other i need to monitor to ensure certain variables stay within the right range.
I was thinking i would use an SX, read in the serial, look at the numbers then light up various LED's based upon the results.
The question is.
The data i need to look at is a 4 Byte Float 32.
I need to know when the value is greater than 0.02.
(If it matters, the value will never be less than 0)
Can i do this with the SX???
Thanks
Lucas
Comments
Your GPS is putting out floating point data?
If you really need a floating point comparison, you'll first need to find out what floating point format the data is stored in. If it's IEEE-754, then you're ahead of the game. Check out this page:
www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
In particular, look down the page under the heading Comparing using integers. This describes a features of IEEE-754 floats which says that if you're just doing a comparison, you can treat the data as 32 bit integers and then simply compare tham. For this you'll need to find out the value of .02 as an IEEE-754 format float, and then do a 32 bit integer compare of it to your incoming data.
Thanks,
PeterM
Yes my GPS unit is putting out floats. (Trying to control a 10,000 dollar GPS unit with 50 bucks worth of parts.)
Would this be easier with a propeller or stamp?
Lucas
Guess thats a stupid question.
I just need to compare byte by byte.
Post Edited (lboucher) : 5/10/2009 2:41:11 PM GMT
No, it's not a stupid question. You're on the right track in that you do the work a byte at a time. However, since you're trying to compare to a value, you need to do a 32 bit signed compare. This means that basically you're doing a 32 bit subtraction and seeing if the result is 0 (they're the same) or one is bigger than the other. So, if you're subtracting your new value from the constant .02, if the result is negative than you're new value is greater than .02, and vice versa if the result is positive.
In order to do a multibyte subtraction, you need to have the carry flag factor into your results. Go to this site...
www.SxList.com
..and look for the math routines on the site. They don't seem to have a 32 bit subtraction, but a 16 bit subtraction can be extended by simply doing two more bytes worth of work.
Thanks,
PeterM
Thanks for the site and the info.
I actually don't think i need to worry about the negative.
I am monitoring the standard deviation of the GPS solution, and that will never go negative.
I think as long as i know the 4 int representation of the number i want to compare with I can simply have 4 if statements and make it work.
Thanks.
See attached.
Works fine as long as there are no negative numbers.
So now the question is, how many nested if functions can an SX handle.
Guess i could always find a way around this issue using GOTO's.
· Here is a program that will convert a IEEE754 32-bit float to a WORD value of trunc(abs(float * 65536))
· With this program the value 0.02 will be converted to 1310.
· You can then compare this WORD variable to see if the float value is greater than 1310.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
Post Edited (Bean (Hitt Consulting)) : 5/11/2009 5:09:20 PM GMT
Thanks alot