Skip to content

Instantly share code, notes, and snippets.

View MalcolmMielle's full-sized avatar
🦝
Having fun

Malcolm Mielle MalcolmMielle

🦝
Having fun
View GitHub Profile
@MalcolmMielle
MalcolmMielle / graph.py
Created January 17, 2024 17:05
Set up matlplotlib to get the same beautiful graph that I had in gnuplot
# This script will create a graph with a light grey grid to see the spacing between values
# The axis will be visible only on the bottom and left, and both the axis and labels will
# be light blue/green
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use("pgf")
matplotlib.rcParams.update(
{
@MalcolmMielle
MalcolmMielle / IMURPYKalmanFilter.py
Last active September 15, 2023 13:14
Kalman filter to calculate roll pitch yaw. Based on the BaseKalman in KalmanFilter.py
def convert_acc(acc):
"""Convert raw accelerometer measurements in roll pitch yaw
https://stackoverflow.com/questions/3755059/3d-accelerometer-calculate-the-orientation
The yaw equation comes from here https://robotics.stackexchange.com/questions/14305/yaw-from-accelerometer-no-so-what-do-these-equations-actually-mean
If you have a magnetometer check out https://habr.com/en/post/499190/
Args:
acc (np.array): Array containing the three raw measurements on the accelerometer along
x, y, z
Returns:
@MalcolmMielle
MalcolmMielle / KalmanFilter.py
Created December 31, 2020 11:38
A base class for (Extended) Kalman Filter
from typing import Tuple
import numpy as np
class BaseKF:
"""This class can hold either a Kalman filter or an extended kalman filter depending on
the way f and h are implemented.
"""
def __init__(self, z0: np.array, r: np.array, q: np.array, pval=0.1) -> None:
self.x_sk = z0
self.n = q.shape[0] # number of state