8000 Add gain scheduling to create_statefbk_iosystem() by murrayrm · Pull Request #827 · python-control/python-control · GitHub
[go: up one dir, main page]

Skip to content

Add gain scheduling to create_statefbk_iosystem() #827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 30, 2022

Conversation

murrayrm
Copy link
Member

This PR adds functionality to the create_statefbk_iosystem function, allowing it to be used to set up a simple gain scheduled controller. From the documentation:

Gain scheduling on the desired state, desired input, or system state can be implemented by setting the gain to a 2-tuple consisting of a list of gains and a list of points at which the gains
were computed, as well as a description of the scheduling variables

  ctrl, clsys = ct.create_statefbk_iosystem(
      sys, ([g1, ..., gN], [p1, ..., pN]), gainsched_indices=[s1, ..., sq])

The list of indices can either be integers indicating the offset into the controller input vector or a list of strings matching the names of the input signals.

Example:

    # Create a simple nonlinear system to check (kinematic car)
    def unicycle_update(t, x, u, params):
        return np.array([np.cos(x[2]) * u[0], np.sin(x[2]) * u[0], u[1]])

    def unicycle_output(t, x, u, params):
        return x

    unicycle = ct.NonlinearIOSystem(
        unicycle_update, unicycle_output, inputs = ['v', 'phi'], 
        outputs = ['x', 'y', 'theta'], states = ['x_', 'y_', 'theta_'])

    # Speeds and angles at which to compute the gains
    speeds = [1, 5, 10]
    angles = np.linspace(0, pi/2, 4)
    points = list(itertools.product(speeds, angles))

    # Gains for each speed (using LQR controller)
    Q = np.identity(unicycle.nstates)
    R = np.identity(unicycle.ninputs)
    gains = [np.array(ct.lqr(unicycle.linearize(
        [0, 0, angle], [speed, 0]), Q, R)[0]) for speed, angle in points]

    #
    # Schedule on desired speed and angle
    #

    # Create gain scheduled controller
    ctrl, clsys = ct.create_statefbk_iosystem(
        unicycle, (gains, points), gainsched_indices=['vd', 'theta'])

Includes unit tests and documentation.

@murrayrm murrayrm added this to the 0.9.3 milestone Dec 29, 2022
@coveralls
Copy link
coveralls commented Dec 29, 2022

Coverage Status

Coverage: 94.845% (-0.002%) from 94.846% when pulling 51f3b6b on murrayrm:gainsched-23Dec2022 into 49b0077 on python-control:main.

@murrayrm murrayrm merged commit c3488cd into python-control:main Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0