You can increase the frequency of measurement if you like! This cycle repeats every 1/10 of a second. Finally, I run a while loop to get real sensor values and plug them into the filter to spit out the new filtered value.Be careful in that an alpha value that is too high can make your application too slow to respond to changes, it can be an empirical choice when deciding what alpha value to use.įinally, I run a while loop to get real sensor values and plug them into the filter to spit out the new filtered value. ![]() That means the higher the alpha value, the more filtering we will be doing and we will get a smoother signal. The concept is simple, the higher the alpha value, the more we trust the previous data value, in this case, our acceleration in the x-direction. In the 2nd portion of the code I am initializing an alpha value and creating the lowpass filter function.Be careful in that an alpha value that is too high can make your application too slow to respond to changes, it can be an empirical choice when deciding what alpha value to use. In the 2nd portion of the code, I am initializing an alpha value and creating the lowpass filter function. You are probably not concerned with this if you are reading this tutorial. Initially I am creating a connection to my MPU6050 object, which is the sensor I am getting data from. ![]() Initially, I am creating a connection to my MPU6050 object, which is the sensor I am getting data from. The code I have in MicroPython (this is essentially equivalent to Python excluding some libraries) is shown here: #Native libs from machine import Pin, I2C import math import time from time import sleep from imu import MPU6050 i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000) sensor = MPU6050(i2c) filtered_ax = 0 alpha = 0.85 # must be between 0 and 1 inclusive def low_pass_filter(prev_value, new_value): return alpha * prev_value + (1 - alpha) * new_value while True: ax_new = filtered_ax = low_pass_filter(filtered_ax, ax_new) print("filtered_ax: ", filtered_ax, "raw ax", ax_new) time.sleep(1/10)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |