L latcc Banned Dec 21, 2011 #1 I have been messing with the internal compass function of the SensorExtended library. It returns directions in radians. What code do I use to display this magnetic direction in degrees? The demo program gives these values in radians: N = 0 W = -90 S = 180 or -180 E = 90 I have tried this code: degrees = radians * (180 / PI) actual code is: NumberFormat(ORi(0),0,2) * (180 / PI) where ORi is the direction-radians returned by the sensor library. But this doesn't return values in 360 degrees.
I have been messing with the internal compass function of the SensorExtended library. It returns directions in radians. What code do I use to display this magnetic direction in degrees? The demo program gives these values in radians: N = 0 W = -90 S = 180 or -180 E = 90 I have tried this code: degrees = radians * (180 / PI) actual code is: NumberFormat(ORi(0),0,2) * (180 / PI) where ORi is the direction-radians returned by the sensor library. But this doesn't return values in 360 degrees.
klaus Expert Licensed User Longtime User Dec 21, 2011 #2 Try this code: Code: Copy NumberFormat(ORi(0)* 180 / cPI, 1, 2) Did you declare PI? The PI constant in B4A is cPI. Best regards. Upvote 0
Try this code: Code: Copy NumberFormat(ORi(0)* 180 / cPI, 1, 2) Did you declare PI? The PI constant in B4A is cPI. Best regards.
L latcc Banned Dec 21, 2011 #3 klaus said: Try this code: Code: Copy NumberFormat(ORi(0)* 180 / cPI, 1, 2) Did you declare PI? The PI constant in B4A is cPI. Best regards. Click to expand... That doesn't work either, Klaus. It shows correct compass headings from north (0) through east (090) to south (180) but then it turns negative and works backward through west to zero (north). It should show increasing values through west all the way up to 360 (0) at north again. So the west 180 half circle is a minus version of the east half circle. I attach the program and would appreciate any help. Attachments Sensor Extender.zip Sensor Extender.zip 275.3 KB · Views: 588 Upvote 0
klaus said: Try this code: Code: Copy NumberFormat(ORi(0)* 180 / cPI, 1, 2) Did you declare PI? The PI constant in B4A is cPI. Best regards. Click to expand... That doesn't work either, Klaus. It shows correct compass headings from north (0) through east (090) to south (180) but then it turns negative and works backward through west to zero (north). It should show increasing values through west all the way up to 360 (0) at north again. So the west 180 half circle is a minus version of the east half circle. I attach the program and would appreciate any help.
klaus Expert Licensed User Longtime User Dec 21, 2011 #4 This works: Code: Copy Dim ORi(3) As Float ORi = se.GetOrientation(R) Dim ORi0 As Float ORi0 = ORi(0)* 180 / cPI If ORi0 < 0 Then ORi0 = 360 + ORi0 End If lb1.text = NumberFormat(ORi0, 1, 2) Best regards. Upvote 0
This works: Code: Copy Dim ORi(3) As Float ORi = se.GetOrientation(R) Dim ORi0 As Float ORi0 = ORi(0)* 180 / cPI If ORi0 < 0 Then ORi0 = 360 + ORi0 End If lb1.text = NumberFormat(ORi0, 1, 2) Best regards.
L latcc Banned Dec 21, 2011 #5 Thanks for the brain-work, Klaus! Much appreciated.:sign0098: Upvote 0