This repository contains Python code for implementing an offline Kalman filter-based state estimator for the Mini Cheetah robot. The filter processes logged data to estimate the robot's center of mass (COM) position and velocity, as well as individual leg positions, velocities, and heights. It is designed for offline analysis and debugging of state estimation algorithms. This code is based on the Cheetah Software published by the MIT Biomimetic Robotics Lab.
The Linear Kalman filter operates in two main steps:
- Observation:
- Kalman Gain:
- State Update:
- Covariance Update:
The state vector contains the following components:
-
COM Position (3 values):
$[x, y, z]$ -
COM Velocity (3 values):
$[\dot{x}, \dot{y}, \dot{z}]$ - Leg Positions (4 legs × 3 values each):
Total size of
The matrix
- The top-left
$6 \times 6$ block handles the COM position and velocity dynamics. - The bottom-right
$12 \times 12$ block is an identity matrix for the leg positions.
The control input vector
-
Control Input Matrix (
$B$ ):
-
Input Vector (
$a_k$ ): Acceleration input:$[a_x, a_y, a_z]$
The measurement vector contains:
- Leg Positions (4 legs × 3 values each):
- Leg Velocities (4 legs × 3 values each):
- Leg Heights (4 legs × 1 value each):
Total size of
The matrix
- Direct mapping of leg positions from
$\hat{x}$ to$y_k$ . - Negative identity blocks for relative positions and velocities.
-
Process Noise Covariance (
$Q$ ): Represents uncertainty in the model:- If you want to rely more on the model, which uses states calculated from IMU data, you should decrease the values in
$Q$ . A better IMU means more confidence in the model, so you can lower the noise values.
- If you want to rely more on the model, which uses states calculated from IMU data, you should decrease the values in
-
Measurement Noise Covariance (
$R$ ): Represents sensor noise:- If you want to rely more on the inverse kinematics (measurements), you should decrease the values in
$R$ . This means putting more trust in the sensor data (leg positions, foot tip positions) rather than the model.
- If you want to rely more on the inverse kinematics (measurements), you should decrease the values in
-
Log Parsing: The
parse_log_filefunction is responsible for extracting data from the logged file which are computed using inverse kinematics. The data contains real-world measurements recorded from the robot during operations. These measurements will be used as inputs for the Kalman filter to estimate the robot's state:-
Leg Positions: These are collected from the robot’s legs, representing their positions in space.
-
Z Foot Tip: The foot tip height of the legs.
These two (leg positions and foot tip positions) will serve as the measurements
$(y_k)$ in the Kalman filter’s observation update step, where they are compared with the predicted values from the model. -
-
Kalman Filtering: The
LinearKalmanFilterfunction applies the Kalman filter algorithm:-
Prediction: The state vector is predicted based on the previous state and accelaration inputs, using the system's state transition matrix
$A$ . -
Observation: The observed measurements
$y_k$ , which include leg positions and foot tip positions, are compared with the predicted state values$yModel$ calculated from the accelerometer data of the IMU. -
Error Calculation: The difference between the observed measurements
$y_k$ and the predicted values$yModel$ generates an error vector$e_y$ .
-
-
State Estimation:
- The error vector
$e_y$ is multiplied by the Kalman Gain ($K_k$ ) to compute how much influence the measurement error will have on correcting the state estimate. - This correction is then added to the previous state estimate
$\hat{x}_{k|k-1}$ to update the state estimate to a new value$\hat{x}_{k|k}$ .
- The error vector
A logged file (in .txt format) from real robot tests in the Recovery Stand and Squat Down modes of the Mini Cheetah is provided. You can use this data to run offline tests, debug the Kalman filter, and analyze the accuracy and performance of the state estimator.
- P.S: Additionally, there is another Python script that implements the mathematical model of KF symbolically.