%%
%------HOBM S BLDC MOTOREM------%
%

%%
%pozn.:

    %---rovnice BLDC motoru--%
    %{
       %Napěťová rovnice
           u(t) = 2*R_a*i(t) + 2*L_a*(di(t)/dt) + u_i(t)
           u(t) = 2*R_a*i(t) + 2*L_a*(di(t)/dt) + C_fi*w(t)
       %Momentová rovnice
           M(t) = J(dw(t)/dt) + B*w(t) + M_0
           M(t) = C_fi*i(t)
    %}

%%
%DATASHEETS AND OTHERS
    %whole set
        %https://www.maxongroup.com/maxon/view/service_search?query=248999
        %part number: 248999
    
    %Motor info
        %https://www.maxongroup.com/maxon/view/product/136198?fbclid=IwAR3cqwtDUjNfYqP8-_RPmIEz0rOxLixNP8-nvA9--8vebHsEo4HaGvyeC3w
        %part number: 136198
        
        %Nominal voltage:                           24      V
        %No load speed:                             6090    rpm
        %No load current:                           328     mA
        %Nominal speed:                             4840    rpm
        %Nominal torque (max. countinuous torque):  183     mNm
        %Nominal current (max. continuous current): 5.13    A
        %Stall torque:                              952     mNm
        %Stall current:                             25.6    A
        %Max. efficiency:                           79      %
        
        %Characteristics:
            %Terminal resistance phase to phase:    0.936   ohmfa
            %Terminal inductance pahse to phase:    0.275   mH
            %Torque constant:                       37.1    mNm/A
            %Speed constant:                        257     rpm/V
            %Speed/torque gradient:                 6.49    rpm/mNm
            %Mechanical time constant:              8.08    ms
            %Rotor inertia:                         119     gcm^2
    
    %Gear box
        %https://www.maxongroup.com/maxon/view/product/gear/planetary/gp42/203126
        %part number: 203126
        
        %Reduction:                 113:1   -
        %Mass inertia:              9.4     gcm^2
        %Max. motor shaft diametr:  8       mm
        
    %Encoder
        %https://www.maxongroup.com/maxon/view/product/137959?fbclid=IwAR2HMVj-urgFbWpDbkQUuKsUrMYakHKm16gF2wuRqy7sBowdOrZ4Rha4N8w
        %part number: 137959
        
           %counts per turn: 500
        %quadratic per turn: 4*500 = 2000
    
%%
clear all; clc;

%%
%BASIC VARIABLES
    m = 1.2;           %kg
    r = 5.3346;              %mms
    start_pos = 0;      %mm
    g = 9.81;           %m/s^2
    deadZone = 0.200;     %kg

%%
%GEAR BOX
    reduct = 1;                %-
    J_p = 9.4e-7;                %kg*m^2
    B_p = 0%B;                  %Nms

%%    ss
%WRINCH
    J_n = 0;                     %kg*m^2
        
%%
%MOTOR CONSTANTS
    Speed_const = 257;            %rpm/V
    U_max =     24;                 %V
    C_fi =      1/(Speed_const*2*pi/60);            %Nm/A
    R_a =       0.936/2;              %ohm
    L_a =       (0.275e-3)/2;           %H
    T_mech =    8.08e-3;            %s
    J_k =       119e-7;             %kgm^2
    n_max =     6090;               %rpm
    w_max =     n_max*2*pi/60;      %rad/s
    I_no_load = 328e-3;             %A
    I_max =     25.6;               %A
    M_max =     952e-3;             %Nm
    
    %Damping
        %T_mech = J/B => B = J/T_mech
        B = J_k/T_mech     %Nms
    
    %Eletrical time constant
        %T_el = L_a/R_a
        T_el = L_a/R_a;     %s
    
    %Max. vertical velocity
        v_max = (r*w_max)/(reduct*1000);    %m/s

%%
%PRINT 
    fprintf('------HOBM------\n');
    %fprintf('\nU_max:\t%f\tV\n', U_max);
    %fprintf('I_max:\t%f\tA\n', I_max);
    fprintf('v_max:\t%f\tm/s\n', v_max);
    fprintf('\n');
    
%%