Skip to main content

Model Free Adaptive Control Toolbox

Project description

MFAC

Model Free Adaptive Control Toolbox for Python

This 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.

Installation

You can easily install MFAC Toolbox from PyPI:

pip install MFAC

Simple Example

The following code shows the functionality of MFAC Toolbox in controlling a simple SISO system using CFDL method from (\examples\siso_cfdl_simple.py):

import numpy as np
import matplotlib.pyplot as plt
from mfac.plants.siso import Model1
from mfac.controllers import CompactFormDynamicLinearization

# define the model and set the initial values
model = Model1(initial_state=np.array([0]))

# Simulation conditions
total_time = 8
step_time = 0.01

# Desired output (y_desire)
y_d = np.zeros(int(total_time / step_time) + 1)
for k in range(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 iteration
def log_function(cfdl):
    print('iteration: ', cfdl.iteration)

# define the controller
controller = 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 simulation
controller.run()

# plot the output
fig, 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:
img.png

Components

To control a system using the current MFAC library, two major components are required; model and controller.

Model

A model is simply a class with the following structure:

Part Variables/Methods Description
Input Initial_state (array) Initial position of the plant in state space
Parameters number_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 inputs
Number of state parameters
Number of outputs
The current state of the system
The current output of the system
Current input control of the system
States of the system during the simulation
Outputs of the system during the simulation
Controls of the system during the simulation
The current time of the simulation (discrete)
Functions reset()
step()
observe()
render()
predict()
Resets the plant for the next simulation
Gets the input controller and moves one step forward, returns the output
Observes the system's state or output variable defined by full_state input parameter
Renders the system based on input parameter mode which can be print, plot, or visual
Gets a series of inputs (k future steps) and predicts the systems state or output

Controller

A controller is simply a class with the following structure:

Part Variables/Methods Description
Input model (Model)
iteration_function (Function)
reference_output (array)
simulation_time (int)
time_step (Float)
mimo (Boolean)
Control parameters
The plant to be controlled
The function which will be called in each step
The desired output
Simulation duration in seconds
Timestep for each step
The control for using the MIMO form
Control parameters for each specific method
Parameters u (array)
fai (array)
U (array)
Fai (array)
The current control input
The current fai value
Control inputs during the simulation
Fai values during the simulation
Functions run() Runs the simulation based on the time and time step, in each step calles the model.step() with the calculated control and calls the iteration_function at the end of step

Development Status

Currently developed methods:

  • CFDL
  • FFDL
  • PFDL

Currently developed models:

  • Simple SISO model 1 (Model1)
  • Simple MIMO model 1 (Model1)

Currently tested scenarios:

  • CFDL on SISO Model1
  • CFDL on MIMO Model1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mfac-0.1.17.tar.gz (18.0 kB view hashes)

Uploaded Source

Built Distribution

mfac-0.1.17-py3-none-any.whl (17.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page