read

Read acceleration, angular velocity, magnetic field, time, and overrun data

Description

example

[sensorReadings,overrun] = read(imu) returns the sensor readings in timetable format. The timetable contains acceleration, angular velocity, magnetic field, and time data along with the overrun data. The number of samples depends on the SamplesPerRead value specified while creating the sensor object. These output arguments are returned only when the output format is set to timetable.

Note

This function is available only with the Sensor Fusion and Tracking Toolbox™.

Note

For 6 DOF sensors all readings are not available. For example, in MPU-6050, magnetic field is not available.

example

[accelReadings, gyroReadings, magReadings, timeStamps, overrun] = read(imu) returns matrices of acceleration, gyroscope, magnetic field, time stamps, and overrun. The number of samples depends on the SamplesPerRead value specified while creating the sensor object. These output arguments are returned only when the output format is set to matrix.

Examples

Read Data from Sensor

Create an Arduino object and include the I2C library.

a = arduino('COM4', 'Uno', 'Libraries', 'I2C');

Create a sensor object with properties available only with the Sensor Fusion and Tracking Toolbox.

imu = mpu9250(a,'SampleRate',50,'SamplesPerRead',5,'ReadMode','Latest');

Read five samples of sensor data in datetime format.

[sensorReadings,overrun] = read(imu)

sensorReadings =

 5×3 timetable

              Time                        Acceleration                         AngularVelocity                       MagneticField        
    ________________________    ________________________________    ______________________________________    ____________________________

    14-Dec-2018 15:01:34.832    -0.28261     0.30836      10.395    0.018968     -0.0050405     -0.0026529    8.4938     10.582    -17.051
    14-Dec-2018 15:01:34.852    -0.28261     0.30836      10.395    0.018968     -0.0050405     -0.0026529    8.4938     10.582    -15.687
    14-Dec-2018 15:01:34.872     -0.2874     0.31375      10.432    0.021356       0.001857     0.00026529    8.4938     9.8766    -17.051
    14-Dec-2018 15:01:34.892    -0.29339     0.30896      10.327    0.020427     -0.0013265    -0.00013265    8.4938     10.582    -17.733
    14-Dec-2018 15:01:34.912    -0.29339     0.30896      10.327    0.020427     -0.0013265    -0.00013265    7.0781     9.1711    -17.733



overrun =

     0

Input Arguments

collapse all

The IMU sensor object with the default or specified properties.

Output Arguments

collapse all

Acceleration, angular velocity, and magnetic field data read from the sensor when the output format is set to timetable. The timetable returned has the following fields:

  • Time — Time stamps in datetime or duration format

  • Acceleration — N-by-3 array in units of m/s2

  • AngularVelocity — N-by-3 array in units of rad/s

  • MagneticField — N-by-3 array in units of µT (microtesla)

Data Types: timetable

The discarded number of data samples between the previous read and the current read is the overrun. The overrun is zero when ReadMode is set to oldest.

Data Types: single | double

Acceleration read from the sensor on x, y and z axis. This value is specified as a real, finite N-by-3 matrix in m/s2. N is the number of samples in the current frame.

Data Types: double

Angular velocity read from the sensor on x, y and z axis. This value is specified as a real, finite N-by-3 matrix in rad/s. N is the number of samples in the current frame.

Data Types: double

Magnetic field read from the sensor on x, y and z axis. This value is specified as a real, finite N-by-3 matrix in µT (microtesla) . N is the number of samples in the current frame.

Data Types: double

Time displayed when the sensor data is read.

  • datetime — Displays the date and time at which the data is read.

  • duration — Displays the time elapsed in seconds after the first call of the read function or the last execution of the release function.

Introduced in R2019a