Go Down

Topic: Float and asin, computation problems (Read 726 times) previous topic - next topic

pchelper4

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: [Select]
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?

Grumpy_Mike

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.

MarkT

asin(x) returns radians, not degrees - trig functions work in radians in all the math libraries I've ever seen.
[ I won't respond to messages, use the forum please ]

pchelper4

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!

Coding Badly


[font=Courier New]float Angle = degrees( asin((AxisData -1024.0)/1638.0) );   //Uses mfg equation to convert to degrees
[/font]

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy