Help with code, Not enough arguments. Possible Euler error?
Ältere Kommentare anzeigen
Thanks very much for any help on this. Sorry to be asking this so close to Christmas, but I have been stuck in a rut and can't get my way out of it. I have to have the code and report in by tonight and I would appreciate any and all help you that can be provided.
I am currently having trouble with the MATLAB code that is within this file The outputs that I need to get are values for X and (X dot) being positions and speed of parts of a robot arm system.
clear all
global BSM BSF JM JG1 JF Gc GR L R KE KF KG KI KR KS KT lF mF thetafref thetaU mu
BSM = 0.01;
BSF = 1.5;
JM = 0.002;
JG1 = 0.001;
JF = 0.020;
Gc = 8.1;
GR = 1.7;
L = 0.1;
R = 4;
KE = 0.35;
KF = 0.6;
KG = 2.0;
KI = 0;
KR = 1.1;
KS = 1.1;
KT = 0.35;
lF = 0.35;
mF = 0.5;
thetafref = 0.6981;
thetaU = 15;
mu = 1;
stepsize = 0.1;
comminterval = 0.1;
EndTime = 2;
noofst = EndTime/stepsize;
u = 0; % Although there is no input, it is defined for model
x = zeros(7,1);
y = zeros(size(x));
xdot = zeros(7,1)';
xout = zeros(noofst,1);
tout = zeros(noofst,1);
xdout = zeros(noofst,1);
i = 0;
for time = 0:stepsize:EndTime
if rem(time,comminterval)==0
i = i+1;
tout(i,1) = time;
for j=1:7
xout(i) = x(i);
xdout(i,1) = xdot(i);
xdot = f(x,u);
x = RK4(stepsize, xdot,time,f);
end
end
end
figure(1)
clf
plot(tout,xout(:,1),'bo-')
xlabel('time [s]')
ylabel('states')
hold on
grid on
plot(tout,xout(:,2),'ro-')
hold off
function x = RK4(stepsize, xdot,time,f)
k1 = stepsize*f(xdot(j),time);
k2 = stepsize*f(xdot(j)+stepsize/2, time+k1/2);
k3 = stepsize*f(xdot(j)+stepsize/2, time+k2/2);
k4 = stepsize*f(xdot(j)+stepsize, time+k3);
time = time + (k1+2*k2+2*k3+k4)/6;
xdot(j+1) = xdot(j) + stepsize;
end
function xdot = f(x,u)
global BSM BSF JM JG1 JF Gc GR L R KE KF KG KI KR KS KT lF mF thetafref thetaU mu
xdot(1,1) = (((Gc*KG*((thetafref*KR)-(x(2)*KS)))-(R*x(1))-(KE*x(3)))/L);
xdot(2,1) = x(3);
xdot(3,1) = ((KT*x(1))-(BSM*(abs(x(3)-x(5)))))/JM;
xdot(4,1) = x(5);
xdot(5,1) = (BSF/JG1)*(abs(x(5)-x(7)));
xdot(6,1) = x(7);
xdot(7,1) = ((GR*KF*x(4))-(BSF*x(5))-(((mF*lF*9.81)/2)*(sin(x(3)+x(1)))))/JF;
end
I have included in the code file and Simulink diagram so you can have the full picture. The main error that I'm encountering is
''' Not enough input arguments. Error in Robot_arm_Model>f (line 72) xdot(1,1) = (((Gc*KG*((thetafref*KR)-(x(2)*KS)))-(R*x(1))-(KE*x(3)))/L); Error in Robot_arm_Model (line 45) x = RK4(stepsize, xdot,time,f); '''
Antworten (1)
Walter Roberson
am 22 Dez. 2021
x = RK4(stepsize, xdot,time,f);
That is invoking the function f. In that particular line you need @f
It would be better if you used a different name for the function f than you use for the function handle that you use to carry the function around.
Kategorien
Mehr zu Signal Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!