This documentation is for an unreleased version of MPF!

This is the developer documentation for MPF 0.51, which is the “dev” (next) release of MPF that is a work-in-progress. Use the “Read the Docs” link in the lower left corner to view the developer docs for the version of MPF you’re using.


class mpf.devices.accelerometer.Accelerometer(*args, **kwargs)

Bases: mpf.core.system_wide_device.SystemWideDevice

Implements a multi-axis accelerometer.

In modern machines, accelerometers can be used for tilt detection and to detect whether a machine is properly leveled.

The accelerometer device produces a data stream of readings which MPF converts to g-forces, and then events can be posted when the “hit” (or g-force) of an accelerometer exceeds a predefined threshold.

Accessing accelerometers in code

The device collection which contains the accelerometers in your machine is available via self.machine.accelerometers. For example, to access one called “foo”, you would use self.machine.accelerometers.foo. You can also access accelerometers in dictionary form, e.g. self.machine.accelerometers['foo'].

You can also get devices by tag or hardware number. See the DeviceCollection documentation for details.

Methods & Attributes

Accelerometers have the following methods & attributes available. Note that methods & attributes inherited from base classes are not included here.

get_level_xyz() → float

Return current 3D level.

get_level_xz() → float

Return current 2D x/z level.

get_level_yz() → float

Return current 2D y/z level.

raise_config_error(msg, error_no, *, context=None)

Raise a ConfigFileError exception.

update_acceleration(x: float, y: float, z: float) → None

Calculate acceleration based on readings from hardware.