Pages: [1]   Go Down
Author Topic: Float and asin, computation problems  (Read 512 times)
0 Members and 1 Guest are viewing this topic.
Minnesota, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Just a guy...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to use a sensor to measure angles of incline on a stationary, flat plane. When I try to convert the raw data to an angle, it doesn't work right. Angle results can range from +/- 30 degrees which is sent from the sensor as a value ranging from 0-2047. I have been given this equation:

angle = arcsin((SensorDataOutput - 1024))/1638

at the bottom of page 12 from my sensor's mfg data sheet:

http://www.muratamems.fi/sites/default/files/documents/sca100t_inclinometer_datasheet_8261800a.pdf

My problem code looks like this:
Code:
float AxisData;   //Stores output value from sensor ranging from 0-2047
float Angle = asin((AxisData -1024.0)/1638.0);   //Uses mfg equation to convert to degrees
lcd.print(anglex,4);   //Prints conversion to lcd

So for example, the sensor sends a value of 837 to arduino. The equation converts this to -0.1144 degrees. The correct result would be -6.5554 degrees. On the arduino reference on floats, it suggests, to the best of my understanding, that a float can't exceed approximately 3.4. Is this a problem? Any ideas?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 505
Posts: 31332
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
On the arduino reference on floats, it suggests, to the best of my understanding, that a float can't exceed approximately 3.4.
No,
It says
Quote
Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38.
That is 3.4 times ten to the power 38 to -3.4 times ten to the power 38,
So the biggest number is
340000000000000000000000000000000000000
Approximately.
Logged

0
Offline Offline
Shannon Member
****
Karma: 159
Posts: 10409
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

asin(x) returns radians, not degrees - trig functions work in radians in all the math libraries I've ever seen.
Logged

[ I won't respond to messages, use the forum please ]

Minnesota, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Just a guy...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Problem solved!1 radian = 57.2957795 degrees.

When I times that by the number outputted, -0.1144, it yields a result of -6.5546 degrees which is very close to what it should be. Thanks!
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


float Angle = degrees( asin((AxisData -1024.0)/1638.0) );   //Uses mfg equation to convert to degrees
Logged

Pages: [1]   Go Up
Jump to: