Skip to content
Snippets Groups Projects
as_model_nl.m 2.18 KiB
Newer Older
function [dx, y] = as_model_nl(t, x, u, ks, ku, r, bs, bu, fs, fu, gf, FileArgument)
    % AS_MODEL_NL(t, x, u, ...) Simulate a system step for nonlinear greybox identification
    % 
    % This function is intended to be given to nlgreyest(). Please see
    % the source code of as_model_nl() for explanation of what 
    % its parameters mean.

    ms = 2.5;
    mu = ms / r;
    
    % explanation of parameters:
    % - ks = stiffness of the spring between the upper and lower masses
    % - ku = stiffness of the spring between the lower mass and the road platform
    % - ms = mass of the upper mass
    % - mu = mass of the lower mass
    % - r  = ratio of ms/mu. This is what is actually optimized - it seems
    %        that this removes an unconstrained degree of freedom in the
    %        parameters.
    % - bs = coefficient of viscous friction between the upper mass and the guiding rail connected to the base
    % - bu = coefficient of viscous friction between the lower mass and the guiding rail connected to the base
    % - fs = coefficient of static friction between the upper mass and the guiding rail connected to the base
    % - fu = coefficient of static friction between the lower mass and the guiding rail connected to the base
    % - gf = relative strength of the actuator between lower and upper masses

    % explanation of states/inputs/outputs:
    % - x(1) = height of the upper mass above the base, minus its idle position
    % - x(2) = speed of the upper mass wrt. the base
    % - x(3) = height of the lower mass above the base, minus its idle position
    % - x(4) = speed of the lower mass wrt. the base
    % - u(1) = road height above the base, minus its idle position
    % - u(2) = actuator control signal
    % - y(1) = x(1)
    % - y(2) = x(3)


    zs = x(1);
    dzs = x(2);
    zus = x(3);
    dzus = x(4);
    zr = u(1);
    act = u(2);

    sprung_Fext   = +gf*act -(zs-zus)*ks;
    unsprung_Fext = -gf*act +(zs-zus)*ks + (zr-zus)*ku;
    sprung_Ffri   = -dzs *bs - sign(dzs) *fs;
    unsprung_Ffri = -dzus*bu - sign(dzus)*fu;

    dx = [
        dzs;
        (sprung_Fext + sprung_Ffri) / ms;
        dzus;
        (unsprung_Fext + unsprung_Ffri) / mu
    ];
    y = [zs; zus];
end