14. API - Inertial Measurement Unit (IMU)¶
The Inertial Measurement Unit (IMU) on the Sense HAT has myriad uses in all
sorts of projects from High Altitude Balloon (HAB) flights, robotics,
detecting magnetic fields, or making novel user interfaces. It is represented
in pisense by the
SenseIMU class, and provides readings as
The settings parameter can be used to point to alternate settings files but it is strongly recommended you leave this at the default as this can affect the calibration of the IMU.
If the emulate parameter is
True, the instance will connect to the IMU in the desktop Sense HAT emulator instead of the “real” Sense HAT IMU.
close()method to close the inertial measurement unit interface and free up any background resources. The method is idempotent (you can call it multiple times without error) and after it is called, any operations on the inertial measurement unit may return an error (but are not guaranteed to do so).
Return the current state of the inertial measurement unit as an
This method will wait until the next set of readings are available, and then return them. Hence it is suitable for use in a loop without additional waits, although it may be simpler to simply treat the instance as an iterator in that case.
Returns the name of the IMU chip. On the Sense HAT this should always be “LSM9DS1”.
The sensors that are used in determining the orientation are specified in the
The orientation of the board is only calculated when the sensors are read. The drift of certain sensors (the gyroscope in particular) mean that reading the orientation more frequently can result in greater accuracy.
Specifies the rotation about the Z axis applied to IMU readings as a multiple of 90 degrees. When rotation is 0 (the default), positive X is toward the joystick, and positive Y is away from the GPIO pins:
When rotation is 90, positive X is toward the GPIO pins, and positive Y is toward the joystick:
The other two rotations are trivial to derive from this.
This property is updated by the unifying
IMUState(compass, gyro, accel, orient)¶
namedtuple()representing a single reading from the Inertial Measurement Unit (IMU). The fields are as follows:
Represents the calibration settings for the Sense HAT.
The settings_file refers to the INI-style file containing all calibration settings for the Sense HAT. For no particularly good reason, the underlying library requires that this filename ends with ‘.ini’.
If the specified file does not exist, it will be created with default calibration settings. Hence you should ensure that the location specified either exists or is writeable by the current user. Furthermore, if the file successfully loads the underlying library will attempt to overwrite it with “cleaned” values. If you wish to keep modifications to the file (comments, etc.) ensure that the file is effectively read-only for the executing user.
Yes, this is a ridiculous requirement and while I would dearly love to re-write this chunk of the underlying library, it’s not something I have time for currently!
Returns the underlying RTIMULib settings object.