2012-04-14 360 views
0

注意:这是我第一次使用MATLAB S函数,而且我只用了少量的Simulink。s函数直接馈通

当我尝试在S函数inp中使用我的输入变量时,他们返回NaN标志3。系统的输入是三个简单的统一步骤功能,通过总线创建者连接到系统。当试图模拟系统时,我收到一条错误信息 - 我只通过在inp上进行测试打印而发现它们是NaN。有任何想法吗?


详情:
我模拟赛格威作为一类项目。我在Simulink中将执行器(直流电机)和设备(Segway本身)作为单独的S功能块进行仿真。电机需要三个输入:一个电压,Segway的速度,以及相对于其俯仰轴的角速度Segway(由于反电动势)。输出是电枢电流。

这是一个简单的线性非差分系统。出于这个原因,没有国家。唯一完成的计算是从输入到输出的馈通。代码如下:

function [sys,X0]=nl_pend(time,state,inp,FLAG,ICs); 
% actuator parameters: 
% R_m: motor armature resistance 
% K_b: motor back emf constant 
% K_t: motor torque constant 
% r: radius of the wheel 
global R_m K_b K_t r; 

if FLAG == 0, % initialize system parameters and states 
% Call file that initializes parameters 
    segway_dcmotor_pars; 
% This system has: 
% 0 states (theta,thetatheta_dot), 
% 3 input (v,x_dot,theta_dot), 
% 1 outputs (i) 
nx = 0; % # of states 
nu = 3; % # of inputs 
ny = 1; % # of outputs 
sys = [nx; 0; ny; nu; 0; 0]; 
% Initial Conditions (will be passed as and argument) 
X0 = ICs; 
elseif FLAG == 1, % states derivatives 
    %blank 
elseif FLAG == 3, % system outputs 
    %inp(1) = motor voltage 
    %inp(2) = segway velocity 
    %inp(3) = segway pitch angular velocity 
    display(inp); 
    y(1) = (1/R_m)*inp(1) - (K_b/(r*R_m))*inp(2) + (K_b/R_m)*inp(3); 
    sys = y; 
else, 
    sys = []; 
end 
+0

嘛。我改变了它,以便不是没有状态,系统有一个单一的状态q,它是电枢中的电荷。 由于这是一个解决方案,而不是一个答案,我会留下任何想法的问题,为什么第一种方法不起作用。 – Ataraxia 2012-04-14 16:25:02

回答

1

至于你提到的,我已经找到了解决办法是直接馈通,所以你必须设置

sys(6)=1 in flag==0...