-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Gyro
BrianGenisio edited this page Dec 24, 2014
·
31 revisions
The Gyro
class constructs objects that represent a single Gyro sensor attached to the physical board.
We currently support two kinds of Gyros:
- Analog (Like the Tinkerkit 2-Axis Gyro)
- MPU-6050 I2C IMU
This list will continue to be updated as more Gyro devices are confirmed.
- General Options
Property Name | Type | Value(s) | Description | Default | Required |
---|---|---|---|---|---|
controller | string | "ANALOG" | "MPU6050" | The Name of the controller to use | "ANALOG" | no |
- Analog Options(
controller: "ANALOG"
)
Property Name | Type | Value(s) | Description | Default | Required |
---|---|---|---|---|---|
pins | Array of Strings | ["A*"] | The String analog pins that X, Y, and Z (optional) are attached to | none | yes |
sensitivity | Number | Varies by device. For Tinkerkit, use `Gyro.TK_4X` or `Gyro.TK_1X` | This value can be identified in the device's datasheet. | none | yes |
resolution | Number | Varies by device | This value can be identified in the device's datasheet | 4.88 | no |
- MPU-6050 Options(
controller: "MPU6050"
)
Property Name | Type | Value(s) | Description | Default | Required |
---|---|---|---|---|---|
sensitivity | Number | LSB/DegreesPerSecond | The sensitivity of the device. The MPU-6050 is currently configured at +/- 250 degrees per second | 131 | no |
// Create an analog Gyro object:
//
// - attach X and Y to "A0" and "A1" respectively
// - Use the LPR5150AL 4X sensitivity rating
//
var gyro = new five.Gyro({
pins: ["A0", "A1"],
sensitivity: 0.67,
resolution: 4.88
});
// Create an MPU-6050 Gyro object:
//
// - attach SDA and SCL to the I2C pins on your board (A4 and A5 for the Uno)
// - specify the MPU6050 controller
var gyro = new five.Gyro({
controller: "MPU6050",
sensitivity: 131
});
{
id: A user definable id value. Defaults to a generated uid
pins: The pins defined for X, Y, and Z.
isCalibrated: The calibration state of the device. READONLY
pitch: An object containing values for the pitch rate and angle. READONLY
roll: An object containing values for the roll rate and angle. READONLY
yaw: An object containing values for the yaw rate and angle. READONLY
rate: And object containing the rate values of X, Y, and Z. READONLY
x: Value of x axis. READONLY
y: Value of y axis. READONLY
z: Value of z axis. READONLY
}
var five = require("johnny-five"),
board = new five.Board();
board.on("ready", function() {
var gyro = new five.Gyro({
pins: ["I0", "I1"],
sensitivity: 0.67 // LPR5150AL 4X
});
gyro.on("change", function(err, data) {
console.log("X raw: %d rate: %d", this.x, this.rate.x);
console.log("Y raw: %d rate: %d", this.y, this.rate.y);
});
});
- recalibrate() Tell the device to recalibrate
-
change The "change" event is emitted whenever the value of the gyro changes more then the threshold value allows.
-
data The "data" event is fired as frequently as the user defined
freq
will allow in milliseconds. ("data" replaced the "read" event)