backstepping-controller


Namebackstepping-controller JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttps://github.com/sof-danny/backstepping_controller
SummaryA package for developing backstopping controller for linear and nonlinear systems.
upload_time2024-08-12 06:59:16
maintainerNone
docs_urlNone
authorSamuel O. Folorunsho
requires_python>=3.6
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Backstepping Controller

A Python package for developing controllers for control affine systems using backstepping control laws. This package provides a flexible and easy-to-use interface for designing, simulating, and analyzing control systems with options for trajectory tracking, plotting, and saving results.  


## Introduction to Backstepping Control

Backstepping is a systematic and recursive control design technique primarily used for stabilizing nonlinear systems. Unlike traditional control methods that might struggle with complex nonlinearities, backstepping breaks down the control problem into smaller, more manageable sub-problems. These sub-problems are then solved sequentially, "stepping back" from the output to the input, hence the name "backstepping."

Key Concepts:
Virtual Control: Intermediate control laws are designed for each state, leading to the final control input.
Lyapunov Function: A mathematical function that helps ensure system stability. Backstepping uses this function to guide the control design process.
Recursive Design: The control input is designed by recursively stabilizing each state in the system.

Worked examples can be found in [this paper]( https://doi.org/10.1016/B978-0-12-817582-8.00008-8).
 


## Installation

To install the package, simply run:

```bash
pip install backstepping_controller
```

## Usage

1. Importing the Package
To use the package, import the necessary functions:

```bash
import sympy as sp
import numpy as np
```

```bash
from backstepping_controller import generic_backstepping_controller, simulate_system, plot_responses, save_responses
```

2. Defining the System
First, you need to define your system's state equations and parameters. For example, if you have a 3D system:


# Define system parameters
```bash
num_states = 3

x1, x2, x3 = sp.symbols('x1 x2 x3') #states
u = sp.Symbol('u') #input
a, b, c = sp.symbols('a b c') #known parameters

# Define the state equations for a 3D system
state_equations = [
    a * x1 + x2,
    b * x2 + x3,
    c * x3 + u
]

# Define the gains
gains_vals = [10.0, 10.0, 15.0] #can modify to change system's response(typically higher values , faster response (but more expensive)
```

3. Creating the Control Law
Use the `generic_backstepping_controller` function to create the control law for your system:

```bash 
final_control_law, states, gains = generic_backstepping_controller(num_states, state_equations, 'u', gains_vals, tracking=False)
```

If you want to include trajectory tracking, you can enable the tracking parameter:

```bash 
final_control_law, states, gains, refs, errors = generic_backstepping_controller(num_states, state_equations, 'u', gains_vals, tracking=True)
```

4. Simulating the System
Simulate the system using the `simulate_system` function. You can configure it to print the control law, plot the results (states, inputs), and save the responses as a .json file:

```bash 
# Simulation parameters
time = np.linspace(0, 10, 1000)  # 10 seconds of simulation with 1000 time steps
initial_conditions = [0.1, 0.0, 0.1]  # Initial conditions for x1, x2, x3, you can change this since region of attraction is the entire R^n. 
params_subs = {a: 1.0, b: 0.5, c: 0.2, 'k1': gains_vals[0], 'k2': gains_vals[1], 'k3': gains_vals[2]} #can change parameter values based on system

# Simulate the system
state_values, control_inputs = simulate_system(
    final_control_law, states, gains_vals, initial_conditions, time, state_equations, params_subs, 
    plot=True, save_path='results.json', print_law=True) #You can change plot to `False` if you dont want to see the plots yet
```

5. Plotting the Results
If you haven't plotted the results directly in the simulation, you can use the `plot_responses` function to plot the states and control inputs on separate plots:

```bash 
plot_responses(time, state_values, control_inputs)
```

6. Saving the Results
The results can be saved to a JSON file for later analysis. The simulate_system function allows you to save the results directly during the simulation by specifying the save_path:

```bash
simulate_system(final_control_law, states, gains_vals, initial_conditions, time, state_equations, params_subs, save_path='results.json')
```

Alternatively, you can save the results after the simulation using the `save_responses` function:

```bash
save_responses('results.json', time, state_values, control_inputs)
```

Example: Full Workflow
Here's a complete example that ties everything together:

```bash

import numpy as np
import sympy as sp
from backstepping_controller import generic_backstepping_controller, simulate_system, plot_responses, save_responses

# Define system parameters
num_states = 3
x1, x2, x3 = sp.symbols('x1 x2 x3')
u = sp.Symbol('u')
a, b, c = sp.symbols('a b c')

# Define the state equations for a 3D system
state_equations = [
    a * x1 + x2,
    b * x2 + x3,
    c * x3 + u
]

# Define the gains
gains_vals = [10.0, 10.0, 15.0]

# Create the control law
final_control_law, states, gains = generic_backstepping_controller(num_states, state_equations, 'u', gains_vals, tracking=False)

# Simulation parameters
time = np.linspace(0, 10, 1000)  # 10 seconds of simulation with 1000 time steps
initial_conditions = [0.1, 0.0, 0.1]  # Initial conditions for x1, x2, x3
params_subs = {a: 1.0, b: 0.5, c: 0.2, 'k1': gains_vals[0], 'k2': gains_vals[1], 'k3': gains_vals[2]}

# Simulate the system
state_values, control_inputs = simulate_system(
    final_control_law, states, gains_vals, initial_conditions, time, state_equations, params_subs, 
    plot=True, save_path='results.json', print_law=True
)

# Optional: Plot and save the results separately
plot_responses(time, state_values, control_inputs)
save_responses('results.json', time, state_values, control_inputs)
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sof-danny/backstepping_controller",
    "name": "backstepping-controller",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Samuel O. Folorunsho",
    "author_email": "folorunshosamuel001@gmail.com",
    "download_url": null,
    "platform": null,
    "description": "# Backstepping Controller\n\nA Python package for developing controllers for control affine systems using backstepping control laws. This package provides a flexible and easy-to-use interface for designing, simulating, and analyzing control systems with options for trajectory tracking, plotting, and saving results.  \n\n\n## Introduction to Backstepping Control\n\nBackstepping is a systematic and recursive control design technique primarily used for stabilizing nonlinear systems. Unlike traditional control methods that might struggle with complex nonlinearities, backstepping breaks down the control problem into smaller, more manageable sub-problems. These sub-problems are then solved sequentially, \"stepping back\" from the output to the input, hence the name \"backstepping.\"\n\nKey Concepts:\nVirtual Control: Intermediate control laws are designed for each state, leading to the final control input.\nLyapunov Function: A mathematical function that helps ensure system stability. Backstepping uses this function to guide the control design process.\nRecursive Design: The control input is designed by recursively stabilizing each state in the system.\n\nWorked examples can be found in [this paper]( https://doi.org/10.1016/B978-0-12-817582-8.00008-8).\n \n\n\n## Installation\n\nTo install the package, simply run:\n\n```bash\npip install backstepping_controller\n```\n\n## Usage\n\n1. Importing the Package\nTo use the package, import the necessary functions:\n\n```bash\nimport sympy as sp\nimport numpy as np\n```\n\n```bash\nfrom backstepping_controller import generic_backstepping_controller, simulate_system, plot_responses, save_responses\n```\n\n2. Defining the System\nFirst, you need to define your system's state equations and parameters. For example, if you have a 3D system:\n\n\n# Define system parameters\n```bash\nnum_states = 3\n\nx1, x2, x3 = sp.symbols('x1 x2 x3') #states\nu = sp.Symbol('u') #input\na, b, c = sp.symbols('a b c') #known parameters\n\n# Define the state equations for a 3D system\nstate_equations = [\n    a * x1 + x2,\n    b * x2 + x3,\n    c * x3 + u\n]\n\n# Define the gains\ngains_vals = [10.0, 10.0, 15.0] #can modify to change system's response(typically higher values , faster response (but more expensive)\n```\n\n3. Creating the Control Law\nUse the `generic_backstepping_controller` function to create the control law for your system:\n\n```bash \nfinal_control_law, states, gains = generic_backstepping_controller(num_states, state_equations, 'u', gains_vals, tracking=False)\n```\n\nIf you want to include trajectory tracking, you can enable the tracking parameter:\n\n```bash \nfinal_control_law, states, gains, refs, errors = generic_backstepping_controller(num_states, state_equations, 'u', gains_vals, tracking=True)\n```\n\n4. Simulating the System\nSimulate the system using the `simulate_system` function. You can configure it to print the control law, plot the results (states, inputs), and save the responses as a .json file:\n\n```bash \n# Simulation parameters\ntime = np.linspace(0, 10, 1000)  # 10 seconds of simulation with 1000 time steps\ninitial_conditions = [0.1, 0.0, 0.1]  # Initial conditions for x1, x2, x3, you can change this since region of attraction is the entire R^n. \nparams_subs = {a: 1.0, b: 0.5, c: 0.2, 'k1': gains_vals[0], 'k2': gains_vals[1], 'k3': gains_vals[2]} #can change parameter values based on system\n\n# Simulate the system\nstate_values, control_inputs = simulate_system(\n    final_control_law, states, gains_vals, initial_conditions, time, state_equations, params_subs, \n    plot=True, save_path='results.json', print_law=True) #You can change plot to `False` if you dont want to see the plots yet\n```\n\n5. Plotting the Results\nIf you haven't plotted the results directly in the simulation, you can use the `plot_responses` function to plot the states and control inputs on separate plots:\n\n```bash \nplot_responses(time, state_values, control_inputs)\n```\n\n6. Saving the Results\nThe results can be saved to a JSON file for later analysis. The simulate_system function allows you to save the results directly during the simulation by specifying the save_path:\n\n```bash\nsimulate_system(final_control_law, states, gains_vals, initial_conditions, time, state_equations, params_subs, save_path='results.json')\n```\n\nAlternatively, you can save the results after the simulation using the `save_responses` function:\n\n```bash\nsave_responses('results.json', time, state_values, control_inputs)\n```\n\nExample: Full Workflow\nHere's a complete example that ties everything together:\n\n```bash\n\nimport numpy as np\nimport sympy as sp\nfrom backstepping_controller import generic_backstepping_controller, simulate_system, plot_responses, save_responses\n\n# Define system parameters\nnum_states = 3\nx1, x2, x3 = sp.symbols('x1 x2 x3')\nu = sp.Symbol('u')\na, b, c = sp.symbols('a b c')\n\n# Define the state equations for a 3D system\nstate_equations = [\n    a * x1 + x2,\n    b * x2 + x3,\n    c * x3 + u\n]\n\n# Define the gains\ngains_vals = [10.0, 10.0, 15.0]\n\n# Create the control law\nfinal_control_law, states, gains = generic_backstepping_controller(num_states, state_equations, 'u', gains_vals, tracking=False)\n\n# Simulation parameters\ntime = np.linspace(0, 10, 1000)  # 10 seconds of simulation with 1000 time steps\ninitial_conditions = [0.1, 0.0, 0.1]  # Initial conditions for x1, x2, x3\nparams_subs = {a: 1.0, b: 0.5, c: 0.2, 'k1': gains_vals[0], 'k2': gains_vals[1], 'k3': gains_vals[2]}\n\n# Simulate the system\nstate_values, control_inputs = simulate_system(\n    final_control_law, states, gains_vals, initial_conditions, time, state_equations, params_subs, \n    plot=True, save_path='results.json', print_law=True\n)\n\n# Optional: Plot and save the results separately\nplot_responses(time, state_values, control_inputs)\nsave_responses('results.json', time, state_values, control_inputs)\n```\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A package for developing backstopping controller for linear and nonlinear \t\tsystems.",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/sof-danny/backstepping_controller"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ddb5298970fdad6557ffdda2c0d3a8312141d4e1c0f819f464c55b8ef1ee990e",
                "md5": "528e98cad6f3d4f3a328ce0ac4772144",
                "sha256": "cd75d9c3e505e9f033d661d3d67eaa10a26e30c276833103dd638feef78f14f2"
            },
            "downloads": -1,
            "filename": "backstepping_controller-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "528e98cad6f3d4f3a328ce0ac4772144",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7216,
            "upload_time": "2024-08-12T06:59:16",
            "upload_time_iso_8601": "2024-08-12T06:59:16.562418Z",
            "url": "https://files.pythonhosted.org/packages/dd/b5/298970fdad6557ffdda2c0d3a8312141d4e1c0f819f464c55b8ef1ee990e/backstepping_controller-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-12 06:59:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sof-danny",
    "github_project": "backstepping_controller",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "backstepping-controller"
}
        
Elapsed time: 0.31676s