Package: mfac
MFACModel Free Adaptive Control Toolbox for PythonThis project aims to provide a simple and fast python package for model-free adaptive control. The package includes compact form dynamic linearization (CFDL), partial form dynamic linearization (PFDL) and full form dynamic linearization (FFDL) model free adaptive control methods both for SISO and MIMO systems.InstallationYou can easily install MFAC Toolbox from PyPI:pip install MFACSimple ExampleThe following code shows the functionality of MFAC Toolbox in controlling a simple SISO system using CFDL method from (\examples\siso_cfdl_simple.py):importnumpyasnpimportmatplotlib.pyplotaspltfrommfac.plants.sisoimportModel1frommfac.controllersimportCompactFormDynamicLinearization# define the model and set the initial valuesmodel=Model1(initial_state=np.array([0]))# Simulation conditionstotal_time=8step_time=0.01# Desired output (y_desire)y_d=np.zeros(int(total_time/step_time)+1)forkinrange(int(total_time/step_time)+1):y_d[k]=0.5+0.5*np.power(-1,np.round(k/200))# log function which will be ran after each iterationdeflog_function(cfdl):print('iteration: ',cfdl.iteration)# define the controllercontroller=CompactFormDynamicLinearization(model=model,iteration_function=log_function,time_step=step_time,reference_output=y_d,simulation_time=total_time,labda=1,eta=1,mu=1,rho=0.45,)# run the simulationcontroller.run()# plot the outputfig,ax=plt.subplots()ax.plot(model.Y)ax.plot(y_d)ax.set(xlabel='time (t)',ylabel='output (y)',title='system output')ax.grid()# fig.savefig("test.png")plt.show()the output will be like:ComponentsTo control a system using the current MFAC library, two major components are required; model and controller.ModelA model is simply a class with the following structure:PartVariables/MethodsDescriptionInputInitial_state (array)Initial position of the plant in state spaceParametersnumber_of_inputs (int)number_of_states (int)number_of_outputs (int)x (array)y (array)u (array)X (array)Y (array)U (array)time (int)Number of control inputsNumber of state parametersNumber of outputsThe current state of the systemThe current output of the systemCurrent input control of the systemStates of the system during the simulationOutputs of the system during the simulationControls of the system during the simulationThe current time of the simulation (discrete)Functionsreset()step()observe()render()predict()Resets the plant for the next simulationGets the input controller and moves one step forward, returns the outputObserves the system's state or output variable defined byfull_stateinput parameterRenders the system based on input parametermodewhich can beprint,plot, orvisualGets a series of inputs (k future steps) and predicts the systems state or outputControllerA controller is simply a class with the following structure:PartVariables/MethodsDescriptionInputmodel (Model)iteration_function (Function)reference_output (array)simulation_time (int)time_step (Float)mimo (Boolean)Control parametersThe plant to be controlledThe function which will be called in each stepThe desired outputSimulation duration in secondsTimestep for each stepThe control for using the MIMO formControl parameters for each specific methodParametersu (array)fai (array)U (array)Fai (array)The current control inputThe current fai valueControl inputs during the simulationFai values during the simulationFunctionsrun()Runs the simulation based on the time and time step, in each step calles themodel.step()with the calculated control and calls theiteration_functionat the end of stepDevelopment StatusCurrently developed methods:CFDLFFDLPFDLCurrently developed models:Simple SISO model 1 (Model1)Simple MIMO model 1 (Model1)Currently tested scenarios:CFDL on SISO Model1CFDL on MIMO Model1