@@ -167,7 +167,22 @@ def test_nonlinear_iosys(self, tsys):
167
167
np .testing .assert_array_almost_equal (lti_t , ios_t )
168
168
np .testing .assert_allclose (lti_y , ios_y ,atol = 0.002 ,rtol = 0. )
169
169
170
- def test_linearize (self , tsys ):
170
+ @pytest .fixture
171
+ def kincar (self ):
172
+ # Create a simple nonlinear system to check (kinematic car)
173
+ def kincar_update (t , x , u , params ):
174
+ return np .array ([np .cos (x [2 ]) * u [0 ], np .sin (x [2 ]) * u [0 ], u [1 ]])
175
+
176
+ def kincar_output (t , x , u , params ):
177
+ return np .array ([x [0 ], x [1 ]])
178
+
179
+ return ios .NonlinearIOSystem (
180
+ kincar_update , kincar_output ,
181
+ inputs = ['v' , 'phi' ],
182
+ outputs = ['x' , 'y' ],
183
+ states = ['x' , 'y' , 'theta' ])
184
+
185
+ def test_linearize (self , tsys , kincar ):
171
186
# Create a single input/single output linear system
172
187
linsys = tsys .siso_linsys
173
188
iosys = ios .LinearIOSystem (linsys )
@@ -180,13 +195,7 @@ def test_linearize(self, tsys):
180
195
np .testing .assert_array_almost_equal (linsys .D , linearized .D )
181
196
182
197
# Create a simple nonlinear system to check (kinematic car)
183
- def kincar_update (t , x , u , params ):
184
- return np .array ([np .cos (x [2 ]) * u [0 ], np .sin (x [2 ]) * u [0 ], u [1 ]])
185
-
186
- def kincar_output (t , x , u , params ):
187
- return np .array ([x [0 ], x [1 ]])
188
-
189
- iosys = ios .NonlinearIOSystem (kincar_update , kincar_output )
198
+ iosys = kincar
190
199
linearized = iosys .linearize ([0 , 0 , 0 ], [0 , 0 ])
191
200
np .testing .assert_array_almost_equal (linearized .A , np .zeros ((3 ,3 )))
192
201
np .testing .assert_array_almost_equal (
@@ -196,6 +205,29 @@ def kincar_output(t, x, u, params):
196
205
np .testing .assert_array_almost_equal (linearized .D , np .zeros ((2 ,2 )))
197
206
198
207
208
+ def test_linearize_named_signals (self , kincar ):
209
+ # Full form of the call
210
+ linearized = kincar .linearize ([0 , 0 , 0 ], [0 , 0 ], copy = True ,
211
+ name = 'linearized' )
212
+ assert linearized .name == 'linearized'
213
+ assert linearized .find_input ('v' ) == 0
214
+ assert linearized .find_input ('phi' ) == 1
215
+ assert linearized .find_output ('x' ) == 0
216
+ assert linearized .find_output ('y' ) == 1
217
+ assert linearized .find_state ('x' ) == 0
218
+ assert linearized .find_state ('y' ) == 1
219
+ assert linearized .find_state ('theta' ) == 2
220
+
221
+ # If we copy signal names w/out a system name, append '_linearized'
222
+ linearized = kincar .linearize ([0 , 0 , 0 ], [0 , 0 ], copy = True )
223
+ assert linearized .name == kincar .name + '_linearized'
224
+
225
+ # If copy is False, signal names should not be copied
226
+ lin_nocopy = kincar .linearize (0 , 0 , copy = False )
227
+ assert lin_nocopy .find_input ('v' ) is None
228
+ assert lin_nocopy .find_output ('x' ) is None
229
+ assert lin_nocopy .find_state ('x' ) is None
230
+
199
231
@noscipy0
200
232
def test_connect (self , tsys ):
201
233
# Define a couple of (linear) systems to interconnection
0 commit comments