Klipper3d / klipper

Klipper is a 3d-printer firmware
GNU General Public License v3.0
8.98k stars 5.17k forks source link

accelerometer: Fix LIS2DW and MPU9250 abnormal reading #6582

Closed Neko-vecter closed 1 month ago

Neko-vecter commented 1 month ago

Fix abnormal reading when using ACCELEROMETER_QUERY and MEASURE_AXES_NOISE.

Below is what happen after commit 43ce7c0b9ad4f30277c10b086b86a0937dbfebbc. The ACCELEROMETER_QUERY and MEASURE_AXES_NOISE reading are abnormal. It around 7 times larger than normal value. Screenshot 2024-04-29 112602

line 40 in lis2dw.py

        self.axes_map = adxl345.read_axes_map(config)

The LIS2DW and MCP9250 are using the ADXL345 SCALE value.

After change self.axes_map using the LIS2DW SCALE value.

        am = {'x': (0, SCALE), 'y': (1, SCALE), 'z': (2, SCALE),
              '-x': (0, -SCALE), '-y': (1, -SCALE), '-z': (2, -SCALE)}
        axes_map = config.getlist('axes_map', ('x','y','z'), count=3)
        if any([a not in am for a in axes_map]):
            raise config.error("Invalid lis2dw axes_map parameter")
        self.axes_map = [am[a.strip()] for a in axes_map]

Below is the result after using LIS2DW SCALE value. Screenshot 2024-04-29 125339

Signed-off-by: Vecter Fang vecterfang@icloud.com

KevinOConnor commented 1 month ago

Thanks. Good catch. I implemented a slightly different fix (commit d8d072b3).

-Kevin

github-actions[bot] commented 1 month ago

This ticket is being closed because the underlying issue is now thought to be resolved.

Best regards, ~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.