永磁同步电机递推最小二乘法辨识转动惯量J和负载转矩TL

下面是我在simulink中S-Function搭建的递推最小二乘法的函数,这样之后就进行不下去了,也找不到解决方法,有没有大佬解答一下,救命!!!

以下代码中感觉有问题的在y的公式和最后J、TL的计算上面!

function [sys, x0, str, ts] = RLS_J_TL_SFunction(t, x, u, flag)
    switch flag
        case 0  % Initialization
            [sys, x0, str, ts] = mdlInitializeSizes;
        case 2  % Update discrete states
            sys = [];
        case 3  % Calculate outputs
            sys = mdlOutputs(t, x, u);
        case {1, 4, 9}  % Unused flags
            sys = [];
        otherwise
            DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
    end

function [sys, x0, str, ts] = mdlInitializeSizes
    sizes = simsizes;
    sizes.NumContStates  = 0;
    sizes.NumDiscStates  = 0;
    sizes.NumOutputs     = 2;  % Two outputs: J and TL
    sizes.NumInputs      = 2;   % Two inputs: Measured torque and speed
    sizes.DirFeedthrough = 1;
    sizes.NumSampleTimes = 1;

    sys = simsizes(sizes);
    x0  = [];  % No initial states
    str = [];
    ts  = [0 0];  % Set the sample time (0 means continuous)

    % Initialize parameters for RLS
    global P_past2 theta_past2 
    P_past2 = 1e4 * eye(3, 3);  % Three-dimensional covariance matrix
    theta_past2 = [0.0001; 0.0001; 0.0001];

function sys = mdlOutputs(t, x, u)
    global P_past2 theta_past2

%初值的确定
    lambda = 1;  %遗忘因子0-1
    
    Te = u(1);
    wm = u(2);
    xt = [Te -wm -1];  
    y = u(2);%theta_past2(1)*Te+theta_past2(2)*(-wm)+theta_past2(3)*(-1);
    I = eye(3,3);
    
    K = P_past2*xt'/(lambda + xt * P_past2*xt');  
    P_new = 1/lambda*(I - K*xt) * P_past2;  
    theta_new = theta_past2 + K*(y-xt*theta_past2);   
    
    P_past2 = P_new ;
    theta_past2 = theta_new;
    
    A = theta_new(1);
    B = theta_new(2);
    C = -theta_new(3);
    ts= ;
    J = -(1+B)*ts/A*log(-B) ;
    TL= C/A;
    
    sys = [J; TL];
  • 13
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值