Automatic Control Knowledge Repository

You currently have javascript disabled. Some features will be unavailable. Please consider enabling javascript.

Details for: "Bell 201A-1 helicopter D.-"

Name: Bell 201A-1 helicopter D.- (Key: COM21)
Path: ackrep_data/system_models/compleib_models/HE3 View on GitHub
Type: system_model
Short Description: HE3 Bell 201A-1 helicopter D.-W. Gu, P. Hr. Petkov and M. M. Konstantinov, "H_inf and H_2 Optimization Toolbox in SLICOT", SLICOT Working Note 1999-12, available via ftp wgs.esat.kuleuven.ac.be/ pub/WGS/REPORTS/SLWN1999-12.ps.Z
Created: 2022-10-10 15:53:25
Compatible Environment: default_conda_environment (Key: CDAMA)
Source Code [ / ] simulation.py
# This file was autogenerated from the template: simulation.py.template (2022-10-10 15:53:25).

import numpy as np
import system_model
from scipy.integrate import solve_ivp, odeint

from ackrep_core import ResultContainer
from ackrep_core.system_model_management import save_plot_in_dir
import matplotlib.pyplot as plt
import os
from ipydex import Container

# link to documentation with examples: https://ackrep-doc.readthedocs.io/en/latest/devdoc/contributing_data.html


def simulate():
    """
    simulate the system model with scipy.integrate.solve_ivp

    :return: result of solve_ivp, might contains input function
    """

    model = system_model.Model()

    rhs_xx_pp_symb = model.get_rhs_symbolic()
    rhs = model.get_rhs_func()

    # initial state values
    xx0 = np.ones(model.sys_dim)

    t_end = 10
    tt = np.linspace(0, t_end, 1000)

    simulation_data = solve_ivp(rhs, (0, t_end), xx0, t_eval=tt)

    # using odeint for models with large state vectors
    # res = odeint(rhs, y0=xx0, t=tt, tfirst=True)
    # simulation_data = Container()
    # simulation_data.y = res.transpose()
    # simulation_data.t = tt

    # postprocessing: calc output
    ny = 6
    C = model.get_parameter_value("C")
    D21 = model.get_parameter_value("D21")
    output = np.zeros((ny, len(tt)))
    for i in range(len(tt)):
        output[:,i] = np.matmul(C, simulation_data.y[:,i]) # + np.matmul(D21, w)
    simulation_data.output = output

    save_plot(simulation_data)

    return simulation_data


def save_plot(simulation_data):
    """
    plot your data and save the plot
    access to data via: simulation_data.t   array of time values
                        simulation_data.y   array of data components
                        simulation_data.uu  array of input values

    :param simulation_data: simulation_data of system_model
    :return: None
    """

    for i in range(simulation_data.output.shape[0]):
        plt.plot(simulation_data.t, simulation_data.output[i], label=f"$y_{i}$")

    plt.legend()
    plt.tight_layout()

    save_plot_in_dir()


def evaluate_simulation(simulation_data):
    """
    assert that the simulation results are as expected

    :param simulation_data: simulation_data of system_model
    :return:
    """
    expected_final_state = np.array([-25.15934549,  27.58959294,  -1.60676421, -42.85335097,
         2.75549403,  -6.03782014,  -6.28992315,   5.23811152])

    rc = ResultContainer(score=1.0)
    simulated_final_state = simulation_data.y[:, -1]
    rc.final_state_errors = [
        simulated_final_state[i] - expected_final_state[i] for i in np.arange(0, len(simulated_final_state))
    ]
    rc.success = np.allclose(expected_final_state, simulated_final_state, rtol=0, atol=1e-2)

    return rc
system_model.py
# This file was autogenerated from the template: system_model.py.template (2022-10-10 15:53:25).

import sympy as sp
import numpy as np
import symbtools as st
import importlib
import sys, os
#from ipydex import IPS, activate_ips_on_exception  

from ackrep_core.system_model_management import GenericModel, import_parameters

# Import parameter_file
params = import_parameters()


#link to documentation with examples: https://ackrep-doc.readthedocs.io/en/latest/devdoc/contributing_data.html


class Model(GenericModel): 

    def initialize(self):
        """
        this function is called by the constructor of GenericModel

        :return: None
        """

        # Define number of inputs -- MODEL DEPENDENT
        self.u_dim = 4

        # Set "sys_dim" to constant value, if system dimension is constant 
        self.sys_dim = 8

        # check existence of params file
        self.has_params = True
        self.params = params
        

    # ----------- SET DEFAULT INPUT FUNCTION ---------- # 
    def uu_default_func(self):
        """
        define input function
    
        :return:(function with 2 args - t, xx_nv) default input function 
        """ 
        
        def uu_rhs(t, xx_nv):
            """
            sequence of numerical input values

            :param t:(scalar or vector) time
            :param xx_nv:(vector or array of vectors) numeric state vector
            :return:(list) numeric inputs 
            """ 
            u = np.zeros(self.u_dim)
            return u

        return uu_rhs


    # ----------- SYMBOLIC RHS FUNCTION ---------- # 

    def get_rhs_symbolic(self):
        """
        define symbolic rhs function

        :return: matrix of symbolic rhs-functions
        """
        if self.dxx_dt_symb is not None:
            return self.dxx_dt_symb

        x = self.xx_symb  
        A, B, B1, C1, C, D11, D12, D21 = self.pp_symb   # parameters
        w = np.zeros(1) # noise
        u = self.uu_symb   # inputs

        # define symbolic rhs functions
        self.dxx_dt_symb = np.matmul(A,x) + np.matmul(B1,w) + np.matmul(B,u)
        



        return self.dxx_dt_symb
    
parameters.py
# This file was autogenerated from the template: parameters.py.template (2022-10-10 15:53:25).

import sys
import os
import numpy as np
import sympy as sp

import tabulate as tab


#link to documentation with examples: https://ackrep-doc.readthedocs.io/en/latest/devdoc/contributing_data.html


# set model name
model_name = 'Bell 201A-1 helicopter D.-'


# ---------- create symbolic parameters
A = sp.MatrixSymbol('A', 8, 8)
B = sp.MatrixSymbol('B', 8, 4)
B1 = sp.MatrixSymbol('B1', 8, 1)
C1 = sp.MatrixSymbol('C1', 10, 8)
C = sp.MatrixSymbol('C', 6, 8)
D11 = sp.MatrixSymbol('D11', 10, 1)
D12 = sp.MatrixSymbol('D12', 10, 4)
D21 = sp.MatrixSymbol('D21', 6, 1)

pp_symb = [A, B, B1, C1, C, D11, D12, D21]


# ---------- create auxiliary symbolic parameters 

# set numerical values of auxiliary parameters
# trailing "_nv" stands for "numerical value"
A_nv = sp.Matrix(np.array([[-4.600e-03,  3.800e-02,  3.259e-01, -4.500e-03, -4.020e-01,
        -7.300e-02, -9.810e+00,  0.000e+00],
       [-1.978e-01, -5.667e-01,  3.570e-01, -3.780e-02, -2.149e-01,
         5.683e-01,  0.000e+00,  0.000e+00],
       [ 3.900e-03, -2.900e-03, -2.947e-01,  7.000e-03,  2.266e-01,
         1.480e-02,  0.000e+00,  0.000e+00],
       [ 1.330e-02, -1.400e-03, -4.076e-01, -6.540e-02, -4.093e-01,
         2.674e-01,  0.000e+00,  9.810e+00],
       [ 1.270e-02, -1.000e-02, -8.152e-01, -3.970e-02, -8.210e-01,
         1.442e-01,  0.000e+00,  0.000e+00],
       [-2.850e-02, -2.320e-02,  1.064e-01,  7.090e-02, -2.786e-01,
        -7.396e-01,  0.000e+00,  0.000e+00],
       [ 0.000e+00,  0.000e+00,  1.000e+00,  0.000e+00,  0.000e+00,
         0.000e+00,  0.000e+00,  0.000e+00],
       [ 0.000e+00,  0.000e+00,  0.000e+00,  0.000e+00,  1.000e+00,
         0.000e+00,  0.000e+00,  0.000e+00]]))
B_nv = sp.Matrix(np.array([[ 6.7600e-02,  1.2210e-01, -1.0000e-04, -1.6000e-03],
       [-1.1151e+00,  1.0550e-01,  3.9000e-03,  3.5000e-03],
       [ 6.2000e-03, -6.8200e-02,  1.0000e-03, -3.5000e-03],
       [-1.7000e-02,  4.9000e-03,  1.0670e-01,  1.6920e-01],
       [-1.2900e-02,  1.0600e-02,  2.2270e-01,  1.4300e-01],
       [ 1.3900e-01,  5.9000e-03,  3.2600e-02, -4.0700e-01],
       [ 0.0000e+00,  0.0000e+00,  0.0000e+00,  0.0000e+00],
       [ 0.0000e+00,  0.0000e+00,  0.0000e+00,  0.0000e+00]]))
B1_nv = sp.Matrix(np.array([[ 6.7600e-02,  1.2210e-01, -1.0000e-04, -1.6000e-03],
       [-1.1151e+00,  1.0550e-01,  3.9000e-03,  3.5000e-03],
       [ 6.2000e-03, -6.8200e-02,  1.0000e-03, -3.5000e-03],
       [-1.7000e-02,  4.9000e-03,  1.0670e-01,  1.6920e-01],
       [-1.2900e-02,  1.0600e-02,  2.2270e-01,  1.4300e-01],
       [ 1.3900e-01,  5.9000e-03,  3.2600e-02, -4.0700e-01],
       [ 0.0000e+00,  0.0000e+00,  0.0000e+00,  0.0000e+00],
       [ 0.0000e+00,  0.0000e+00,  0.0000e+00,  0.0000e+00]]))
C1_nv = sp.Matrix(np.array([[0., 1., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 1., 0.],
       [0., 0., 0., 0., 0., 0., 0., 1.],
       [0., 0., 0., 0., 0., 1., 0., 0.],
       [0., 0., 1., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 1., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0.]]))
C_nv = sp.Matrix(np.array([[0., 1., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 1., 0.],
       [0., 0., 0., 0., 0., 0., 0., 1.],
       [0., 0., 0., 0., 0., 1., 0., 0.],
       [0., 0., 1., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 1., 0., 0., 0.]]))
D11_nv = sp.Matrix(np.array([[0.],
       [0.],
       [0.],
       [0.],
       [0.],
       [0.],
       [0.],
       [0.],
       [0.],
       [0.]]))
D12_nv = sp.Matrix(np.array([[0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [1., 0., 0., 0.],
       [0., 1., 0., 0.],
       [0., 0., 1., 0.],
       [0., 0., 0., 1.]]))
D21_nv = sp.Matrix(np.array([[0.  ],
       [0.1 ],
       [0.  ],
       [0.  ],
       [0.05],
       [0.  ]]))


# ---------- create symbolic parameter functions
# parameter values can be constant/fixed values OR set in relation to other parameters (for example: a = 2*b)  


# list of symbolic parameter functions
# tailing "_sf" stands for "symbolic parameter function"
pp_sf = [A_nv, B_nv, B1_nv, C1_nv, C_nv, D11_nv, D12_nv, D21_nv]


#  ---------- list for substitution
# -- entries are tuples like: (independent symbolic parameter, numerical value)
pp_subs_list = []


# OPTONAL: Dictionary which defines how certain variables shall be written
# in the table - key: Symbolic Variable, Value: LaTeX Representation/Code
# useful for example for complex variables: {Z: r"\underline{Z}"}
latex_names = {}


# ---------- Define LaTeX table

# Define table header 
# DON'T CHANGE FOLLOWING ENTRIES: "Symbol", "Value"
tabular_header = ["Symbol", "Value"]

# Define column text alignments
col_alignment = ["center", "left"]


# Define Entries of all columns before the Symbol-Column
# --- Entries need to be latex code
col_1 = [] 

# contains all lists of the columns before the "Symbol" Column
# --- Empty list, if there are no columns before the "Symbol" Column
start_columns_list = []


# Define Entries of the columns after the Value-Column
# --- Entries need to be latex code
col_4 = []

# contains all lists of columns after the FIX ENTRIES
# --- Empty list, if there are no columns after the "Value" column
end_columns_list = []

Related Problems:
Extensive Material:
Result: Success.
Last Build: Checkout CI Build
Runtime: 4.0 (estimated: 10s)