Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Orientation Sensor not working

Hi,
Has anyone tried using the Orientation Sensor?
I haven't been able to get the sensor to work.

Would love some sample code if possible.

Thanks heaps in advance,

Echo

Best Answer
7 REPLIES 7
The accelerometer?
Best Answer
0 Votes

Thanks Allan for your reply.

 

I've got the Accelerometer working.  I'm talking about the OrientationSensor API.
I'm trying this as there also seem to be problems with the Gyroscope as well.

 

Best Answer
0 Votes
Ooo...I didn't realise there was such a thing!
Best Answer
0 Votes

Same happens to me:

const orientationSensor = new OrientationSensor();
setInterval(() => {
	console.log(orientationSensor.readings);
	if (orientationSensor.readings) {
		const { quaternion } = orientationSensor.readings;
		console.log(quaternion);
		if (quaternion) {
			console.log(quaternion.join());
		}
	}
}, 1000);

Prints forever:

[‎22‎:‎06‎:‎21]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎22]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎23]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎24]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎25]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎26]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎27]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎28]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎29]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎31]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎32]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎33]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎34]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎35]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎36]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎37]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎38]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎39]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎40]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎41]undefined
app/index.js:28,1
[‎22‎:‎06‎:‎43]undefined
Best Answer
0 Votes

Hi Sergius,
Sorry for taking so long to respond, busy days.
I'm working on the orientation sensor these days.  Once I have more information I'll share here.
Eddie

Best Answer
0 Votes

Hi,

 

any news?

 

Thank you.

 

Regards,

Mark

End!Now free time!
Best Answer
0 Votes

Have you tried the example in the sensor guide?  

 

It uses onreading plus it starts the sensor orientation.start() which it needs for operation otherwise you are just reading an empty record.  Also it sets the interval so you should not need to use setInterval().

 

 

import { OrientationSensor } from "orientation";

let orientation = new OrientationSensor({ frequency: 60 });

orientation.onreading = function() {
  console.log("Orientation Sensor Reading: " +
              "timestamp: " + orientation.timestamp,
              "quaternion[0]: " + orientation.quaternion[0],
              "quaternion[1]: " + orientation.quaternion[1],
              "quaternion[2]: " + orientation.quaternion[2],
              "quaternion[3]: " + orientation.quaternion[3]);
}

orientation.start();

 

Best Answer
0 Votes