cpsim.controllers package

Submodules

cpsim.controllers.LP_cvxpy module

class cpsim.controllers.LP_cvxpy.LP(param_dict: dict)[source]

Bases: Controller

formulate()[source]

x = | x0, x1, …, xN, u0, u1, …, u{N-1} | Aeq leq (1-D)

-I | | -x0 |
Ad -I Bd | | |
Ad -I Bd | | |
… … | | |
Ad -I Bd | | |
formulate_only_x0()[source]
get_full_ctrl()[source]

Only call after self.update to get full utils input sequence u0,…,u{N-1}

get_last_x()[source]

Only call after self.update to get last system state xN for debug

ready_to_formulate()[source]
set_control_limit(control_lo: ndarray, control_up: ndarray)[source]
set_reference(ref: ndarray)[source]
set_solver(solver)[source]
update(feedback_value: ndarray, current_time=None)[source]
update_ddl(ddl: int | None)[source]
update_horizon(N: int)[source]
update_model(Ad: ndarray, Bd: ndarray)[source]
update_model_residual(cd: ndarray)[source]
update_params(**kwargs)[source]

parameter template: lp_settings = {

‘Ad’: , ‘Bd’: , ‘N’: , ‘ddl’: , ‘target_lo’: , ‘target_up’: , ‘safe_lo’: , ‘safe_up’: , ‘control_lo’: , ‘control_up’: , ‘ref’:

}

update_safe_set(safe_lo: ndarray, safe_up: ndarray)[source]
update_target_set(target_lo: ndarray, target_up: ndarray)[source]

cpsim.controllers.LQR module

class cpsim.controllers.LQR.LQR(A: ndarray, B: ndarray, Q: ndarray, R: ndarray)[source]

Bases: Controller

set_control_limit(control_lo: ndarray, control_up: ndarray)[source]
set_reference(ref: ndarray)[source]
update(feedback_value: ndarray, current_time=None) ndarray[source]
update_gain(A: ndarray, B: ndarray, Q: ndarray, R: ndarray)[source]

cpsim.controllers.LQRSSE module

class cpsim.controllers.LQRSSE.LQRSSE(A: ndarray, B: ndarray, Q: ndarray, R: ndarray)[source]

Bases: Controller

compute_Nbar(A: ndarray, B: ndarray, C: ndarray, D: ndarray)[source]
set_control_limit(control_lo: ndarray, control_up: ndarray)[source]
set_reference(ref: ndarray)[source]
update(feedback_value: ndarray, current_time=None) ndarray[source]
update_gain(A: ndarray, B: ndarray, Q: ndarray, R: ndarray)[source]

cpsim.controllers.MPC_OSQP module

class cpsim.controllers.MPC_OSQP.MPC(param_dict: dict)[source]

Bases: Controller

formulate()[source]

x = | x0, x1, …, xN, u0, u1, …, u{N-1} | Aeq leq (1-D)

-I | | -x0 |
Ad -I Bd | | |
Ad -I Bd | | |
… … | | |
Ad -I Bd | | |
formulate_only_x0()[source]
ready_to_formulate()[source]
set_control_limit(control_lo: ndarray, control_up: ndarray)[source]
set_reference(ref: ndarray)[source]
update(feedback_value: ndarray, current_time=None)[source]
update_ddl(ddl: int | None)[source]
update_horizon(N: int)[source]
update_model(Ad: ndarray, Bd: ndarray)[source]
update_object(Q: ndarray, QN: ndarray, R: ndarray)[source]
update_params(**kwargs)[source]

parameter template: mpc_settings = {

‘Ad’: , ‘Bd’: , ‘Q’: , ‘QN’:, ‘R’:, ‘N’: , ‘ddl’: , ‘target_lo’: , ‘target_up’: , ‘safe_lo’: , ‘safe_up’: , ‘control_lo’: , ‘control_up’: , ‘ref’:

}

update_safe_set(safe_lo: ndarray, safe_up: ndarray)[source]
update_target_set(target_lo: ndarray, target_up: ndarray)[source]

cpsim.controllers.MPC_cvxpy module

class cpsim.controllers.MPC_cvxpy.MPC(param_dict: dict)[source]

Bases: Controller

formulate()[source]

x = | x0, x1, …, xN, u0, u1, …, u{N-1} | Aeq leq (1-D)

-I | | -x0 |
Ad -I Bd | | -c |
Ad -I Bd | | -c |
… … | | -c |
Ad -I Bd | | -c |
formulate_only_x0()[source]
get_full_ctrl()[source]

Only call after self.update to get full utils input sequence u0,…,u{N-1}

get_last_x()[source]

Only call after self.update to get last system state xN for debug

ready_to_formulate()[source]
set_control_limit(control_lo: ndarray, control_up: ndarray)[source]
set_reference(ref: ndarray)[source]
update(feedback_value: ndarray, current_time=None)[source]
update_ddl(ddl: int | None)[source]
update_horizon(N: int)[source]
update_model(Ad: ndarray, Bd: ndarray)[source]
update_model_residual(cd: ndarray)[source]
update_object(Q: ndarray, QN: ndarray, R: ndarray)[source]
update_params(**kwargs)[source]

parameter template: mpc_settings = {

‘Ad’: , ‘Bd’: , ‘Q’: , ‘QN’:, ‘R’:, ‘N’: , ‘ddl’: , ‘target_lo’: , ‘target_up’: , ‘safe_lo’: , ‘safe_up’: , ‘control_lo’: , ‘control_up’: , ‘ref’:

}

update_safe_set(safe_lo: ndarray, safe_up: ndarray)[source]
update_target_set(target_lo: ndarray, target_up: ndarray)[source]

cpsim.controllers.PID module

Ivmech PID Controller is simple implementation of a Proportional-Integral-Derivative (PID) Controller in the Python Programming Language. More information about PID Controller: http://en.wikipedia.org/wiki/PID_controller

class cpsim.controllers.PID.PID(P=0.2, I=0.0, D=0.0, current_time=None)[source]

Bases: Controller

PID Controller

clear(current_time=None)[source]

Clears PID computations and coefficients

setKd(derivative_gain)[source]

Determines how aggressively the PID reacts to the current error with setting Derivative Gain

setKi(integral_gain)[source]

Determines how aggressively the PID reacts to the current error with setting Integral Gain

setKp(proportional_gain)[source]

Determines how aggressively the PID reacts to the current error with setting Proportional Gain

setSampleTime(sample_time)[source]

PID that should be updated at a regular interval. Based on a pre-determined sampe time, the PID decides if it should compute or return immediately.

setWindup(windup)[source]

Integral windup, also known as integrator windup or reset windup, refers to the situation in a PID feedback controller where a large change in setpoint occurs (say a positive change) and the integral terms accumulates a significant error during the rise (windup), thus overshooting and continuing to increase as this accumulated error is unwound (offset by errors in the other direction). The specific problem is the excess overshooting.

set_control_limit(control_lo: float, control_up: float)[source]
set_reference(ref: float)[source]
update(feedback_value: float, current_time=None) float[source]

Calculates PID value for given reference feedback

\[u(t) = K_p e(t) + K_i \int_{0}^{t} e(t)dt + K_d {de}/{dt}\]
apidoc/images/pid_1.png

Test PID with Kp=1.2, Ki=1, Kd=0.001 (test_pid.py)

cpsim.controllers.PID_incremental module

Ivmech PID Controller is simple implementation of a Proportional-Integral-Derivative (PID) Controller in the Python Programming Language. More information about PID Controller: http://en.wikipedia.org/wiki/PID_controller

class cpsim.controllers.PID_incremental.PID(u_0, P=0.2, I=0.0, D=0.0, current_time=None)[source]

Bases: Controller

PID Controller

clear(current_time=None)[source]

Clears PID computations and coefficients

setKd(derivative_gain)[source]

Determines how aggressively the PID reacts to the current error with setting Derivative Gain

setKi(integral_gain)[source]

Determines how aggressively the PID reacts to the current error with setting Integral Gain

setKp(proportional_gain)[source]

Determines how aggressively the PID reacts to the current error with setting Proportional Gain

setSampleTime(sample_time)[source]

PID that should be updated at a regular interval. Based on a pre-determined sampe time, the PID decides if it should compute or return immediately.

setWindup(windup)[source]

Integral windup, also known as integrator windup or reset windup, refers to the situation in a PID feedback controller where a large change in setpoint occurs (say a positive change) and the integral terms accumulates a significant error during the rise (windup), thus overshooting and continuing to increase as this accumulated error is unwound (offset by errors in the other direction). The specific problem is the excess overshooting.

set_control_limit(control_lo: float, control_up: float)[source]
set_reference(ref: float)[source]
update(feedback_value: float, current_time=None) float[source]

Calculates PID value for given reference feedback

\[u(t) = K_p e(t) + K_i \int_{0}^{t} e(t)dt + K_d {de}/{dt}\]
apidoc/images/pid_1.png

Test PID with Kp=1.2, Ki=1, Kd=0.001 (test_pid.py)

cpsim.controllers.controller_base module

class cpsim.controllers.controller_base.Controller[source]

Bases: ABC

clear()[source]
abstract set_control_limit(control_lo, control_up)[source]
abstract set_reference(ref)[source]
abstract update(feedback_value, current_time=None)[source]

Module contents