Supporting Browser-based Javascript and Node.js
Stella.bilodeau
Fresh meat
Posts: 2 Joined: Thu Oct 25, 2018 9:10 am
Post
by Stella.bilodeau » Thu Oct 25, 2018 9:13 am
Hi
,
I would like to know how to access the bearing data of the compass in javascript.
I found the acceleration, the three axis of the compass and the magnetic field, but not the bearing of the compass
.
mparadis
Site Admin
Posts: 679 Joined: Fri Oct 28, 2011 12:17 pm
Post
by mparadis » Thu Oct 25, 2018 9:18 am
You'll have to calculate bearing manually. See
this page in our documentation for more information.
Stella.bilodeau
Fresh meat
Posts: 2 Joined: Thu Oct 25, 2018 9:10 am
Post
by Stella.bilodeau » Thu Oct 25, 2018 9:23 am
mparadis wrote: You'll have to calculate bearing manually. See
this page in our documentation for more information.
Would you have an example in javascript?
mparadis
Site Admin
Posts: 679 Joined: Fri Oct 28, 2011 12:17 pm
Post
by mparadis » Thu Oct 25, 2018 9:31 am
This is the only example we have, but it's mostly math so if you understand what's being calculated it should be easy to convert to JavaScript.
clinton_le_castor
Fresh meat
Posts: 1 Joined: Fri Aug 19, 2022 8:51 am
Post
by clinton_le_castor » Fri Aug 19, 2022 8:52 am
Have you found out how to calculate the Compass Data Pitch Roll Bearing?
I only need this in Python...
mparadis
Site Admin
Posts: 679 Joined: Fri Oct 28, 2011 12:17 pm
Post
by mparadis » Fri Aug 19, 2022 9:11 am
That post was from 4 years ago, so things have changed quite a bit.
Our phidget22 library now calculates these for you- look up the "eulerAngles" property (in the Spatial channel class) in the
API documentation for details:
Code: Select all
from Phidget22.Phidget import *
from Phidget22.Devices.Spatial import *
ch = Spatial()
ch.openWaitForAttachment(1000)
eulerAngles = ch.getEulerAngles()
print("EulerAngles: " + str(eulerAngles))
ch.close()