-
Notifications
You must be signed in to change notification settings - Fork 1.8k
The IMU
class constructs objects that represent a single IMU module attached to the physical board. An IMU is an Inertial Measurement Unit. IMUs come in all shapes and DOFs (Degrees of Freedom). They are often made up of several components like Accelerometers, Gyros, Temperature Sensors, and Magnetometers.
Johnny-Five currently supports one kind of IMU:
This list will continue to be updated as more devices are confirmed.
- General Options
Property Name | Type | Value(s) | Description | Default | Required |
---|---|---|---|---|---|
controller | string | "MPU6050" | The Name of the controller to use | "MPU6050" | no |
freq | Number | ms | The delay in reporting data from this device | 100 | no |
- MPU-6050 Options(
controller: "MPU6050"
)
Property Name | Type | Value(s) | Description | Default | Required |
---|---|---|---|---|---|
address | Number | 8-bit value | The address of the component (can be switched via ADO pin) | 0x68 | no |
// Create an MPU-6050 IMU object:
//
// - attach SDA and SCL to the I2C pins on your board (A4 and A5 for the Uno)
// - specify the MPU6050 controller
var accelerometer = new five.IMU({
controller: "MPU6050",
address: 0x68, // optional
freq: 100 // optional
});
Some of these properties may or may not exist depending on whether the IMU supports it.
{
accelerometer: An instance of `Accelerometer` class. READONLY
gyro: An instance of `Gyro` class. READONLY
temperature: An instance of `Temperature` class. READONLY
}
var five = require("johnny-five"),
board = new five.Board();
board.on("ready", function() {
var accelerometer = new five.IMU({
controller: "MPU6050"
});
accelerometer.on("data", function(err, data) {
console.log("Accelerometer: %d, %d, %d", this.accelerometer.x, this.accelerometer.z, this.accelerometer.z);
console.log("Gyro: %d, %d, %d", this.gyro.x, this.gyro.z, this.gyro.z);
console.log("Temperature: %d", this.temperature.celsius);
});
});
The IMU does not have an explicit API. Refer to the individual components for their APIs
-
data The "data" event is fired as frequently as the user defined
freq
will allow in milliseconds. -
change The IMU does not emit "change" events directly. You can watch the aggregate components for "change" events.