You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/ControlSystemsBase/src/timeresp.jl
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -144,7 +144,7 @@ Continuous-time systems are simulated using an ODE solver if `u` is a function (
144
144
If `u` is a function, then `u(x,i)` (for discrete systems) or `u(x,t)` (for continuous ones) is called to calculate the control signal at every iteration (time instance used by solver). This can be used to provide a control law such as state feedback `u(x,t) = -L*x` calculated by `lqr`.
145
145
To simulate a unit step at `t=t₀`, use `(x,t)-> t ≥ t₀`, for a ramp, use `(x,t)-> t`, for a step at `t=5`, use `(x,t)-> (t >= 5)` etc.
146
146
147
-
*Note:* The function `u` will be called once before simulating to verify that it returns an array of the correct dimensions. This can cause problems if `u` is stateful. You can disable this check by passing `check_u = false`.
147
+
*Note:* The function `u` will be called once before simulating to verify that it returns an array of the correct dimensions. This can cause problems if `u` is stateful or has other side effects. You can disable this check by passing `check_u = false`.
148
148
149
149
For maximum performance, see function [`lsim!`](@ref), available for discrete-time systems only.
150
150
@@ -206,7 +206,7 @@ function lsim(sys::AbstractStateSpace, u::AbstractVecOrMat, t::AbstractVector;
Copy file name to clipboardExpand all lines: lib/ControlSystemsBase/src/types/result_types.jl
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,14 @@ y, t, x, u = result
24
24
- `x::Tx`
25
25
- `u::Tu`
26
26
- `sys::Ts`
27
+
28
+
## Concatenation of SimResults
29
+
30
+
Two SimResults can be concatenated in time using `hcat`, or `[res1 res2]`, the rules for this are as follows:
31
+
- If the start time of the second result is one sample interval after the end time of the first result, the results are concatenated and the length of the result is the sum of the lengths of the two results.
32
+
- If the start time of the second result is equal to the end time of the first result, _and_ the initial state of the second result is equal to the final state of the first result, the results are concatenated omitting the initial point from the second result, which would otherwise have been repeated. The length of the result is the sum of the lengths of the two results minus one.
33
+
If none of the above holds, a warning is issued and the result has the length of the sum of the lengths of the two results.
34
+
- If the sample intervals of the two results are different, an error is thrown.
27
35
"""
28
36
struct SimResult{Ty, Tt, Tx, Tu, Ts} <:AbstractSimResult# Result of lsim
29
37
y::Ty
@@ -42,6 +50,18 @@ function Base.getindex(r::SimResult, v::AbstractVector)
@warn"Concatenated SimResults do not appear to be continuous in time, the first ends at t=$(r1.t[end]) and the second starts at t=$(r2.t[1]). With sample interval Ts=$(r1.sys.Ts), the second simulation was expected to start at t=$(r1.t[end] + r1.sys.Ts) To start a simulation at a non-zero time, pass a time vector to lsim."
@testlength(res12.t) ==length(res1.t) +length(res2.t) -1# -1 since we do not include the initial time point from the second result which overlaps with the first
268
+
269
+
res2 =lsim(sysd,u)
270
+
@test_logs (:warn, r"Concatenated SimResults do not appear to be continuous in time") [res1 res2]
271
+
res12 = [res1 res2]
272
+
@testlength(res12.t) ==length(res1.t) +length(res2.t) # not -1 since we do include the initial time point from the second result if they do not appear to be continuous in time
@testlength(res12.t) ==length(res1.t) +length(res2.t) # not -1 since we do do include the initial time point from the second result if they do not appear to be continuous in time
0 commit comments