Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased
### Changed
- BREAKING: the flight path planner, the flight path controller and `SystemStateControl` take the heading and the course in the right-handed convention of KiteUtils after v0.14.2 and the KiteModels release that follows it: zero towards zenith, positive to the right as seen from the ground station, the opposite sign of before. Fed that convention, they fly the same figure of eight and park the same way as before. Code that passes its own heading or course to `on_new_systate`, `on_new_data` or `calc_steering(ssc; heading)` negates it.
- BREAKING: `heading_upper_turn` in `FPPSettings` and in `data/fpp_settings*.yaml` is 25° instead of 335°: the upper turn ends once the heading lies between it and 180°. A settings file of your own that sets it takes 360° minus its old value.
- the examples that compute the heading themselves call `calc_heading(kps)` of the KiteModels release that follows KiteUtils, which has no `neg_azimuth` keyword; they now steer on the geometric heading instead of one computed at the negated azimuth
- the parking controller of `examples/parking_controller.jl` takes the heading and its set value positive to the right and returns the steering of the kite model directly; its reference values are re-derived for that sign, and `test_calc_steering` passes again (its turn rate and steering references were stale)

## KiteControllers v0.4.2 - 2026-10-24
### Changed
- the plot functions of the examples (before `examples/plot_functions.jl` and `examples/plot_helpers.jl`) moved to the new local package KitePlots in `lib/KitePlots`, which is part of the system image. Defined in `Main`, they could not be stored in it: the first plot of a log, e.g. with the OK button next to `plot_main` in the autopilot, took about 20 s to compile, mostly for the very large log type. The system image has to be created again with `bin/create_sys_image`
Expand Down
2 changes: 1 addition & 1 deletion data/fpp_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fpp_settings:
heading_offset_int: 32.0 # dito, for the turn around the intermediate point
heading_offset_high: 54.0 # dito, for elevation angles > 47.5 degrees
heading_offset_up: 60.0 # degrees, before finishing the up-turn
heading_upper_turn: 335 # degrees
heading_upper_turn: 25 # degrees, heading above which the upper turn ends
k_factor: 1.2 # a factor > 1 reduces the width of the intermediate phase
corr_vec: [16.15, 16.15, 22.75, 27.85, 23.71, 19.52, 16.13, 13.44, 11.31, 9.42, 7.79, 5.92]
2 changes: 1 addition & 1 deletion data/fpp_settings_hydra20.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fpp_settings:
heading_offset_int: 32.0 # dito, for the turn around the intermediate point
heading_offset_high: 54.0 # dito, for elevation angles > 47.5 degrees
heading_offset_up: 60.0 # degrees, before finishing the up-turn
heading_upper_turn: 335 # degrees
heading_upper_turn: 25 # degrees, heading above which the upper turn ends
k_factor: 1.8 # a factor > 1 reduces the width of the intermediate phase
corr_vec: [10.35, 10.35, 2.04, 5.07, 3.89, 2.21, 0.57, -0.88, -2.79]
2 changes: 1 addition & 1 deletion data/fpp_settings_hydra20_426.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fpp_settings:
heading_offset_int: 32.0 # dito, for the turn around the intermediate point
heading_offset_high: 54.0 # dito, for elevation angles > 47.5 degrees
heading_offset_up: 60.0 # degrees, before finishing the up-turn
heading_upper_turn: 335 # degrees
heading_upper_turn: 25 # degrees, heading above which the upper turn ends
k_factor: 1.8 # a factor > 1 reduces the width of the intermediate phase
corr_vec: [0.0, -16.0, -0.61, 2.96, 2.12, 0.63, -0.73, -1.88, -2.91, -3.71, -4.18]
2 changes: 1 addition & 1 deletion data/fpp_settings_hydra20_920.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fpp_settings:
heading_offset_int: 32.0 # dito, for the turn around the intermediate point
heading_offset_high: 54.0 # dito, for elevation angles > 47.5 degrees
heading_offset_up: 60.0 # degrees, before finishing the up-turn
heading_upper_turn: 335 # degrees
heading_upper_turn: 25 # degrees, heading above which the upper turn ends
k_factor: 1.8 # a factor > 1 reduces the width of the intermediate phase
corr_vec: [10.01, 10.01, 7.15, 2.59, 3.39, 3.54, 2.92, 2.19, 1.51, 0.85, 0.26]
2 changes: 1 addition & 1 deletion examples/autopilot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function simulate(integrator, stopped=true)
if i > 100
dp = KiteControllers.get_depower(app.ssc::SystemStateControl)
if dp < 0.22 dp = 0.22 end
heading = calc_heading(app.kps4::KPS4; neg_azimuth=true, one_point=false)
heading = calc_heading(app.kps4::KPS4)
azimuth = -calc_azimuth(app.kps4::KPS4)
steering = -calc_steering(app.ssc::SystemStateControl; heading, azimuth)
set_depower_steering((app.kps4::KPS4).kcu, dp, steering)
Expand Down
2 changes: 1 addition & 1 deletion examples/autopilot_1p.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function simulate(integrator)
if i > 100
dp = KiteControllers.get_depower(ssc)
if dp < 0.22 dp = 0.22 end
heading = calc_heading(kps3; neg_azimuth=true, one_point=false)
heading = calc_heading(kps3)
sys_state.heading = heading
sys_state.azimuth = -calc_azimuth(kps3)
steering = -calc_steering(ssc)
Expand Down
2 changes: 1 addition & 1 deletion examples/batch_pilot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function simulate(app::KiteApp)
if i > 100
dp = KiteControllers.get_depower(app.ssc::SystemStateControl)
if dp < 0.22; dp = 0.22; end
heading = calc_heading(app.kps4::KPS4; neg_azimuth = true, one_point = false)
heading = calc_heading(app.kps4::KPS4)
app.ssc.sys_state.heading = heading
app.ssc.sys_state.azimuth = -calc_azimuth(app.kps4::KPS4)
steering = -calc_steering(app.ssc::SystemStateControl)
Expand Down
2 changes: 1 addition & 1 deletion examples/joystick.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function simulate(integrator)
depower = KiteControllers.get_depower(ssc)
# println("dp: ", dp)
if depower < 0.22; depower = 0.22; end
heading = calc_heading(kps4; neg_azimuth=true)
heading = calc_heading(kps4)
steering = calc_steering(ssc, jsaxes.x; heading)
set_depower_steering(kps4.kcu, depower, steering)
println("depower: ", depower, " steering: ", round(steering, digits=3))
Expand Down
2 changes: 1 addition & 1 deletion examples/learn_corrections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function residual(corr_vec=nothing; full_sim=false)
if i > 100
dp = KiteControllers.get_depower(ssc)
if dp < 0.22 dp = 0.22 end
heading = calc_heading(kps4; neg_azimuth=true, one_point=false)
heading = calc_heading(kps4)
ssc.sys_state.heading = heading
ssc.sys_state.azimuth = -calc_azimuth(kps4)
local steering
Expand Down
2 changes: 1 addition & 1 deletion examples/matlab/compare_full_cycle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function fly(winch_model, project; max_time=MAX_TIME)
for i in 1:steps
if i > 100
dp = max(KiteControllers.get_depower(ssc), 0.22)
heading = calc_heading(kps4; neg_azimuth=true, one_point=false)
heading = calc_heading(kps4)
azimuth = -calc_azimuth(kps4)
steering = -calc_steering(ssc; heading, azimuth)
set_depower_steering(kps4.kcu, dp, steering)
Expand Down
2 changes: 1 addition & 1 deletion examples/minipilot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function simulate(integrator, kps4, ssc, PARKING::Ref{Bool}, stopped=true)
if i > 100
dp = KiteControllers.get_depower(ssc)
if dp < 0.22 dp = 0.22 end
heading = calc_heading(kps4::KPS4; neg_azimuth=true, one_point=false)
heading = calc_heading(kps4::KPS4)
ssc.sys_state.heading = heading
ssc.sys_state.azimuth = -calc_azimuth(kps4)
steering = -calc_steering(ssc)
Expand Down
2 changes: 1 addition & 1 deletion examples/minipilot_12.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function simulate(integrator, kps4, ssc, PARKING::Ref{Bool}, stopped=true)
if i > 100
dp = KiteControllers.get_depower(ssc)
if dp < 0.22 dp = 0.22 end
heading = calc_heading(kps4::KPS4; neg_azimuth=true, one_point=false)
heading = calc_heading(kps4::KPS4)
ssc.sys_state.heading = heading
ssc.sys_state.azimuth = -calc_azimuth(kps4)
steering = -calc_steering(ssc)
Expand Down
2 changes: 1 addition & 1 deletion examples/parking_1p.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function simulate(integrator)
on_new_systate(ssc, sys_state)
while true
if i > 100
heading = calc_heading(kps; neg_azimuth=true, one_point=false)
heading = calc_heading(kps)
steering = calc_steering(ssc, 0; heading)
time = i * dt
# disturbance
Expand Down
39 changes: 21 additions & 18 deletions examples/parking_controller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ end
"""
linearize(pcs::ParkingControllerSettings, psi_dot, psi, elevation, v_app; ud_prime=0)

Nonlinear, dynamic inversion block (NDI) according to Eq. 6.4 and Eq. 6.12.
Nonlinear, dynamic inversion block (NDI) according to Eq. 6.4 and Eq. 6.12. Positive
steering turns the kite to the left as seen from the ground station.

Parameters:
- psi_dot: desired turn rate in radians per second
- psi: heading in radians
- psi_dot: desired turn rate in radians per second, positive to the right
- psi: heading in radians, positive to the right
- elevation: elevation angle in radians
- v_app: apparent wind speed in m/s
- ud_prime: depower setting in the range of 0 to 1, 0 means fully powered, 1 means fully depowered
Expand All @@ -62,7 +63,8 @@ function linearize(pc::ParkingController, psi_dot, psi, elevation, v_app; ud_pri
# Eq. 6.13: calculate va_hat
va_hat = clamp(v_app, pcs.va_min, pcs.va_max)
# Eq. 6.12: calculate the steering from the desired turn rate
u_s = (1.0 + pcs.k_ds * ud_prime) / (pcs.c1 * va_hat) * (psi_dot - pcs.c2 / va_hat * sin(psi) * cos(elevation))
gravity_turn_rate = pcs.c2 / va_hat * sin(psi) * cos(elevation)
u_s = -(1.0 + pcs.k_ds * ud_prime) / (pcs.c1 * va_hat) * (psi_dot - gravity_turn_rate)
if abs(psi_dot) < 1e-6
ndi_gain = pc.last_ndi_gain
else
Expand All @@ -73,9 +75,10 @@ function linearize(pc::ParkingController, psi_dot, psi, elevation, v_app; ud_pri
end

"""
navigate(fpc, limit=50.0)
navigate(pc, azimuth, elevation; limit=50.0)

Calculate the desired flight direction chi_set using great circle navigation.
Calculate the desired flight direction chi_set, positive to the right, using great circle
navigation from the azimuth (positive to the left) and the elevation of the kite.
Limit delta_beta to the value of the parameter limit (in degrees).
"""
function navigate(pc::ParkingController, azimuth, elevation; limit=50.0)
Expand All @@ -90,7 +93,7 @@ function navigate(pc::ParkingController, azimuth, elevation; limit=50.0)
elseif beta_set - beta < -r_limit
beta_set = beta - r_limit
end
y = sin(phi_set - phi) * cos(beta_set)
y = sin(phi - phi_set) * cos(beta_set)
x = cos(beta) * sin(beta_set) - sin(beta) * cos(beta_set) * cos(phi_set - phi)
pc.chi_set = atan(y, x)
end
Expand All @@ -102,9 +105,9 @@ Calculate rel_steering and ndi_gain from the actual heading, elevation, and appa

Parameters:
- pc: parking controller
- heading: actual heading in radians
- heading: actual heading in radians, positive to the right seen from the ground station
- heading_rate: measured heading rate in rad/s
- chi_set: desired heading in radians
- chi_set: desired heading in radians, positive to the right
- elevation: elevation angle in radians
- v_app: apparent wind speed in m/s
- ud_prime: depower setting in the range of 0 to 1, 0 means fully powered, 1 means fully depowered
Expand Down Expand Up @@ -150,8 +153,8 @@ function test_linearize()
ud_prime = 0.5
# linearize the NDI block
u_s, ndi_gain = linearize(pc, psi_dot, psi, elevation, v_app; ud_prime)
@test u_s ≈ 0.41666666666666674
@test ndi_gain ≈ 4.166666666666667
@test u_s ≈ -0.41666666666666674
@test ndi_gain ≈ -4.166666666666667
end
nothing
end
Expand All @@ -165,15 +168,15 @@ function test_calc_steering()
# create the parking controller
pc = ParkingController(pcs)
# set the heading
heading = deg2rad(1.0)
heading = deg2rad(-1.0)
heading_rate = 0.0
elevation = deg2rad(70.0)
chi_set = deg2rad(34.0)
chi_set = deg2rad(-34.0)
u_s, ndi_gain, psi_dot, psi_dot_set = calc_steering(pc, heading, heading_rate, chi_set; elevation)
@test u_s ≈ 18.135061759003584
@test ndi_gain ≈ 2.0833333333333335
@test psi_dot ≈ 0.3490658503988659
@test psi_dot_set ≈ 8.639379797371932
@test u_s ≈ 18.898643306751104
@test ndi_gain ≈ -2.0833333333333335
@test psi_dot ≈ 0.0
@test psi_dot_set ≈ -8.639379797371932
end
nothing
end
Expand All @@ -191,7 +194,7 @@ function test_navigate()
# set the elevation
elevation = deg2rad(70.0)
chi_set = navigate(pc, azimuth, elevation)
@test chi_set ≈ -deg2rad(34.019878734151234)
@test chi_set ≈ deg2rad(34.019878734151234)
end
nothing
end
Expand Down
23 changes: 13 additions & 10 deletions src/flightpathplanner2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,22 @@ end
on_new_systate(fpp::FlightPathPlanner, phi, beta, heading, course, v_a, u_d)

Forward the current estimated kite system state to the [`FlightPathController`](@ref)
by calling `on_est_sysstate`. Sign conventions are applied before forwarding: azimuth and
heading angles are negated to match the controller's coordinate frame.
by calling `on_est_sysstate`. The azimuth is negated to match the controller's coordinate
frame; heading and course are passed on unchanged.

# Arguments
- `fpp`: the `FlightPathPlanner` instance.
- `phi`: azimuth angle of the kite in radians (positive to the left).
- `beta`: elevation angle of the kite in radians.
- `heading`: kite heading angle `ψ` in radians, in the range `0 .. 2π`.
- `course`: kite course angle `χ` in radians, in the range `0 .. 2π`.
- `heading`: kite heading angle `ψ` in radians, positive to the right (KiteUtils).
- `course`: kite course angle `χ` in radians, positive to the right (KiteUtils).
- `v_a`: apparent wind speed in m/s.
- `u_d`: relative depower setting of the kite, in the range `0.0 .. 1.0`.
"""
function on_new_systate(fpp::FlightPathPlanner, phi, beta, heading, course, v_a, u_d)
psi = wrap2pi(heading)
chi = wrap2pi(course)
on_est_sysstate(fpp.fpca.fpc, -phi, beta, -psi, -chi, fpp.fpca._omega, v_a, u_d=u_d)
on_est_sysstate(fpp.fpca.fpc, -phi, beta, psi, chi, fpp.fpca._omega, v_a, u_d=u_d)
end

"""
Expand All @@ -239,7 +239,8 @@ the transition conditions defined in Tables 5.3–5.6 of the PhD thesis are sati
- `fpp`: the `FlightPathPlanner` instance.
- `depower`: relative depower setting of the kite, in the range `0.0 .. 1.0`.
- `length`: tether length in metres.
- `heading`: kite heading angle `ψ` in radians, in the range `0 .. 2π`.
- `heading`: kite heading angle `ψ` in radians, in the range `0 .. 2π`, positive to the right
seen from the ground station.
- `height`: kite height above ground in metres.

# State read from `fpp.fpca`
Expand Down Expand Up @@ -279,20 +280,21 @@ function on_new_data(fpp::FlightPathPlanner, depower, length, heading, height, _
fpp.fpca.high = true
_switch(fpp, FLY_LEFT)
end
elseif state == UPPER_TURN && psi > π && psi < deg2rad(fpp.fpps.heading_upper_turn)
elseif state == UPPER_TURN && psi > deg2rad(fpp.fpps.heading_upper_turn) && psi < π
_switch(fpp, LOW_RIGHT)
elseif state == LOW_RIGHT && phi < -phi_1
fpp.fpca.fig8 += 1
_switch(fpp, LOW_LEFT) # was LOW_TURN
elseif state == LOW_TURN && psi < deg2rad(180.0 + fpp.fpps.heading_offset_int)
elseif state == LOW_TURN && psi > deg2rad(180.0 - fpp.fpps.heading_offset_int)
_switch(fpp, LOW_LEFT)
elseif state == LOW_LEFT && phi > -phi_2 # &&
_switch(fpp, TURN_LEFT)
# see: Table 5.5
elseif state == FLY_LEFT && phi > fpp.fpca._phi_sw
fpp.fpca.fig8 += 1
_switch(fpp, TURN_LEFT)
elseif state == TURN_LEFT && (psi > deg2rad(180.0 - fpp.fpca._heading_offset) || fpp.timeout > fpp.fpps.timeout)
elseif state == TURN_LEFT && (psi < deg2rad(180.0 + fpp.fpca._heading_offset) ||
fpp.timeout > fpp.fpps.timeout)
_switch(fpp, FLY_RIGHT)
elseif state == FLY_RIGHT && phi >= phi_3
if ! fpp.finish
Expand All @@ -302,7 +304,8 @@ function on_new_data(fpp::FlightPathPlanner, depower, length, heading, height, _
_switch(fpp, UP_TURN_LEFT)
elseif state == FLY_RIGHT && phi < -fpp.fpca._phi_sw # &&
_switch(fpp, TURN_RIGHT)
elseif state == TURN_RIGHT && (psi < deg2rad(180.0 + fpp.fpca._heading_offset) || fpp.timeout > fpp.fpps.timeout)
elseif state == TURN_RIGHT && (psi > deg2rad(180.0 - fpp.fpca._heading_offset) ||
fpp.timeout > fpp.fpps.timeout)
if fpp.fpps.log_level > 1
println("timeout TURN_RIGHT: $(fpp.timeout)")
elseif fpp.fpps.log_level > 0
Expand Down
4 changes: 2 additions & 2 deletions src/fpp_settings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Construct with `FPPSettings(true)` to auto-load from disk, or `FPPSettings()` fo
- `heading_offset_int::Float64`: heading lead angle for the turn around the intermediate point [°].
- `heading_offset_high::Float64`: heading lead angle for elevation angles > 47.5° [°].
- `heading_offset_up::Float64`: heading lead angle before finishing the up-turn [°].
- `heading_upper_turn::Float64`: heading angle that triggers the upper turn [°].
- `heading_upper_turn::Float64`: heading above which the upper turn ends [°].
- `k_factor::Float64`: scaling factor for the attractor distance.
- `timeout::Float64`: maximum number of time steps allowed in a single planner state before a forced transition.
- `corr_vec::Vector{Float64}`: elevation-angle correction look-up table (12 entries).
Expand Down Expand Up @@ -50,7 +50,7 @@ Construct with `FPPSettings(true)` to auto-load from disk, or `FPPSettings()` fo
heading_offset_high::Float64 = 54.0
"degrees, before finishing the up-turn"
heading_offset_up::Float64 = 60.0
heading_upper_turn::Float64 = 360.0-25.0
heading_upper_turn::Float64 = 25.0
k_factor::Float64 = 1.0
timeout::Float64 = 145
corr_vec::Vector{Float64} = [24.02, 36.08, 32.70, 25.40, 19.85, 16.13, 13.55, 11.42, 9.32, 7.38, 5.58, 3.84]
Expand Down
2 changes: 1 addition & 1 deletion test/test-fpp_settings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ try
@test fpps.heading_offset_int ≈ 32.0
@test fpps.heading_offset_high ≈ 54.0
@test fpps.heading_offset_up ≈ 60.0
@test fpps.heading_upper_turn ≈ 335.0
@test fpps.heading_upper_turn ≈ 25.0
@test fpps.k_factor ≈ 1.0
@test fpps.timeout ≈ 145.0
@test length(fpps.corr_vec) == 12
Expand Down
Loading