Implementing a Kalman Filter on the UNO Q MPU

Is there anything like NumPy or other matrix arithmetic packages available to help me implement a Kalman Filter on the UNO Q MPU? I see there is a KALMAN.h for the MCU, but I don't want to tie up the real-time processor with this task.

Sure, it is possible, but the first thing to do is come up with a system model. You will benefit from any package that implements efficient matrix math, because the Kalman filter is computationally very heavy.

Thank you for your reply.

My question is about what packages are available that implement efficient matrix math or the Kalman Filter itself. There must be something available if the UNO Q is going to be used for mobile robots.

I would request you to interface an IMU sensor (such as the MPU6050) with the MCU of the Arduino Uno (UNO Q board). After acquiring the sensor data, please apply a Kalman filter using the Kalman.h library. The objective is to demonstrate how the Kalman filter improves the quality of the measured signals, particularly by reducing noise and drift in angle estimation.

Please present the post in the form of a structured tutorial or a repository-style project so that it can be easily imported and used within the App Lab environment.

NumPy is one of them. SciPy is another, but depends on NumPy.

Kalman filters constitute a general approach to estimating the state of a linear system, so there is no "one size fits all" implementation.

Of course, I will be more than happy to share whatever software I develop.

My goal is to develop a SLAM package that will perform both mapping and navigation in my home. While I could sketch the map and make an occupancy grid, I much prefer to have a robot do this job for me.

SLAM is too much for the MCU. The MCU certainly can collect sensor data, do data filtering and send this data to the MPU and I will do that hopefully very soon.

My concern is that the Arduino community is too MCU focused for the UNO Q. If I make any contribution to this community it will by moving appropriate applications to the MPU. SLAM is one such application.

About filtering IMU sensor data, there are several excellent filters for this application. My experience shows when you use a Kalman Filter with sensors it is often for the purpose of sensor fusion.

My question remains: Is there any package on the MPU that will helpful while writing a Kalman Filter?

Is NumPy actually available on the UNO Q MPU?

No idea. Is it too much trouble for you to check? I missed that you want to run this on the MPU, did you mean in C/C++ on the STM32?

I would go with Linux and Python and not waste my time with the MPU.

I did try to check and came up empty. I was hoping I just missed it and that the forum could help me out.

MPU of the UNO Q is a part of syllabus for the forum members.

The fact that you did not come up with anything is telling you something.

There are of course several general purpose matrix libraries written in C or C++ (Eigen and uBLAS are examples), but it would be a major effort to implement a new Kalman filter in the Arduino programming environment.

Some years ago NXP released C/C++ code for a Kalman filter AHRS to support their 9-DOF IMUs.

Adafruit incorporated that into their larger AHRS package, so I looked to see how NXP implemented their filter. The code includes a small matrix library sufficient for the required operations, so that may give you some ideas. I don't know what system model NXP used, but presumably the documentation can be found on NXP's web pages.

Source files Adafruit_AHRS/src at master · adafruit/Adafruit_AHRS · GitHub

Or an earlier version by Paul Stoffregen GitHub - PaulStoffregen/NXPMotionSense: NXP Motion Sensors for Teensy and Arduino · GitHub

Hi @thweight.

The important thing to keep in mind is that the MPU is running a Debian Linux operating system. This means that, in general, it doesn't make sense to ask the question "is x available on the UNO Q MPU?", any more than it would make sense to ask the question "is x available on my Dell Inspiron laptop?". You install the software you need, rather than expecting it to be something built-in to the MPU.

So the question should rather be: how do I install NumPy? The answer to that will depend on how you wish to use NumPy. If you want to use it in an Arduino App Lab "App", you can follow these instructions:

  1. Start Arduino App Lab.
  2. Create or open the App in which you wish to use NumPy.
  3. Select "Editor" from the top bar in the Arduino App Lab window.
  4. Right click (Control-click for macOS users) on the python folder under the "Files" section of the left hand panel in the Arduino App Lab window.
    A context menu will open.
  5. Select "Create file" from the menu.
    A text field will open under the python folder.
  6. Type requirements.txt.
  7. Press the Enter key.
  8. Wait for the notification to appear at the bottom of the Arduino App Lab window:

    File created successfully

  9. The newly created requirements.txt file will open as a tab in the editor panel of the Arduino App Lab window. Type the following line into the editor:
    numpy
    

You can now use the NumPy package in the Python script component of the App. You can learn about using NumPy from the documentation here:

You can learn about the requirements.txt Python package dependency manifest file here:

Arduino App Lab automatically installs the Python packages you specify in the python/requirements.txt file of the App.


In case you instead wish to use NumPy outside the Arduino App framework, you can get general information about installing it under the UNO Q's primary Linux machine here:

(note this is not necessary if you are only using it in Arduino Apps)

If you have any questions or problems doing that, just let us know and we'll provide further assistance.

Great! I'm sure the community will be very interested in your project and findings.

Keep in mind that, among other things, the UNO Q is a general Linux computer. So iuf you don't get any results when you are doing research, check to see if you may be "poisoning" your search by overly narrowing it through the use of keywords like "Arduino" or "UNO Q". In some cases, you will find that vast quantities of general information about Linux, Python, shell, etc. available on the Internet to be completely applicable to working with the UNO Q.

Thank you so much. This information is pure gold.

You are welcome. I'm glad if I was able to be of assistance.

Regards, Per