Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit394e1c2

Browse files
authored
Merge pull request#1135 from roryyorke/rory/lint-examples
Lint fixes on benchmarks and examples/*.py
2 parentsad996f9 +5653531 commit394e1c2

17 files changed

+53
-76
lines changed

‎benchmarks/flatsys_bench.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
importnumpyasnp
99
importmath
10-
importcontrolasct
1110
importcontrol.flatsysasflat
1211
importcontrol.optimalasopt
1312

‎benchmarks/optestim_bench.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# used for optimization-based estimation.
77

88
importnumpyasnp
9-
importmath
109
importcontrolasct
1110
importcontrol.optimalasopt
1211

‎benchmarks/optimal_bench.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# performance of the functions used for optimization-base control.
77

88
importnumpyasnp
9-
importmath
109
importcontrolasct
1110
importcontrol.flatsysasfs
1211
importcontrol.optimalasopt
@@ -21,7 +20,6 @@
2120
'RK23': ('RK23', {}),
2221
'RK23_sloppy': ('RK23', {'atol':1e-4,'rtol':1e-2}),
2322
'RK45': ('RK45', {}),
24-
'RK45': ('RK45', {}),
2523
'RK45_sloppy': ('RK45', {'atol':1e-4,'rtol':1e-2}),
2624
'LSODA': ('LSODA', {}),
2725
}
@@ -129,9 +127,6 @@ def time_optimal_lq_methods(integrator_name, minimizer_name, method):
129127
Tf=10
130128
timepts=np.linspace(0,Tf,20)
131129

132-
# Create the basis function to use
133-
basis=get_basis('poly',12,Tf)
134-
135130
res=opt.solve_ocp(
136131
sys,timepts,x0,traj_cost,constraints,terminal_cost=term_cost,
137132
solve_ivp_method=integrator[0],solve_ivp_kwargs=integrator[1],
@@ -223,8 +218,6 @@ def time_discrete_aircraft_mpc(minimizer_name):
223218
# compute the steady state values for a particular value of the input
224219
ud=np.array([0.8,-0.3])
225220
xd=np.linalg.inv(np.eye(5)-A) @B @ud
226-
yd=C @xd
227-
228221
# provide constraints on the system signals
229222
constraints= [opt.input_range_constraint(sys, [-5,-6], [5,6])]
230223

@@ -234,7 +227,6 @@ def time_discrete_aircraft_mpc(minimizer_name):
234227
cost=opt.quadratic_cost(model,Q,R,x0=xd,u0=ud)
235228

236229
# Set the time horizon and time points
237-
Tf=3
238230
timepts=np.arange(0,6)*0.2
239231

240232
# Get the minimizer parameters to use

‎examples/bdalg-matlab.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# bdalg-matlab.py - demonstrate some MATLAB commands for block diagramaltebra
1+
# bdalg-matlab.py - demonstrate some MATLAB commands for block diagramalgebra
22
# RMM, 29 May 09
33

4-
fromcontrol.matlabimport*# MATLAB-like functions
4+
fromcontrol.matlabimportss,ss2tf,tf,tf2ss# MATLAB-like functions
55

66
# System matrices
77
A1= [[0,1.], [-4,-1]]

‎examples/check-controllability-and-observability.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
RMM, 6 Sep 2010
55
"""
66

7-
importnumpyasnp# Load thescipy functions
8-
fromcontrol.matlabimport*# Load the controls systems library
7+
importnumpyasnp# Load thenumpy functions
8+
fromcontrol.matlabimportss,ctrb,obsv# Load the controls systems library
99

1010
# Parameters defining the system
1111

‎examples/cruise-control.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ def pi_update(t, x, u, params={}):
247247
# Assign variables for inputs and states (for readability)
248248
v=u[0]# current velocity
249249
vref=u[1]# reference velocity
250-
z=x[0]# integrated error
251250

252251
# Compute the nominal controller output (needed for anti-windup)
253252
u_a=pi_output(t,x,u,params)
@@ -394,7 +393,7 @@ def sf_output(t, z, u, params={}):
394393
ud=params.get('ud',0)
395394

396395
# Get the system state and reference input
397-
x,y,r=u[0],u[1],u[2]
396+
x,r=u[0],u[2]
398397

399398
returnud-K* (x-xd)-ki*z+kf* (r-yd)
400399

@@ -440,13 +439,13 @@ def sf_output(t, z, u, params={}):
440439
4./180.*pifortinT]
441440
t,y=ct.input_output_response(
442441
cruise_sf,T, [vref,gear,theta_hill], [X0[0],0],
443-
params={'K':K,'kf':kf,'ki':0.0,'kf':kf,'xd':xd,'ud':ud,'yd':yd})
442+
params={'K':K,'kf':kf,'ki':0.0,'xd':xd,'ud':ud,'yd':yd})
444443
subplots=cruise_plot(cruise_sf,t,y,label='Proportional',linetype='b--')
445444

446445
# Response of the system with state feedback + integral action
447446
t,y=ct.input_output_response(
448447
cruise_sf,T, [vref,gear,theta_hill], [X0[0],0],
449-
params={'K':K,'kf':kf,'ki':0.1,'kf':kf,'xd':xd,'ud':ud,'yd':yd})
448+
params={'K':K,'kf':kf,'ki':0.1,'xd':xd,'ud':ud,'yd':yd})
450449
cruise_plot(cruise_sf,t,y,label='PI control',t_hill=8,linetype='b-',
451450
subplots=subplots,legend=True)
452451

‎examples/kincar.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
importnumpyasnp
55
importmatplotlib.pyplotasplt
6-
importcontrolasct
76
importcontrol.flatsysasfs
87

98
#

‎examples/mrac_siso_mit.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def adaptive_controller_state(t, xc, uc, params):
4646
# Parameters
4747
gam=params["gam"]
4848
Am=params["Am"]
49-
Bm=params["Bm"]
5049
signB=params["signB"]
5150

5251
# Controller inputs

‎examples/phase_plane_plots.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
# using the phaseplot module. Most of these figures line up with examples
66
# in FBS2e, with different display options shown as different subplots.
77

8-
importtime
98
importwarnings
10-
frommathimportpi,sqrt
9+
frommathimportpi
1110

1211
importmatplotlib.pyplotasplt
1312
importnumpyasnp

‎examples/pvtol-nested-ss.py‎

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
importos
1212
importmatplotlib.pyplotasplt# MATLAB plotting functions
13-
fromcontrol.matlabimport*# MATLAB-like functions
1413
importnumpyasnp
1514
importmath
1615
importcontrolasct
@@ -23,12 +22,12 @@
2322
c=0.05# damping factor (estimated)
2423

2524
# Transfer functions for dynamics
26-
Pi=tf([r], [J,0,0])# inner loop (roll)
27-
Po=tf([1], [m,c,0])# outer loop (position)
25+
Pi=ct.tf([r], [J,0,0])# inner loop (roll)
26+
Po=ct.tf([1], [m,c,0])# outer loop (position)
2827

2928
# Use state space versions
30-
Pi=tf2ss(Pi)
31-
Po=tf2ss(Po)
29+
Pi=ct.tf2ss(Pi)
30+
Po=ct.tf2ss(Po)
3231

3332
#
3433
# Inner loop control design
@@ -40,68 +39,68 @@
4039

4140
# Design a simple lead controller for the system
4241
k,a,b=200,2,50
43-
Ci=k*tf([1,a], [1,b])# lead compensator
42+
Ci=k*ct.tf([1,a], [1,b])# lead compensator
4443

4544
# Convert to statespace
46-
Ci=tf2ss(Ci)
45+
Ci=ct.tf2ss(Ci)
4746

4847
# Compute the loop transfer function for the inner loop
4948
Li=Pi*Ci
5049

5150

5251
# Bode plot for the open loop process
5352
plt.figure(1)
54-
bode(Pi)
53+
ct.bode(Pi)
5554

5655
# Bode plot for the loop transfer function, with margins
5756
plt.figure(2)
58-
bode(Li)
57+
ct.bode(Li)
5958

6059
# Compute out the gain and phase margins
6160
#! Not implemented
6261
# (gm, pm, wcg, wcp) = margin(Li);
6362

6463
# Compute the sensitivity and complementary sensitivity functions
65-
Si=feedback(1,Li)
64+
Si=ct.feedback(1,Li)
6665
Ti=Li*Si
6766

6867
# Check to make sure that the specification is met
6968
plt.figure(3)
70-
gangof4(Pi,Ci)
69+
ct.gangof4(Pi,Ci)
7170

7271
# Compute out the actual transfer function from u1 to v1 (see L8.2 notes)
7372
# Hi = Ci*(1-m*g*Pi)/(1+Ci*Pi);
74-
Hi=parallel(feedback(Ci,Pi),-m*g*feedback(Ci*Pi,1))
73+
Hi=ct.parallel(ct.feedback(Ci,Pi),-m*g*ct.feedback(Ci*Pi,1))
7574

7675
plt.figure(4)
7776
plt.clf()
78-
bode(Hi)
77+
ct.bode(Hi)
7978

8079
# Now design the lateral control system
8180
a,b,K=0.02,5,2
82-
Co=-K*tf([1,0.3], [1,10])# another lead compensator
81+
Co=-K*ct.tf([1,0.3], [1,10])# another lead compensator
8382

8483
# Convert to statespace
85-
Co=tf2ss(Co)
84+
Co=ct.tf2ss(Co)
8685

8786
# Compute the loop transfer function for the outer loop
8887
Lo=-m*g*Po*Co
8988

9089
plt.figure(5)
91-
bode(Lo,display_margins=True)# margin(Lo)
90+
ct.bode(Lo,display_margins=True)# margin(Lo)
9291

9392
# Finally compute the real outer-loop loop gain + responses
9493
L=Co*Hi*Po
95-
S=feedback(1,L)
96-
T=feedback(L,1)
94+
S=ct.feedback(1,L)
95+
T=ct.feedback(L,1)
9796

9897
# Compute stability margins
9998
#! Not yet implemented
10099
# (gm, pm, wgc, wpc) = margin(L);
101100

102101
plt.figure(6)
103102
plt.clf()
104-
out=ct.bode(L,logspace(-4,3),initial_phase=-math.pi/2)
103+
out=ct.bode(L,np.logspace(-4,3),initial_phase=-math.pi/2)
105104
axs=ct.get_plot_axes(out)
106105

107106
# Add crossover line to magnitude plot
@@ -111,7 +110,7 @@
111110
# Nyquist plot for complete design
112111
#
113112
plt.figure(7)
114-
nyquist(L)
113+
ct.nyquist(L)
115114

116115
# set up the color
117116
color='b'
@@ -126,10 +125,10 @@
126125
# 'EdgeColor', color, 'FaceColor', color);
127126

128127
plt.figure(9)
129-
Yvec,Tvec=step(T,linspace(1,20))
128+
Yvec,Tvec=ct.step_response(T,np.linspace(1,20))
130129
plt.plot(Tvec.T,Yvec.T)
131130

132-
Yvec,Tvec=step(Co*S,linspace(1,20))
131+
Yvec,Tvec=ct.step_response(Co*S,np.linspace(1,20))
133132
plt.plot(Tvec.T,Yvec.T)
134133

135134
#TODO: PZmap for statespace systems has not yet been implemented.
@@ -142,7 +141,7 @@
142141
# Gang of Four
143142
plt.figure(11)
144143
plt.clf()
145-
gangof4(Hi*Po,Co,linspace(-2,3))
144+
ct.gangof4(Hi*Po,Co,np.linspace(-2,3))
146145

147146
if'PYCONTROL_TEST_EXAMPLES'notinos.environ:
148147
plt.show()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp