# MPU9250

Measure acceleration, angular rate, and magnetic field, and calculate fusion values such as Euler angles and quaternion along the axes of MPU-9250 sensor

**
Add-On Required: This feature requires the Simulink Coder Support
Package for Beaglebone Blue Hardware add-on.**

**Libraries:**

Simulink Coder Support Package for BeagleBone Blue Hardware /
Sensors

## Description

The MPU9250 block reads data from the MPU-9250 sensor that is connected to the hardware. The block has two operation modes: Random and DMP.

The block outputs acceleration, angular rate, and strength of the magnetic field along
the axes of the sensor in Random and DMP mode. In DMP mode, the block also outputs the
orientation of the sensor as an Euler angle and quaternions. The values emitted in the
Random mode are raw values, whereas the values emitted in the DMP mode are calibrated
values. The block outputs all the values except for quaternion as a 3-by-1 array of
`double`

data type. The quaternion is a 4-by-1 array of
`double`

data type.

This illustration shows the default orientation of the *x-*,
*y-*, and *z-* axes of the MPU-9250 sensor.

If you simulate a model that contains the MPU9250 block without connecting the hardware, the block outputs zeros. For more information, see Block Produces Zeros or Does Nothing in Simulation.

**Note**

Before generating code from the MPU9250 block in
`DMP`

mode, calibrate the sensor using the `calibrateGyro`

, `calibrateAccel`

, and `calibrateMag`

functions. These functions calibrate the three-axis
gyroscope, accelerometer, and magnetometer located inside the sensor.

## Ports

### Output

**Accel** — Acceleration including force of gravity along axes of sensor

vector

The **Accel** port outputs acceleration along the
*x-*, *y-*, and
*z-* axes of the sensor as a 3-by-1 vector. In DMP
mode, the elements of the vector represent calibrated values, whereas in
Random mode, the elements represent raw values. The acceleration is
measured in m/s^{2} and also includes
acceleration due to gravity.

#### Dependencies

The **Accel** port is available only when you
select the **Acceleration (m/s^2)** parameter.

**Data Types: **`double`

**Ang rate** — Angle of rotation per second along axes of sensor

vector

The **Ang rate** port outputs the angle of rotation
per second along the *x-*, *y-*, and
*z-* axes of the sensor as a 3-by-1 vector. In DMP
mode, the elements of the vector represent calibrated values, whereas in
Random mode, the elements represent raw values. The angular rate is
measured in dps.

#### Dependencies

The **Ang rate** port is available only when you
select the **Angular rate (dps)** parameter.

**Data Types: **`double`

**Mag field** — Strength of magnetic field along axes of sensor

vector

The **Mag field** port outputs the strength of the
magnetic field along the *x-*, *y-*,
and *z-* axes of the sensor as a 3-by-1 vector. In DMP
mode, the elements of the vector represent calibrated values, whereas in
Random mode, the elements represent raw values. The magnetic strength is
measured in μT.

#### Dependencies

The **Mag field** port is available only when you
select the **Magnetic field (μT)**
parameter.

**Data Types: **`double`

**Euler** — Sensor orientation given as Euler angles

vector

The **Euler** port outputs the orientation along the
axes of the sensor as a 3-by-1 vector. The elements of the vector
represent the orientation using three angular quantities – azimuth
(rotation around *z-* axis), roll (rotation around
*y-* axis), and pitch (rotation around
*x-* axis) of the sensor.

Angular Quantity | Description | Range in Degrees |
---|---|---|

Azimuth | Angle between y- axis of the
sensor and magnetic north | [0, 360] |

Roll | Angle between z- axis and
x- axis of the sensor | [−90, 90] |

Pitch | Angle between z- axis and
y- axis of the sensor | [−180, 180] |

#### Dependencies

The **Euler** port is available only when you set
the **Operation mode** to
`DMP`

and select the **Euler
angles (degrees)** parameter.

**Data Types: **`double`

**Quat** — Sensor orientation given as a quaternion

quaternion array

The **Quat** port outputs the orientation along the
*w-*, *x-*, *y-*,
and *z-* axes of the sensor as a 4-by-1 vector. The
orientation is measured in quaternion. For more information on
quaternions, see `quaternion`

(Robotics System Toolbox).

#### Dependencies

The **Quat** port is available only when you set
the **Operation mode** to
`DMP`

and select the
**Quaternion (quaternion)** parameter.

**Data Types: **`double`

## Parameters

**Operation mode** — Option to output calibrated or raw values

`DMP`

(default) | `Random`

`DMP`

— When you set**Operation mode**to`DMP`

, the sensor operates in 9 degrees of freedom (NDOF) mode. The block outputs calibrated values from the sensor.This table lists the block output, measurement unit, dimension, and the axes of the sensor along which each of these outputs are measured.

Output Unit Dimension Axes Acceleration Meter per second squared (m/s ^{2})3-by-1 *x*,*y*, and*z*Angular rate degrees per second (dps) 3-by-1 *x*,*y*, and*z*Magnetic field microtesla (μT) 3-by-1 *x*,*y*, and*z*Euler angles degrees per second (dps) 3-by-1 *x*,*y*, and*z*Quaternions Quaternion units 4-by-1 *w*,*x*,*y*, and*z***Note**Before generating code from the MPU9250 block in

`DMP`

mode, calibrate the sensor using the`calibrateGyro`

,`calibrateAccel`

, and`calibrateMag`

functions. These functions run an internal fusion algorithm to configure the range and bandwidth of the sensor with some values.`Random`

— When you set**Operation mode**to`Random`

, the sensor operates outputs raw values from the sensor.This table lists the block output, measurement unit, dimension, and the axes of the sensor along which each of these outputs are measured in

`Random`

mode.Output Unit Dimension Axes Acceleration Meter per second squared (m/s ^{2})3-by-1 *x*,*y*, and*z*Angular rate degrees per second (dps) 3-by-1 *x*,*y*, and*z*Magnetic field microtesla (μT) 3-by-1 *x*,*y*, and*z*

**Sample time** — Interval to read values from sensor

`0.1`

(default) | `-1`

| any nonnegative value

Specify how often the block read values from the sensor, in seconds. When
you specify this parameter as `-1`

, Simulink^{®} determines the best sample time for the block based on the
block context within the model.

### Select Outputs

**Acceleration (m/s^2)** — Acceleration including force of gravity along axes of sensor

`on`

(default) | `off`

When you select the **Acceleration (m/s^2)**
parameter, the **Accel** port becomes available. For
more information on the **Accel** port, see Accel.

**Angular rate (dps)** — Angle of rotation per second along axes of sensor

`on`

(default) | `off`

When you select the **Angular rate (dps)** parameter,
the **Ang rate** port becomes available. For more
information on the **Ang rate** port, see Ang rate.

**Magnetic field (μT)** — Strength of magnetic field along axes of sensor

`on`

(default) | `off`

When you select the **Magnetic field (μT)**
parameter, the **Mag field** port becomes available.
For more information on the **Mag field** port, see
Mag field.

**Data Types: **`double`

**Euler angles (degrees)** — Orientation along axes of sensor

`off`

(default) | `on`

When you select the **Euler angles (degrees)**
parameter, the **Euler** port becomes available. For
more information on the **Euler** port, see Euler.

#### Dependencies

The **Euler angles (degrees)** parameter is
available only when you set the **Operation mode**
to `DMP`

.

**Quaternion (quaternion)** — Orientation along axes of sensor

`off`

(default) | `on`

When you select the **Quaternion (quaternion)**
parameter, the **Quat** port becomes available. For
more information on the **Quat** port, see Quat.

#### Dependencies

The **Quaternion (quaternion)** parameter is
available only when you set the **Operation mode**
to `DMP`

**Data Types: **`double`

### Advanced Sensor Settings

**Accelerometer range** — Range of acceleration deviation measured by accelerometer

`4G`

(default) | `2G`

| `8G`

| `16G`

Select a deviation in the acceleration that the accelerometer can measure. The smaller the accelerometer range is, the more sensitive the readings from the accelerometer are. A small range provides more detailed data, resulting in a more precise reading from the accelerometer.

#### Dependencies

The **Accelerometer range** parameter is
available only when you set the **Operation mode**
to `Random`

.

**Accelerometer bandwidth** — Frequency response of accelerometer

`1`

(default) | `0`

| `2`

| `3`

| `4`

| `5`

| `6`

| `7`

Specify the highest frequency at which the accelerometer samples the
signal without aliasing by the specified **DMP
ODR**.

#### Dependencies

The **Accelerometer bandwidth** parameter is
available only when you set the **Operation mode**
to `Random`

.

**Gyroscope range** — Maximum angular velocity measured by gyroscope

`250 dps`

(default) | `500 dps`

| `1000 dps`

| `2000 dps`

Specify the maximum angular velocity that the gyroscope can measure per second.

#### Dependencies

The **Gyroscope range** parameter is available
only when you set the **Operation mode** to
`Random`

.

**Gyroscope bandwidth** — Frequency response of gyroscope

`1`

(default) | `0`

| `2`

| `3`

| `4`

| `5`

| `6`

| `7`

Specify the highest frequency at which the gyroscope samples the
signal without aliasing by the specified **DMP
ODR**.

#### Dependencies

The **Gyroscope bandwidth** parameter is
available only when you set the **Operation mode**
to `Random`

.

**DMP ODR** — Rate at which data is sampled

`200`

(default) | `100`

| `50`

| `40`

| `20`

| `10`

| `8`

| `5`

| `4`

Specify how many times the sensor measures the values per second.

#### Dependencies

The **DMP ODR** parameter is available only when
you set the **Operation mode** to
`DMP`

**Data Types: **`double`

## Version History

**Introduced in R2019a**

## Comando de MATLAB

Ha hecho clic en un enlace que corresponde a este comando de MATLAB:

Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)