|
438 | 438 | matrices, _ = get_sensitivity(sys, sys.ap)
|
439 | 439 | @test matrices == matrices_normal
|
440 | 440 | end
|
| 441 | + |
| 442 | +@testset "Ignored analysis points only affect relevant connection sets" begin |
| 443 | + m1 = 1 |
| 444 | + m2 = 1 |
| 445 | + k = 1000 # Spring stiffness |
| 446 | + c = 10 # Damping coefficient |
| 447 | + |
| 448 | + @named inertia1 = Inertia(; J = m1, phi = 0, w = 0) |
| 449 | + @named inertia2 = Inertia(; J = m2, phi = 0, w = 0) |
| 450 | + |
| 451 | + @named spring = Spring(; c = k) |
| 452 | + @named damper = Damper(; d = c) |
| 453 | + |
| 454 | + @named torque = Torque(use_support = false) |
| 455 | + |
| 456 | + function SystemModel(u = nothing; name = :model) |
| 457 | + eqs = [connect(torque.flange, inertia1.flange_a) |
| 458 | + connect(inertia1.flange_b, spring.flange_a, damper.flange_a) |
| 459 | + connect(inertia2.flange_a, spring.flange_b, damper.flange_b)] |
| 460 | + if u !== nothing |
| 461 | + push!(eqs, connect(torque.tau, u.output)) |
| 462 | + return @named model = ODESystem( |
| 463 | + eqs, t; systems = [torque, inertia1, inertia2, spring, damper, u]) |
| 464 | + end |
| 465 | + ODESystem(eqs, t; systems = [torque, inertia1, inertia2, spring, damper], name) |
| 466 | + end |
| 467 | + |
| 468 | + @named r = Step(start_time = 1) |
| 469 | + @named pid = LimPID(k = 400, Ti = 0.5, Td = 1, u_max = 350) |
| 470 | + @named filt = SecondOrder(d = 0.9, w = 10, x = 0, xd = 0) |
| 471 | + @named sensor = AngleSensor() |
| 472 | + @named add = Add() # To add the feedback and feedforward control signals |
| 473 | + model = SystemModel() |
| 474 | + @named inverse_model = SystemModel() |
| 475 | + @named inverse_sensor = AngleSensor() |
| 476 | + connections = [connect(r.output, :r, filt.input) # Name connection r to form an analysis point |
| 477 | + connect(inverse_model.inertia1.flange_b, inverse_sensor.flange) # Attach the inverse sensor to the inverse model |
| 478 | + connect(filt.output, pid.reference, inverse_sensor.phi) # the filtered reference now goes to both the PID controller and the inverse model input |
| 479 | + connect(inverse_model.torque.tau, add.input1) |
| 480 | + connect(pid.ctr_output, add.input2) |
| 481 | + connect(add.output, :u, model.torque.tau) # Name connection u to form an analysis point |
| 482 | + connect(model.inertia1.flange_b, sensor.flange) |
| 483 | + connect(sensor.phi, :y, pid.measurement)] |
| 484 | + closed_loop = ODESystem(connections, t, |
| 485 | + systems = [model, inverse_model, pid, filt, sensor, inverse_sensor, r, add], |
| 486 | + name = :closed_loop) |
| 487 | + # just ensure the system simplifies |
| 488 | + Blocks.get_sensitivity(closed_loop, :y) |
| 489 | +end |
0 commit comments