GeezerVison is showing github.com — Add gain scheduling to create_statefbk_iosystem() by murrayrm · Pull Request #827 · python-control/python-control
Conversation
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coveralls
commented
Dec 29, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Coverage: 94.845% (-0.002%) from 94.846% when pulling 51f3b6b on murrayrm:gainsched-23Dec2022 into 49b0077 on python-control:main.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|