Dynamics#
Dynamical system models for parameter estimation benchmarks.
Quadrotor#
Full 6-DOF quadrotor dynamics with inertial parameter management.
This module implements a rigid-body quadrotor model with:
Separate ground-truth and estimated inertial parameters (mass, center of mass, full 3x3 inertia tensor).
Newton-Euler data matrix/force vector for parameter estimation (
A theta = b).Payload attach/detach via parallel-axis theorem.
Aerodynamic added-inertia and parameter drift utilities.
RK4 integration and autograd-based linearisation.
- class online_estimators.dynamics.quadrotor.QuadrotorDynamics(r_off=None)[source]#
Bases:
objectRigid-body quadrotor with separate true/estimated inertial parameters.
The model uses a quaternion attitude representation
q = [q_w, q_x, q_y, q_z]and a 13-dimensional state vector:x = [r(3), q(4), v(3), omega(3)]where
ris the world-frame position,qthe body->world quaternion,vthe world-frame linear velocity, andomegathe body-frame angular velocity.- Parameters:
r_off (array-like or None) – Initial body-frame COM offset (3-vector). Defaults to zero.
- T = array([[ 1., 0., 0., 0.], [ 0., -1., 0., 0.], [ 0., 0., -1., 0.], [ 0., 0., 0., -1.]])#
- H = array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])#
- set_true_inertial_params(theta)[source]#
Set ground-truth inertial parameters.
- Parameters:
theta (np.ndarray, shape
(10,)) –[m, m*cx, m*cy, m*cz, Ixx, Iyy, Izz, Ixy, Ixz, Iyz]- Return type:
- get_true_inertial_params()[source]#
Return the 10-vector of ground-truth inertial parameters.
- Returns:
[m, m*cx, m*cy, m*cz, Ixx, Iyy, Izz, Ixy, Ixz, Iyz]- Return type:
np.ndarray, shape
(10,)
- set_estimated_inertial_params(theta)[source]#
Update the controller’s believed inertial parameters.
- Parameters:
theta (np.ndarray, shape
(10,))- Return type:
- get_estimated_inertial_params()[source]#
Return the 10-vector of estimated inertial parameters.
- Return type:
np.ndarray, shape
(10,)
- get_data_matrix(x, dx)[source]#
Build the 6x10 Newton-Euler data matrix
A.Constructs the matrix such that
A theta = wwheretheta = [m, mcx, mcy, mcz, Ixx, Iyy, Izz, Ixy, Ixz, Iyz].Forces and torques are expressed in the body frame.
- Parameters:
x (np.ndarray, shape
(13,)) – State[r, q, v, omega].dx (np.ndarray, shape
(13,)) – State derivative[rdot, q_dot, v_dot_world, alpha_body].
- Return type:
np.ndarray, shape
(6, 10)
- get_force_vector(x_curr, dx, u_curr=None)[source]#
Build the 6x1 wrench vector
b(body frame).The wrench is purely gravito-inertial (excludes motor forces), matching
get_data_matrix()so thatA theta = b.- Parameters:
x_curr (np.ndarray, shape
(13,))dx (np.ndarray, shape
(13,))u_curr (np.ndarray or None) – Unused; kept for API compatibility.
- Return type:
np.ndarray, shape
(6,)
- detach_payload()[source]#
Detach (drop) the most recently attached payload.
- Raises:
RuntimeError – If no payloads are attached.
ValueError – If removing the payload would yield non-positive mass.
- Return type:
- static closest_spd(theta, epsilon=1e-06)[source]#
Project the inertia sub-matrix of
thetato the nearest SPD matrix.- Parameters:
theta (np.ndarray, shape
(10,))epsilon (float) – Eigenvalue floor.
- Return type:
np.ndarray, shape
(10,)
- aero_added_inertia(wind_vec)[source]#
Apply aerodynamic added-inertia perturbation from a wind vector.
- Parameters:
wind_vec (np.ndarray, shape
(3,))- Return type:
- add_drift(mass_std=0.0, inertia_std=0.0, com_std=0.0)[source]#
Add Gaussian drift to true inertial parameters.
- static hat(v)[source]#
Skew-symmetric matrix from 3-vector:
hat(u) v == u x v.- Parameters:
v (np.ndarray, shape
(3,))- Return type:
np.ndarray, shape
(3, 3)
- static L(q)[source]#
Left-quaternion multiplication matrix:
L(q) p == q (x) p.- Parameters:
q (np.ndarray, shape
(4,))- Return type:
np.ndarray, shape
(4, 4)
- classmethod qtoQ(q)[source]#
Quaternion to 3x3 rotation matrix (body -> world).
- Parameters:
q (np.ndarray, shape
(4,))- Return type:
np.ndarray, shape
(3, 3)
- classmethod G(q)[source]#
Quaternion kinematic Jacobian
G(q) = L(q) H.- Parameters:
q (np.ndarray, shape
(4,))- Return type:
np.ndarray, shape
(4, 3)
- static rptoq(phi)[source]#
Rodrigues parameters (3-vector) -> unit quaternion.
- Parameters:
phi (np.ndarray, shape
(3,))- Return type:
np.ndarray, shape
(4,)
Double Pendulum#
Double pendulum dynamics with RK4 integration.
Implements the equations of motion for a planar double pendulum with autograd-based Jacobian computation for linearisation.
- class online_estimators.dynamics.double_pendulum.DoublePendulum(g=9.81, m1=1.0, m2=1.0, l1=1.0, l2=1.0, dt=0.01)[source]#
Bases:
objectPlanar double pendulum with autograd-based linearisation.
State vector:
x = [theta_1, omega_1, theta_2, omega_2]- Parameters:
Examples
>>> from online_estimators.dynamics import DoublePendulum >>> dp = DoublePendulum() >>> x0 = np.array([0.1, 0.0, 0.2, 0.0]) >>> u = np.array([0.0]) >>> x1 = dp.step(x0, u)
- continuous_dynamics(state, m1, m2, l1, l2, g, u)[source]#
Continuous-time equations of motion.
- Parameters:
state (np.ndarray, shape
(4,)) –[theta_1, omega_1, theta_2, omega_2]m1 (float) – Physical parameters.
m2 (float) – Physical parameters.
l1 (float) – Physical parameters.
l2 (float) – Physical parameters.
g (float) – Physical parameters.
u (np.ndarray, shape
(1,)) – Torque applied to the second link.
- Returns:
[omega_1, alpha_1, omega_2, alpha_2]- Return type:
np.ndarray, shape
(4,)