The Gyro widget, for now, doubles as the Core Motion widget. In addition to using it for obtaining raw rotational rate values you can also use it to get the current attitude of the phone in the form of pitch, roll and yaw readings. The attitude is obtained from a combination of Gyro and Accelerometer readings with some signal processing applied. Like the Accelerometer widget, the update rate can be changed for the Gyro. There can only be one Gyro widget per interface.
The raw gyro data is available as xRotationRate, yRotationRate and zRotationRate. The Core Motion data is available as pitch, roll and yaw. By default the Gyro widget will output all six of these values via OSC or MIDI when it is included in an interface.
Additional JSON Attributes
- updateRate : determines how often the Gyro / Core Motion data will be read. The value is expressed in Hz; this means a value of 50 (50 Hz = 50 cycles per second) will be read every 20 ms.
Scripting
Properties
- xRotationRate – the rate of rotation around the x-axis of the phone.
- yRotationRate – the rate of rotation around the y-axis of the phone.
- zRotationRate – the rate of rotation around the z-axis of the phone.
- pitch – the angle the phone is aligned to on the x-axis. The default min is -1.57, the default max is 1.57
- roll – the angle of the phone on the z-axis. The default min is -3.14, the default max is 3.14
- yaw – the angle of the phone y-axis. The default min is -3.14, the default max is 3.14
Methods
- setUpdateRate(rateInHz) – this method changes the rate of updates sent by the gyro / core motion
- setReferenceAttitude – The reference attitude is the default zero settings for pitch, roll and yaw. When you first start up an interface including the gyro widget, this reference attitude will be derived from the attitude of the device at that moment in time. If you’d like to reset the attitude call this method.
- onvaluechange – the only event handler for the gyro, this event is called after they gyro has been read but before its values have been outputted, allowing you to manipulate the values before they are sent to a destination
Simple JSON
{ "name": "gyro", "type": "Gyro", "min": 0, "max": 1, },
Extra JSON
{ "name": "gyro", "type": "Gryo", "updateRate":50, "min": 0, "max": 1, "onvaluechange": "pitchLabel.setValue(this.pitch)", },