Skip to content

Commit 871b23d

Browse files
committed
Refactoring
1 parent 5de9a22 commit 871b23d

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

src/flightpathcontroller.jl

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ See also:
4040
- `chi_set`: desired flight direction (bearing) computed by `navigate()` [rad].
4141
- `u_d0`: minimum depower setting (fully powered kite).
4242
- `u_d_max`: maximum depower setting (fully depowered kite).
43-
- `u_d_prime`: normalised depower setting in [0, 1].
43+
- `u_d_prime`: normalized depower setting in [0, 1].
4444
- `u_s_max`: saturation limit for the steering output.
4545
- `psi_dot_max`: saturation limit for the commanded turn rate [rad/s].
4646
- `u_d`: actual depower setting in [0, 1].
@@ -66,7 +66,7 @@ See also:
6666
- `reset_int1::Bool`: flag to reset the main integrator at the next `calc_steering` call.
6767
- `radius`: commanded turn radius [m], or `nothing` when not in radius-control mode.
6868
- `_n`: filter coefficient for the discrete derivative in the D term.
69-
- `_i`: call counter for `calc_steering`; used to trigger one-shot initialisations.
69+
- `_i`: call counter for `calc_steering`; used to trigger one-shot initializations.
7070
"""
7171
@with_kw mutable struct FlightPathController @deftype Float64
7272
"struct holding the settings of the flight path controller"
@@ -358,7 +358,13 @@ function calc_sat1in_sat1out_sat2in_sat2out(fpc::FlightPathController, x)
358358
sat1_in, sat1_out, sat2_in, sat2_out, int_in
359359
end
360360

361-
361+
function residual_fpc!(F, x, fpc::FlightPathController)
362+
sat1_in, sat1_out, sat2_in, sat2_out, _ = calc_sat1in_sat1out_sat2in_sat2out(fpc, x)
363+
k_u_in = (sat2_out - sat2_in) / fpc.ndi_gain
364+
k_psi_in = sat1_out - sat1_in
365+
F[1] = k_u_in - x[1]
366+
F[2] = k_psi_in - x[2]
367+
end
362368

363369
"""
364370
function calc_steering(fpc, parking)
@@ -372,19 +378,7 @@ Implements the simulink block diagram, shown in:
372378
If the parameter parking is true, only the heading is controlled, not the course.
373379
"""
374380
function calc_steering(fpc::FlightPathController, parking)
375-
"""
376-
residual!(fpc, x)
377-
378-
see: `docs/flight_path_controller_II.png`
379-
x: vector of `k_u_in`, `k_psi_in` and `int2_in`
380-
"""
381-
function residual!(F, x)
382-
sat1_in, sat1_out, sat2_in, sat2_out, int_in = calc_sat1in_sat1out_sat2in_sat2out(fpc, x)
383-
k_u_in = (sat2_out - sat2_in) / fpc.ndi_gain
384-
k_psi_in = sat1_out - sat1_in
385-
F[1] = k_u_in - x[1]
386-
F[2] = k_psi_in - x[2]
387-
end
381+
residual! = (F, x) -> residual_fpc!(F, x, fpc)
388382

389383
navigate(fpc)
390384
# control the heading of the kite

0 commit comments

Comments
 (0)