我目前正在做一个作业,需要在Matlab / Simulink中为机器人外骨骼腿创建两个不同的控制器。其背后的想法是将两者进行比较,并查看哪个控制器更适合于帮助人们佩戴它。将特定的方程式放入Matlab功能块,然后在Simulink中运行以获取AFO(自适应频率振荡器)的结果时,我遇到很多麻烦。该链接包含我要放入的方程式,以下是到目前为止的代码:
function [pos_AFO, vel_AFO, acc_AFO, offset, omega, phi, ampl, phi1] = LHip(theta, eps, nu, dt, AFO_on)
t = 0;
% syms j
% M = 6;
% j = sym('j', [1 M]);
if t == 0
omega = 3*pi/2;
theta = 0;
phi = pi/2;
ampl = 0;
else
omega = omega*(t-1) + dt*(eps*offset*cos(phi1));
theta = theta*(t-1) + dt*(nu*offset);
phi = phi*(t-1) + dt*(omega + eps*offset*cos(phi*core(t-1)));
phi1 = phi*(t-1) + dt*(omega + eps*offset*cos(phi*core(t-1)));
ampl = ampl*(t-1) + dt*(nu*offset*sin(phi));
offset = theta - theta*(t-1) - sym(ampl*sin(phi), [1 M]);
end
pos_AFO = (theta*(t-1) + symsum(ampl*(t-1)*sin(phi* (t-1))))*AFO_on; %symsum needs input arguement for index M and range
vel_AFO = diff(pos_AFO)*AFO_on;
acc_AFO = diff(vel_AFO)*AFO_on;
end
https://www.pastepic.xyz/image/pg4mP
基本上,我不知道该怎么做下标,sigma或(t + 1)函数。感谢您的任何帮助,因为这将在下周发布
答案 0 :(得分:1)
您正在寻找自适应过程的结果,因此您的算法需要考虑时间的进展。没有(t-1)运算符。这只是一种数学符号,告诉您需要重用旧值来计算新值。
omega_old=0;
theta_old=0;
% initialize the rest of your variables
for [t=1:N]
omega[t] = omega_old + % here is the rest of your omega calculation
theta[t] = theta_old + % ...
% more code .....
% remember your old values for next iteration
omega_old = omega[t];
theta_old = theta[t];
end
我认为您忘记了根据链接的原始公式对phi进行模运算。通常,将代码设计成小段,确保每段的输出有意义,然后合并所有段,并确保总体结果正确。