概述
近几天时间比较充足,便学习一下S函数求解微分方程。其求解方程如下:
D
(
q
)
q
¨
+
C
(
q
,
q
˙
)
q
˙
+
G
(
q
)
+
ω
=
τ
Dleft( q right)ddot q + C(q,dot q)dot q{rm{ + G}}left( q right) + omega = tau
D(q)q¨+C(q,q˙)q˙+G(q)+ω=τ (2.7)
ω
=
d
1
+
d
2
∥
e
∥
+
d
3
∥
e
˙
∥
omega = {d_1} + {d_2}left| e right| + {d_3}left| {dot e} right|
ω=d1+d2∥e∥+d3∥e˙∥ (2.10)
y
=
e
˙
+
γ
e
y = dot e + gamma e
y=e˙+γe (2.11)
q
˙
r
=
q
˙
d
−
γ
e
{dot q_r} = {dot q_d} - gamma e
q˙r=q˙d−γe (2.12)
其中
e
=
q
−
q
d
e = q - {q_d}
e=q−qd,
e
˙
=
q
˙
−
q
˙
d
dot e = dot q - {dot q_d}
e˙=q˙−q˙d,
q
q
q是实际输出变量,
q
d
q_d
qd是期望输出变量
τ
=
−
K
p
e
−
K
v
e
˙
+
ϕ
(
q
,
q
˙
,
q
˙
r
,
q
¨
r
)
P
^
+
u
tau {rm{ = - }}{K_p}e - {K_v}dot e + phi left( {q,dot q,{{dot q}_r},{{ddot q}_r}} right)hat P + u
τ=−Kpe−Kve˙+ϕ(q,q˙,q˙r,q¨r)P^+u (2.16)
u
=
[
u
1
⋯
u
n
]
T
,
u
i
=
−
(
d
1
+
d
2
∥
e
∥
+
d
3
∥
e
˙
∥
)
s
g
n
(
y
i
)
u{rm{ = }}{left[ {{u_1} cdots {u_n}} right]^T},{u_i} = - ({d_1} + {d_2}left| e right| + {d_3}left| {dot e} right|){mathop{rm sgn}} left( {{y_i}} right)
u=[u1⋯un]T,ui=−(d1+d2∥e∥+d3∥e˙∥)sgn(yi) (2.17)
P
^
˙
=
−
Γ
ϕ
T
(
q
,
q
˙
,
q
˙
r
,
q
¨
r
)
y
dot { hat {P} }= - Gamma {phi ^T}(q,dot q,{dot q_r},{ddot q_r})y
P^˙=−ΓϕT(q,q˙,q˙r,q¨r)y (2.18)
K
p
=
K
p
1
+
K
p
2
B
p
(
e
)
,
K
v
=
K
v
1
+
K
v
2
B
(
e
˙
)
{K_p} = {K_{p1}} + {K_{p2}}{B_p}left( e right),{K_v} = {K_{v1}} + {K_{v2}}Bleft( {dot e} right)
Kp=Kp1+Kp2Bp(e),Kv=Kv1+Kv2B(e˙)
K
p
1
=
d
i
a
g
(
k
p
11
,
k
p
12
,
⋯
,
k
p
1
n
)
,
K
p
2
=
d
i
a
g
(
k
p
21
,
k
p
22
,
⋯
,
k
p
2
n
)
{K_{p1}} = diagleft( {{k_{p11}},{k_{p12}}, cdots ,{k_{p1n}}} right),{K_{p2}} = diagleft( {{k_{p21}},{k_{p22}}, cdots ,{k_{p2n}}} right)
Kp1=diag(kp11,kp12,⋯,kp1n),Kp2=diag(kp21,kp22,⋯,kp2n)
K
v
1
=
d
i
a
g
(
k
v
11
,
k
v
12
,
⋯
,
k
v
1
n
)
,
K
v
2
=
d
i
a
g
(
k
v
21
,
k
v
22
,
⋯
,
k
v
2
n
)
{K_{v1}} = diagleft( {{k_{v11}},{k_{v12}}, cdots ,{k_{v1n}}} right),{K_{v2}} = diagleft( {{k_{v21}},{k_{v22}}, cdots ,{k_{v2n}}} right)
Kv1=diag(kv11,kv12,⋯,kv1n),Kv2=diag(kv21,kv22,⋯,kv2n)
B
p
(
e
)
=
d
i
a
g
(
1
a
1
+
∣
e
1
∣
,
1
a
2
+
∣
e
2
∣
,
⋯
,
1
a
n
+
∣
e
n
∣
)
{B_p}left( e right) = diagleft( {frac{1}{{{a_1} + left| {{e_1}} right|}},frac{1}{{{a_2} + left| {{e_2}} right|}}, cdots ,frac{1}{{{a_n} + left| {{e_n}} right|}}} right)
Bp(e)=diag(a1+∣e1∣1,a2+∣e2∣1,⋯,an+∣en∣1)
B
v
(
e
)
=
d
i
a
g
(
1
β
1
+
∣
e
˙
1
∣
,
1
β
2
+
∣
e
˙
2
∣
,
⋯
,
1
β
n
+
∣
e
˙
n
∣
)
{B_v}left( e right) = diagleft( {frac{1}{{{beta _1} + left| {{{dot e}_1}} right|}},frac{1}{{{beta _2} + left| {{{dot e}_2}} right|}}, cdots ,frac{1}{{{beta _n} + left| {{{dot e}_n}} right|}}} right)
Bv(e)=diag(β1+∣e˙1∣1,β2+∣e˙2∣1,⋯,βn+∣e˙n∣1)
仿真参数设置如下:
D
11
(
q
2
)
=
(
m
1
+
m
2
)
r
1
2
+
m
2
r
2
2
+
2
m
2
r
1
r
2
c
o
s
q
2
D_{11}(q_2)=(m_1+m_2)r_1^2+m_2r_2^2+2m_2r_1r_2cosq_2
D11(q2)=(m1+m2)r12+m2r22+2m2r1r2cosq2
D
12
(
q
2
)
=
m
2
r
2
2
+
m
2
r
1
r
2
c
o
s
q
2
D_{12}(q_2)=m_2r_2^2 + m_2r_1r_2cosq_2
D12(q2)=m2r22+m2r1r2cosq2
D
22
(
q
2
)
=
m
2
r
2
2
D_{22}(q_2)=m_2r_2^2
D22(q2)=m2r22
D
=
[
D
11
,
D
12
;
D
12
,
D
22
]
D = [D_{11},D_{12};D_{12},D_{22}]
D=[D11,D12;D12,D22]
C
12
(
q
2
)
=
m
2
r
1
r
2
s
i
n
q
2
C_{12}(q_2)=m_2r_1r_2sinq_2
C12(q2)=m2r1r2sinq2
C
=
[
−
C
12
q
˙
2
,
−
C
12
(
q
˙
1
+
q
˙
2
)
;
C
12
q
˙
1
,
0
]
C=[-C_{12}dot q_2,-C_{12}(dot q_1 + dot q_2);C_{12}dot q_1, 0]
C=[−C12q˙2,−C12(q˙1+q˙2);C12q˙1,0]
G
1
(
q
1
,
q
2
)
=
(
m
1
+
m
2
)
r
1
c
o
s
q
2
+
m
2
r
2
c
o
s
(
q
1
+
q
2
)
G_1(q_1,q_2)=(m_1+m_2)r_1cosq_2+m_2r_2cos(q_1+q_2)
G1(q1,q2)=(m1+m2)r1cosq2+m2r2cos(q1+q2)
G
2
(
q
1
,
q
2
)
=
m
1
r
2
c
o
s
(
q
1
+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.5,m_2=0.5,d_1=2,d_2=3,d_3=6,omega=d_1+d_2left| { e} right|+d_3left| {dot e} right|
r1=1,r2=0.8,m1=0.5,m2=0.5,d1=2,d2=3,d3=6,ω=d1+d2∥e∥+d3∥e˙∥
q
1
d
=
s
i
n
(
2
∗
π
∗
t
)
,
q
2
d
=
s
i
n
(
2
∗
π
∗
t
)
q_{1d}=sin(2*pi*t),q_{2d}=sin(2*pi*t)
q1d=sin(2∗π∗t),q2d=sin(2∗π∗t)
[
q
1
;
q
˙
1
;
q
2
;
q
˙
2
]
=
[
0.1
;
0
;
0.1
;
0
]
[q_1;dot q_1;q_2;dot q_2]=[0.1;0;0.1;0]
[q1;q˙1;q2;q˙2]=[0.1;0;0.1;0]
K
p
1
=
d
i
a
g
(
180
,
190
)
,
K
p
2
=
d
i
a
g
(
150
,
150
)
K_{p1}=diag(180,190),K_{p2}=diag(150,150)
Kp1=diag(180,190),Kp2=diag(150,150)
K
v
1
=
d
i
a
g
(
180
,
180
)
,
K
v
2
=
d
i
a
g
(
150
,
150
)
K_{v1}=diag(180,180),K_{v2}=diag(150,150)
Kv1=diag(180,180),Kv2=diag(150,150)
α
i
=
β
i
=
1
(
i
=
1
,
2
)
,
γ
=
5
,
Γ
=
[
5
0
0
;
0
5
0
;
0
0
5
]
alpha_i=beta_i =1(i=1,2),gamma=5,Gamma=[5space0space 0;0 space5 space0;0space 0 space5]
αi=βi=1(i=1,2),γ=5,Γ=[5 0 0;0 5 0;0 0 5]
编程分析:等式2.7右边写成一个S函数。首先分析输入参数个数,由于等式2.16中有
q
,
q
˙
,
q
d
,
q
˙
d
,
q
¨
d
q,dot q,q_d,dot q_d,ddot q_d
q,q˙,qd,q˙d,q¨d五个变量,并且每个变量是二维的所以输入参数设置为10。输出变量
τ
tau
τ是个二维的,
p
p
p是三维的,所以右边S函数的输出设置为5。直接反馈设置为1中间需要求解公式2.18,所以此函数需要用到微分模块sys=mdlDerivatives(t,x,u),所以连续变量状态数设置为3。
等式2.7左边的S函数编写,求解过程中需要
q
,
q
˙
d
,
τ
q_,dot q_d,tau
q,q˙d,τ三个变量,所以输入个数设置6,输出变量
q
,
q
˙
q,dot q
q,q˙,所以设置为4。等式2.7左边是个二维二阶微分方程求解,所以连续状态设置为4。
由于CSDN粘贴Matlab代码不方便,具体的函数编写放在相应的附件中。https://download.csdn.net/download/cswh876908060/12155057。如需代写,或者咨询,请联系:
最后
以上就是稳重电灯胆为你收集整理的Matlab S函数求解PD控制的二阶微分或者二阶状态方程的全部内容,希望文章能够帮你解决Matlab S函数求解PD控制的二阶微分或者二阶状态方程所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复