@@ -19,13 +19,18 @@ import KiteUtils: wrap2pi
1919 k_ds = 2.0 # influence of the depower settings on the steering sensitivity
2020 c1 = 0.048 # v9 kite model
2121 c2 = 0 # a value other than zero creates more problems than it solves
22+ max_turn_rate_set:: Float64 = 100.0 # clamp outer-loop desired turn-rate [rad/s]
23+ max_turn_rate_cmd:: Float64 = 100.0 # clamp inner-loop commanded turn-rate [rad/s]
24+ max_steering:: Float64 = 100.0 # clamp final steering command to physical range
25+ max_steering_rate:: Float64 = 0.0 # optional rate limit [1/s], 0 disables limiting
2226end
2327
2428mutable struct ParkingController
2529 pcs:: ParkingControllerSettings
2630 pid_tr:: DiscretePID
2731 pid_outer:: DiscretePID
2832 last_heading:: Float64
33+ last_steering:: Float64
2934 chi_set:: Float64
3035 last_ndi_gain:: Float64
3136end
@@ -34,7 +39,7 @@ function ParkingController(pcs::ParkingControllerSettings; last_heading = 0.0)
3439 Ts = pcs. dt
3540 pid_tr = DiscretePID (;K= pcs. kp_tr, Ti= pcs. kp_tr/ pcs. ki_tr, Ts)
3641 pid_outer = DiscretePID (;K= pcs. kp, Ti= pcs. kp/ pcs. ki, Ts)
37- return ParkingController (pcs, pid_tr, pid_outer, last_heading, 0 , 0 )
42+ return ParkingController (pcs, pid_tr, pid_outer, last_heading, 0.0 , 0.0 , 0. 0 )
3843end
3944
4045"""
@@ -104,12 +109,22 @@ function calc_steering(pc::ParkingController, heading, chi_set; elevation=0.0, v
104109 # calculate the desired turn rate
105110 heading = wrap2pi (heading) # a different wrap2pi function is needed that avoids any jumps
106111 psi_dot_set = pc. pid_outer (wrap2pi (chi_set), heading)
107- psi_dot = (wrap2pi (heading - pc. last_heading)) / pc. pcs. dt
112+ psi_dot_set = clamp (psi_dot_set, - pc. pcs. max_turn_rate_set, pc. pcs. max_turn_rate_set)
113+ # Use shortest-angle difference to avoid artificial spikes at wrap boundaries.
114+ dpsi = atan (sin (heading - pc. last_heading), cos (heading - pc. last_heading))
115+ psi_dot = dpsi / pc. pcs. dt
108116 pc. last_heading = heading
109117 psi_dot_in = pc. pid_tr (psi_dot_set, psi_dot)
118+ psi_dot_in = clamp (psi_dot_in, - pc. pcs. max_turn_rate_cmd, pc. pcs. max_turn_rate_cmd)
110119 # linearize the NDI block
111120 u_s, ndi_gain = linearize (pc, psi_dot_in, heading, elevation, v_app; ud_prime)
112- u_s, ndi_gain, psi_dot, psi_dot_set
121+ u_cmd = clamp (u_s, - pc. pcs. max_steering, pc. pcs. max_steering)
122+ if pc. pcs. max_steering_rate > 0.0
123+ max_delta = pc. pcs. max_steering_rate * pc. pcs. dt
124+ u_cmd = clamp (u_cmd, pc. last_steering - max_delta, pc. last_steering + max_delta)
125+ end
126+ pc. last_steering = u_cmd
127+ u_cmd, ndi_gain, psi_dot, psi_dot_set
113128end
114129
115130function test_linearize ()
0 commit comments