simple_pendulum.controllers.lqr.roa

Submodules

simple_pendulum.controllers.lqr.roa.plot

simple_pendulum.controllers.lqr.roa.plot.get_ellipse_params(rho, M)

Returns ellipse params (excl center point)

simple_pendulum.controllers.lqr.roa.plot.get_ellipse_patch(px, py, rho, M, alpha_val=1, linec='red', facec='none', linest='solid')

return an ellipse patch

simple_pendulum.controllers.lqr.roa.plot.plot_ellipse(px, py, rho, M, save_to=None, show=True)

simple_pendulum.controllers.lqr.roa.sampling

simple_pendulum.controllers.lqr.roa.sampling.najafi_based_sampling(plant, controller, n=10000, rho0=100, M=None, x_star=array([3.14159265, 0.0]))

Estimate the RoA for the closed loop dynamics using the method introduced in Najafi, E., Babuška, R. & Lopes, G.A.D. A fast sampling method for estimating the domain of attraction. Nonlinear Dyn 86, 823–834 (2016). https://doi.org/10.1007/s11071-016-2926-7

Parameters:
plantsimple_pendulum.model.pendulum_plant

configured pendulum plant object

controllersimple_pendulum.controllers.lqr.lqr_controller

configured lqr controller object

nint, optional

number of samples, by default 100000

rho0int, optional

initial estimate of rho, by default 10

Mnp.array, optional

M, such that x_barT M x_bar is the Lyapunov fct. by default None, and controller.S is used

x_starnp.array, optional

nominal position (fixed point of the nonlinear dynamics)

Returns:
rhofloat

estimated value of rho

Mnp.array

M

simple_pendulum.controllers.lqr.roa.sos

simple_pendulum.controllers.lqr.roa.sos.SOSequalityConstrained(pendulum, controller)
Estimate the RoA for the closed loop dynamics using the method described by Russ Tedrake in “Underactuated Robotics: Algorithms for Walking, Running, Swimming, Flying, and Manipulation”,

Course Notes for MIT 6.832, 2022, “http://underactuated.mit.edu”, sec. 9.3.2: “The equality-constrained formulation”. This is discussed a bit more by Shen Shen and Russ Tedrake in “Sampling Quotient-Ring Sum-of-Squares Programs for Scalable Verification of Nonlinear Systems”, Proceedings of the 2020 59th IEEE Conference on Decision and Control (CDC) , 2020., http://groups.csail.mit.edu/robotics-center/public_papers/Shen20.pdf, pg. 2-3.

Parameters:
pendulumsimple_pendulum.model.pendulum_plant

configured pendulum plant object

controllersimple_pendulum.controllers.lqr.lqr_controller

configured lqr controller object

Returns:
rhofloat

estimated value of rho

Snp.array

S matrix from the lqr controller

simple_pendulum.controllers.lqr.roa.sos.SOSlineSearch(pendulum, controller)

Simple line search(bisection method) on rho that search for the maximum rho which satisfies the Lyapunov conditions in order to obtain an estimate of the RoA for the closed loop dynamics.

Parameters:
pendulumsimple_pendulum.model.pendulum_plant

configured pendulum plant object

controllersimple_pendulum.controllers.lqr.lqr_controller

configured lqr controller object

Returns:
rhofloat

estimated value of rho

Snp.array

S matrix from the lqr controller

simple_pendulum.controllers.lqr.roa.utils

class simple_pendulum.controllers.lqr.roa.utils.PendulumPlantApprox(mass=1.0, length=0.5, damping=0.1, gravity=9.81, coulomb_fric=0.0, inertia=None, torque_limit=inf, taylorApprox_order=1)

Bases: object

forward_dynamics(state, tau)

Computes forward dynamics

Parameters:
statearray like

len(state)=2 The state of the pendulum [angle, angular velocity] floats, units: rad, rad/s

taufloat

motor torque, unit: Nm

Returns:
  • float, angular acceleration, unit: rad/s^2
rhs(t, state, tau)

Computes the integrand of the equations of motion.

Parameters:
tfloat

time, not used (the dynamics of the pendulum are time independent)

statearray like

len(state)=2 The state of the pendulum [angle, angular velocity] floats, units: rad, rad/s

taufloat or array like

motor torque, unit: Nm

Returns:
resarray like

the integrand, contains [angular velocity, angular acceleration]

simple_pendulum.controllers.lqr.roa.utils.direct_sphere(d, r_i=0, r_o=1)

Direct Sampling from the d Ball based on Krauth, Werner. Statistical Mechanics: Algorithms and Computations. Oxford Master Series in Physics 13. Oxford: Oxford University Press, 2006. page 42

Parameters:
dint

dimension of the ball

r_iint, optional

inner radius, by default 0

r_oint, optional

outer radius, by default 1

Returns:
np.array

random vector directly sampled from the solid d Ball

simple_pendulum.controllers.lqr.roa.utils.quad_form(M, x)

Helper function to compute quadratic forms such as x^TMx

simple_pendulum.controllers.lqr.roa.utils.rhoVerification(rho, pendulum, controller)
SOS Verification of the Lyapunov conditions for a given rho in order to obtain an estimate of the RoA for the closed loop dynamics.

This method is described by Russ Tedrake in “Underactuated Robotics: Algorithms for Walking, Running, Swimming, Flying, and Manipulation”, Course Notes for MIT 6.832, 2022, “http://underactuated.mit.edu”, sec. 9.3.2: “Basic region of attraction formulation”.

Parameters:
rho: float

value of rho to be verified

pendulumsimple_pendulum.model.pendulum_plant

configured pendulum plant object

controllersimple_pendulum.controllers.lqr.lqr_controller

configured lqr controller object

Returns:
resultboolean

result of the verification

simple_pendulum.controllers.lqr.roa.utils.sample_from_ellipsoid(M, rho, r_i=0, r_o=1)

sample directly from the ellipsoid defined by xT M x.

Parameters:
Mnp.array

Matrix M such that xT M x leq rho defines the hyperellipsoid to sample from

rhofloat

rho such that xT M x leq rho defines the hyperellipsoid to sample from

r_iint, optional

inner radius, by default 0

r_oint, optional

outer radius, by default 1

Returns:
np.array

random vector from within the hyperellipsoid

simple_pendulum.controllers.lqr.roa.utils.vol_ellipsoid(rho, M)

Calculate the Volume of a Hyperellipsoid Volume of the Hyperllipsoid according to https://math.stackexchange.com/questions/332391/volume-of-hyperellipsoid/332434 Intuition: https://textbooks.math.gatech.edu/ila/determinants-volumes.html Volume of n-Ball https://en.wikipedia.org/wiki/Volume_of_an_n-ball