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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file mfac-0.1.17.tar.gz.

File metadata

  • Download URL: mfac-0.1.17.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for mfac-0.1.17.tar.gz
Algorithm Hash digest
SHA256 c36acc67ca530cdeb12359321b52c159fffcb70d4214d81b735868c82a896676
MD5 f753a36b1d8833cf2a11f5c3e7324e57
BLAKE2b-256 6a1173620dd56aad97c0c6f05979e93b68653a2132efefabdb92a64366739435

See more details on using hashes here.

File details

Details for the file mfac-0.1.17-py3-none-any.whl.

File metadata

  • Download URL: mfac-0.1.17-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for mfac-0.1.17-py3-none-any.whl
Algorithm Hash digest
SHA256 9d6e527967cf8fd1565790fed846eab5f564fae12cc722529796abec63ab0af3
MD5 2b04ece8211f9b533e74aa94c1f8ed59
BLAKE2b-256 2645364448e4312307c4f319acd71ffd2ddcb7d40b32aa0b080ef770326ea03b

See more details on using hashes here.

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