ode45 events function error

2 ビュー (過去 30 日間)
Avinash Siravuru
Avinash Siravuru 2014 年 11 月 25 日
編集済み: Avinash Siravuru 2014 年 11 月 25 日
Hi,
I am trying to integrate a systems of differential equations and I require it to stop at a certain condition. To this end, I tried using the events function that is built into the ode45 solver. However I get an error saying 'Too many input arguments'. More precisely,
'Error using events Too many input arguments.
Error in odeevents (line 29) eventValue = feval(eventFcn,t0,y0,eventArgs{:});
Error in ode45 (line 148) [haveEventFcn,eventFcn,eventArgs,valt,teout,yeout,ieout] = ...
Error in omega_single_main2 (line 18) [t,x] = ode45(@omegaSingleDynamics,[tin tout],x0,options); % xf(i,:)'
I looked up on this forum for suggestions and I tried them all and the problem still persists. Could someone please help me break this deadlock? I've spent way too much time trying to fix this problem. Thank you.
I have attached the code below.
function omega_single_main2
R2 = [1 0 0;0 0 0;0 0 -1]; % virtual constraint for q2 (in terms of q1)
e3 = [0 0 1]';
w01 = [0 -2.5 0];
q01 = Ry(-pi/12)*[0 0 1]';
q01 = q01';
x0 = [q01 w01];
tin = 0;
tout = 0.4;
options = odeset('Events',@events);
% options = odeset('RelTol',1e-7,'AbsTol',1e-9);
[t,x] = ode45(@omegaSingleDynamics,[tin tout],x0,options); % xf(i,:)
[r,m,Mh,Mt,L,g]= omega_modelparams;
nt = size(t,1);
%
x_new = omega_single_transition(x(nt,:)');
function dx = omegaSingleDynamics(t,x)
R2 = [1 0 0;0 0 0;0 0 -1]; % virtual constraint for q2 (in terms of q1)
q1 = x(1:3); % position variables
q2 = R2*q1;
q3 = [0 0 1]';
w1 = x(4:6); % ang vel variable
w2 = [0 0 0;0 -1 0;0 0 0]*w1;
w3 = [0 0 0]';
u2 = zeros(3,1);
u3 = zeros(3,1);
[M C G U] = omega_model(q1,q2,q3,w1,w2,w3,u2,u3);
dx(1:3,1) = hat(q1)*w1;
% dx(4:6,1) = hat(q2)*w2;
% dx(7:9,1) = hat(q3)*w3;
dx_bar = M\(U-G-C);
dx(4:6,1) = dx_bar(1:3);
% Ab = [-r*hat(q1) -r*hat(q2) zeros(3) eye(3)]*[w1;w2;w3;zeros(3,1)];
% Ab = norm(Ab);
function [value,isterminal,direction] = events(t,x)
r = 1;
q1 = x(1:3); % position variables
q2 = R2*q1;
q3 = [0 0 1]';
w1 = x(4:6); % ang vel variable
w2 = [0 0 0;0 -1 0;0 0 0]*w1;
w3 = [0 0 0]';
value= norm([-r*hat(q1) -r*hat(q2) zeros(3) eye(3)]*[w1;w2;w3;zeros(3,1)]);
isterminal=1;
direction=0;
end
% dx = dx'
end
end
function [M C G U] = omega_model(q1,q2,q3,w1,w2,w3,u2,u3)
[r,m,Mh,Mt,L,g]= omega_modelparams; % Robot Model Parameters
e1 = [1 0 0]';
e2 = [0 1 0]';
e3 = [0 0 1]';
M11 = (1.25*m + Mh + Mt)*r^2;
M12 = 0.5*m*r^2;
M13 = Mt*r*L;
M22 = 0.25*m*r^2;
M33 = Mt*L^2;
G1 = (1.5*m + Mh + Mt)*g*r;
G2 = 0.5*m*g*r;
G3 = Mt*g*L;
M = [M11*eye(3) -M12*hat(q1)*hat(q2) -M13*hat(q1)*hat(q3);
-M12*hat(q2)*hat(q1) M22*eye(3) zeros(3);
-M13*hat(q3)*hat(q1) zeros(3) M33*eye(3)];
C = [-M12*norm(w2)*hat(q1)*q2-M13*norm(w3)*hat(q1)*q3;
-M12*norm(w1)*hat(q2)*q1;
-M13*norm(w1)*hat(q3)*q1];
G = [ G1*hat(q1)*e3;
G2*hat(q2)*e3;
G3*hat(q3)*e3];
U = [zeros(3,1);hat(q2)*u2;hat(q3)*u3];
function[r,m,Mh,Mt,L,g]= three_leg_modelparams()
% Model Params
r=1; % length of a leg
m=5; % mass of a leg
Mh=15; % mass of hips
Mt=10; % mass of torso
L=0.5; % distance between hips and torso
g=-9.8; % acceleration due to gravity
end
function My = Ry(th) My = [cos(th) 0 sin(th);0 1 0;-sin(th) 0 cos(th)]; end
function ahat = hat(a) ahat = [0 -a(3) a(2);a(3) 0 -a(1);-a(2) a(1) 0]; end
  2 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 11 月 25 日
Avinash - I tried running your code, omega_single_main2, and it failed with a
Undefined function 'Ry' for input arguments of type 'double'.
What is Ry, a function or variable? Also, what is omega_modelparams?
The error message, Too many input arguments, is telling you that too many input arguments are being supplied to some function. For example,
sqrt(4,4)
generates the same error since I am providing two inputs instead of one. In your case, it isn't clear what line of code is generating this error message, so please update your question with all relevant error message text (so this would be all the red text from the Command Window).
Avinash Siravuru
Avinash Siravuru 2014 年 11 月 25 日
編集済み: Avinash Siravuru 2014 年 11 月 25 日
Thank you Geoff! I apologize for missing out Ry and hat functions. I have updated the the question now. Also, I added the exact error message. Looking forward to your feedback.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by