-
Notifications
You must be signed in to change notification settings - Fork 2
Sensors
The MPU6050 combines a gyroscope and an accelerometer. Current angular velocity and acceleration values can be read via I2C at any given time. Here's our MPU6050 wrapper class.
The gyroscope provides the angular velocity for the given moment in degrees (not radians) per second. The accelerometer provides the aceeleration values in multiples of gravity (gravity is 9.81 m/s2). Gyroscope and accelerometer each provide one value per axis (x, y, z).
Each of the six values is represented by two bytes that can be read via I2C. Two bytes can store values in the range [-32768, +32767]. The MPU6050 features a configuration register for gyroscope and accelerometer each, where one can configure the mapping of this range to the actual measurement units.
- For the gyroscope: +-250, +-500, +-1000, +-2000 degrees/sec
- For the accelerometer: +-2, +-4, +-8, +-16 g (= 9.81 m/s2)
In our MPU6050 wrapper, we compute a factor for gyroscope and accelerometer (one for each) to ease conversion from read-out values to actual measurement results. For the accelerometer, we convert to m/s2.
In general, depending on the area of use, the MPU6050 may be exposed to certain vibrations, e.g. when mounted on a motor, etc. A DLPF can be used to filter out those frequencies to ensure measurements remain uneffected. The strength of the DLPF intervention and the measurement delay it causes can be balanced in consideration of the given use case:
Each individual chip has a slight error on all 6 measurements. These errors are constant offsets than can be identified by averaging values over a longer period of time. These calibration values are stored on an EEPROM (flash storage) on the same board as the MPU6050. Our MPU6050 wrapper take calibration data as an initialization parameter and applies them on every measurement before returning it.
The MPU6050 is mounted on a circuit board which is mounted on the kite. The mounting position of the circuit board on the kite varies among kite generations. Our MPU6050 wrapper consumes 3 mapping functions (one per axis) on initialization. Each of these mapping functions consumes the three MPU6050 measurements (either gyroscope or acceleration, the procedure is equal) to compute the kite's x, y or z axis. As with calibrtion, this is applied on every measurement before returning it.
The Bosch BMP280 is a pressure (and temperature) sensor. In our setup, we do not actively measure temperature. However, the Bosch API that is integrated in our codebase internally requires the temperature in order to compute the pressure from the sensor readings. We use pressure to infer the current height of the kite. Here's our BMP280 wrapper class.
Measurements are three bytes long and provided in Pascal (not hPa).
The following aspects can be configured:
- Mode
- Standby duration / measurement frequency
- Oversampling of temperature and pressure measurements
- IIR filter (see next section)
The sensor features several modes. This project uses the normal mode in which the sensor constantly performs measurements and keeps the results availble for reading through I2C (similar to MPU6050). The standby duration between two measurements is configurable between 0.5ms and 4s. It is possible to configure oversampling (and this project does so) to enhance precision at the cost of a higher energy consumption. Oversamping can be configured for temperature and pressure individually.
The IIR filter smoothens the measurements and removes factors like wind turbulences etc. When enabled, the filter combines the latest measurement and past measrements using weights before writing the results to the respective registers. This project uses the maximum IIR filtering provided by the BMP280.
There are some important considerations when communication with the I2C devices of this project (that includes the CAT24C256 flash storage which is not on this page):
- The CAT24C256 automatically increments the address on continous write operations while the other two do not.
- The CAR24C256 has a adress length of 2 bytes while the other two have 1 byte adress length.
- When reading measurements from BMP280 and MPU6050 it is important to use sequentail reads instead of reading the bytes individually to not mix bytes from two readings.
The Wrapper classes of MPU6050, BMP280 and CAT24C256 all inherit from the same I2cDevice class. The I2cDevices class is our wrapper for the Espressif I2C Driver. As such, it automatically manages the two I2C controllers offered by the ESP32. Upon initialization, the I2cDevice class consumes an I2cConfig struct with the following information:
- Bus (SDA/SCL) to which the devices is connected
- Chip address of the device
- Whether or not the device automatically increments adresses on write operations