Go Down

### Topic: Float and asin, computation problems (Read 1 time)previous topic - next topic

#### pchelper4

##### Jul 12, 2012, 11:44 pm
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-2047float Angle = asin((AxisData -1024.0)/1638.0);   //Uses mfg equation to convert to degreeslcd.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

#1
##### Jul 13, 2012, 12:05 am
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

#2
##### Jul 13, 2012, 12:52 am
asin(x) returns radians, not degrees - trig functions work in radians in all the math libraries I've ever seen.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### pchelper4

#3
##### Jul 13, 2012, 03:33 pm
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!