-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicalSystem.m
More file actions
75 lines (69 loc) · 2.75 KB
/
DynamicalSystem.m
File metadata and controls
75 lines (69 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
% ┌─────────────────────────────────────────────────────────────────────────┐
% │ Dynamical System Class │
% └─────────────────────────────────────────────────────────────────────────┘
% by Marco Tallone, 2024
%
% Abstract class to define dynamical systems
%
% Usage
% classdef MySystem < DynamicalSystem
%
% Methods
% discretize - Discretize a continuous-time linear system
classdef (Abstract) DynamicalSystem < handle
properties (Abstract)
n % number of states
m % number of inputs
p % number of outputs
Ts % sampling time
eps_x; % state constraints matrix
f_x; % state constraints vector
eps_u; % input constraints matrix
f_u; % input constraints vector
end
methods (Abstract)
dxdt = dynamics(obj, t, x, u)
x_final = simulate(obj, x0, u, T)
y = output(obj, x, u)
[A_lin, B_lin] = linearize(obj, x_bar, u_bar)
x_ref_fixed = fix_angles(obj, x, x_ref)
x_hat = EKF_estimate(obj, x_hat, u, y)
[x_ref, u_ref, Tend] = generate_trajectory(obj, N_guide, shape, extra_params)
end
methods
% Discretization function (from linear system)
function [A_discrete, B_discrete] = discretize(obj, A, B)
% discretize
% Discretize a continuous-time linear system using Euler method
%
% Syntax
% [A_discrete, B_discrete] = obj.discretize(A, B)
%
% Input Arguments
% A - State matrix
% real matrix
% B - Input matrix
% real matrix
%
% Output Arguments
% A_discrete - Discretized state matrix
% real matrix
% B_discrete - Discretized input matrix
% real matrix
% Euler discretization
A_discrete = eye(obj.n) + A * obj.Ts;
B_discrete = B * obj.Ts;
end
% m-matrix m(t) function for Murray trajectory generation
function m_matrix = m_matrix(obj, t, basis, order)
syms x
m_matrix = zeros(order+1, length(basis));
for i = 0:order
for j = 1:length(basis)
derivative = diff(basis(j), x, i);
m_matrix(i+1, j) = subs(derivative, x, t);
end
end
end
end
end