MFAC


NameMFAC JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/shahind/MFAC
SummaryModel Free Adaptive Control
upload_time2022-12-11 10:26:12
maintainer
docs_urlNone
authorShahin Darvishpoor
requires_python
licenseGPLv3
keywords mfac control dynamic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MFAC
<a><img align="right" src="https://img.shields.io/github/license/shahind/MFAC"/></a>
<a><img align="right" src="https://img.shields.io/pypi/v/MFAC"/></a>
<a><img align="right" src="https://img.shields.io/pypi/pyversions/MFAC"/></a>
<a><img align="right" src="https://img.shields.io/github/languages/code-size/shahind/MFAC?color=blueviolet"/></a>
<p align="center">
  <img src="https://github.com/shahind/MFAC/raw/main/logo.png" />
</p>
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`):

```python
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](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)<br>number_of_states (int)<br>number_of_outputs (int)<br>x (array)<br>y (array)<br>u (array)<br>X (array)<br>Y (array)<br>U (array)<br>time (int) |       Number of control inputs<br>Number of state parameters<br>Number of outputs<br>The current state of the system<br>The current output of the system<br>Current input control of the system<br>States of the system during the simulation<br>Outputs of the system during the simulation<br>Controls of the system during the simulation<br>The current time of the simulation (discrete)       |
| Functions  |                                                         reset()<br>step()<br>observe()<br>render()<br>predict()                                                         | Resets the plant for the next simulation<br>Gets the input controller and moves one step forward, returns the output<br>Observes the system's state or output variable defined by `full_state` input parameter<br>Renders the system based on input parameter `mode` which can be `print`, `plot`, or `visual`<br>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)<br>iteration_function (Function)<br>reference_output (array)<br>simulation_time (int)<br>time_step (Float)<br>mimo (Boolean)<br>Control parameters | The plant to be controlled<br>The function which will be called in each step<br>The desired output<br>Simulation duration in seconds<br>Timestep for each step<br>The control for using the MIMO form<br>Control parameters for each specific method |
| Parameters |                                                       u (array)<br>fai (array)<br>U (array)<br>Fai (array)                                                       |                                                            The current control input<br>The current fai value<br>Control inputs during the simulation<br>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:  
- [x] CFDL
- [ ] FFDL
- [ ] PFDL

Currently developed models:
- [x] Simple SISO model 1 (Model1)
- [x] Simple MIMO model 1 (Model1)

Currently tested scenarios:
- [x] CFDL on Model1

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/shahind/MFAC",
    "name": "MFAC",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "MFAC,Control,Dynamic",
    "author": "Shahin Darvishpoor",
    "author_email": "Shahindarvishpoor@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d0/a2/2bedb51051d28627cf1eb43ee738d2ed0b9d18655aa5442dd060980b7bd1/MFAC-0.1.4.tar.gz",
    "platform": null,
    "description": "# MFAC\r\n<a><img align=\"right\" src=\"https://img.shields.io/github/license/shahind/MFAC\"/></a>\r\n<a><img align=\"right\" src=\"https://img.shields.io/pypi/v/MFAC\"/></a>\r\n<a><img align=\"right\" src=\"https://img.shields.io/pypi/pyversions/MFAC\"/></a>\r\n<a><img align=\"right\" src=\"https://img.shields.io/github/languages/code-size/shahind/MFAC?color=blueviolet\"/></a>\r\n<p align=\"center\">\r\n  <img src=\"https://github.com/shahind/MFAC/raw/main/logo.png\" />\r\n</p>\r\nModel Free Adaptive Control Toolbox for Python\r\n\r\nThis 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.\r\n\r\n## Installation\r\nYou can easily install MFAC Toolbox from PyPI:\r\n```\r\npip install MFAC\r\n```\r\n\r\n## Simple Example\r\nThe following code shows the functionality of MFAC Toolbox in controlling a simple SISO system using CFDL method from (`\\examples\\siso_cfdl_simple.py`):\r\n\r\n```python\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nfrom mfac.plants.siso import Model1\r\nfrom mfac.controllers import CompactFormDynamicLinearization\r\n\r\n# define the model and set the initial values\r\nmodel = Model1(initial_state=np.array([0]))\r\n\r\n# Simulation conditions\r\ntotal_time = 8\r\nstep_time = 0.01\r\n\r\n# Desired output (y_desire)\r\ny_d = np.zeros(int(total_time / step_time) + 1)\r\nfor k in range(int(total_time / step_time) + 1):\r\n    y_d[k] = 0.5 + 0.5*np.power(-1, np.round(k/200))\r\n\r\n# log function which will be ran after each iteration\r\ndef log_function(cfdl):\r\n    print('iteration: ', cfdl.iteration)\r\n\r\n# define the controller\r\ncontroller = CompactFormDynamicLinearization(model=model,\r\n                                             iteration_function=log_function,\r\n                                             time_step=step_time,\r\n                                             reference_output=y_d,\r\n                                             simulation_time=total_time,\r\n                                             labda=1,\r\n                                             eta=1,\r\n                                             mu=1,\r\n                                             rho=0.45,\r\n                                             )\r\n\r\n# run the simulation\r\ncontroller.run()\r\n\r\n# plot the output\r\nfig, ax = plt.subplots()\r\nax.plot(model.Y)\r\nax.plot(y_d)\r\nax.set(xlabel='time (t)', ylabel='output (y)',\r\n       title='system output')\r\nax.grid()\r\n# fig.savefig(\"test.png\")\r\nplt.show()\r\n```\r\nthe output will be like:\r\n![img.png](img.png)\r\n\r\n# Components\r\nTo control a system using the current MFAC library, two major components are required; model and controller.\r\n## Model\r\nA model is simply a class with the following structure:\r\n\r\n|    Part    |                                                                            Variables/Methods                                                                            |                                                                                                                                                                                             Description                                                                                                                                                                                             |\r\n|:----------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|\r\n| Input      |                                                                          Initial_state (array)                                                                          |                                                                                                                                                                            Initial position of the plant in state space                                                                                                                                                                             |\r\n| Parameters | number_of_inputs (int)<br>number_of_states (int)<br>number_of_outputs (int)<br>x (array)<br>y (array)<br>u (array)<br>X (array)<br>Y (array)<br>U (array)<br>time (int) |       Number of control inputs<br>Number of state parameters<br>Number of outputs<br>The current state of the system<br>The current output of the system<br>Current input control of the system<br>States of the system during the simulation<br>Outputs of the system during the simulation<br>Controls of the system during the simulation<br>The current time of the simulation (discrete)       |\r\n| Functions  |                                                         reset()<br>step()<br>observe()<br>render()<br>predict()                                                         | Resets the plant for the next simulation<br>Gets the input controller and moves one step forward, returns the output<br>Observes the system's state or output variable defined by `full_state` input parameter<br>Renders the system based on input parameter `mode` which can be `print`, `plot`, or `visual`<br>Gets a series of inputs (k future steps) and predicts the systems state or output |\r\n\r\n## Controller\r\nA controller is simply a class with the following structure:\r\n\r\n|    Part    |                                                                        Variables/Methods                                                                         |                                                                                                                     Description                                                                                                                      |\r\n|:----------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|\r\n| Input      | model (Model)<br>iteration_function (Function)<br>reference_output (array)<br>simulation_time (int)<br>time_step (Float)<br>mimo (Boolean)<br>Control parameters | The plant to be controlled<br>The function which will be called in each step<br>The desired output<br>Simulation duration in seconds<br>Timestep for each step<br>The control for using the MIMO form<br>Control parameters for each specific method |\r\n| Parameters |                                                       u (array)<br>fai (array)<br>U (array)<br>Fai (array)                                                       |                                                            The current control input<br>The current fai value<br>Control inputs during the simulation<br>Fai values during the simulation                                                            |\r\n| 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                                     |\r\n\r\n\r\n# Development Status\r\nCurrently developed methods:  \r\n- [x] CFDL\r\n- [ ] FFDL\r\n- [ ] PFDL\r\n\r\nCurrently developed models:\r\n- [x] Simple SISO model 1 (Model1)\r\n- [x] Simple MIMO model 1 (Model1)\r\n\r\nCurrently tested scenarios:\r\n- [x] CFDL on Model1\r\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "Model Free Adaptive Control",
    "version": "0.1.4",
    "split_keywords": [
        "mfac",
        "control",
        "dynamic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "a13c76fdcb36aa5fe14d2fac5be58cf5",
                "sha256": "0ce31aa14cc68f206c5d15bdeaad311081bc711567c16e54a049251a1dc0e573"
            },
            "downloads": -1,
            "filename": "MFAC-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "a13c76fdcb36aa5fe14d2fac5be58cf5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15371,
            "upload_time": "2022-12-11T10:26:12",
            "upload_time_iso_8601": "2022-12-11T10:26:12.977300Z",
            "url": "https://files.pythonhosted.org/packages/d0/a2/2bedb51051d28627cf1eb43ee738d2ed0b9d18655aa5442dd060980b7bd1/MFAC-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-11 10:26:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "shahind",
    "github_project": "MFAC",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mfac"
}
        
Elapsed time: 0.04260s