0

I have a combination of a Gyroscope, accelerometer, and magnetometer and I am trying to use the madgwick algorithm to find the roll, pitch, and yaw angle. I found the following code in GutHub and tried to run it in Spyder (Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)] Type "copyright", "credits" or "license" for more information. IPython 7.31.1 -- An enhanced Interactive Python. But I am getting the error. "ModuleNotFoundError: No module named 'madgwickahrs"

This is the code:

import numpy as np
from ahrs.filters import QUEST
from ahrs.filters import Madgwick
from madgwickahrs import MadgwickAHRS

gyr = np.array( [1.6, 0.6, 1.5])
acc = np.array( [1.2, 1.9, 1.3])
mag = np.array( [2.1, 1.3, 2.1])
gyr_rad = gyr * (np.pi/180)

heading = MadgwickAHRS()

while True:
    ninedofxyz = self._ninedof.read()
    heading.update(ninedofxyz[0], ninedofxyz[2], ninedofxyz[1])
    ahrs = heading.quaternion.to_euler_angles()
    roll = ahrs[0]
    pitch = ahrs[1]
    yaw = ahrs[2]

Can anyone help me with this error!

  • `madgwickahrs` is not a standard Python module. It must be a third-party library. You would need to install it yourself. Did you do that? – John Gordon Jul 09 '23 at 00:29

1 Answers1

0

You need to install the following repository as a python package (or alternatively, take the modules you require and duplicate them to your project).

To install a GitHub repository using pip, you can follow the instructions here.

Philip Ciunkiewicz
  • 2,652
  • 3
  • 12
  • 24
  • How should I install a repository as a python library? – SAHAR GOHARSHENASAN Jul 09 '23 at 13:32
  • I use "git clone https://github.com/morgil/madgwick_py.git" but it gives this error. Cloning into 'madgwick_py'... fatal: unable to access 'https://github.com/morgil/madgwick_py.git/': SSL certificate problem: unable to get local issuer certificate – SAHAR GOHARSHENASAN Jul 09 '23 at 14:19
  • I think for your case since the repository is small (two modules), it would be simpler for you to take the code from those modules and have it included locally in your project. Read up on the particular license that the code is using if this is relevant to your project. – Philip Ciunkiewicz Jul 10 '23 at 23:45