88from cyecca .models .bezier import derive_dcm_to_quat
99from cyecca .lie .group_se23 import SE23Quat , se23
1010from cyecca .symbolic import SERIES
11+ from cyecca .models .rdd2 import saturatem
1112
1213# print("python: ", sys.executable)
1314
3637# kp_yaw = 1
3738
3839# position loop
39- kp_pos = 0.5 # position proportional gain
40- kp_vel = 2.0 # velocity proportional gain
4140# pos_sp_dist_max = 2 # position setpoint max distance
4241# vel_max = 2.0 # max velocity command
43- z_integral_max = 0 # 5.0
44- ki_z = 0.05 # velocity z integral gain
42+ x_integral_max = 0.25 # 10% trim throttle
43+ y_integral_max = 0.25 # 10% trim throttle
44+ z_integral_max = 0.25 # 10% trim throttle
45+ ki_x = 0.1 # 1/ integrator time constant in 1/seconds
46+ ki_y = 0.1 # 1/ integrator time constant in 1/seconds
47+ ki_z = 0.1 # 1/ integrator time constant in 1/seconds
4548
4649
4750def saturate (x , x_min , x_max ):
@@ -175,8 +178,8 @@ def se23_solve_control():
175178 # ]
176179 # ) # omega3 # control omega1,2,3, and az
177180 # Q = 100*ca.diag(ca.vertcat(10, 10, 10, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)) # penalize state
178- Q = 8 * np .eye (9 ) # penalize state
179- R = 1 * ca .DM .eye (9 ) # penalize input
181+ Q = 100 * np .eye (9 ) # penalize state
182+ R = 2e- 1 * ca .DM .eye (9 ) # penalize input
180183 K , _ , _ = lqr (A , B , Q , R )
181184 K = - K
182185 BK = B @ K
@@ -203,7 +206,7 @@ def derive_outerloop_control():
203206 zeta = ca .SX .sym ("zeta" , 9 )
204207 at_w = ca .SX .sym ("at_w" , 3 )
205208 q_wb = SO3Quat .elem (ca .SX .sym ("q_wb" , 4 )) # orientation
206- z_i = ca .SX .sym ("z_i" ) # z velocity error integral
209+ z_i = ca .SX .sym ("z_i" , 3 ) # z velocity error integral
207210 dt = ca .SX .sym ("dt" ) # time step
208211
209212 # CALC
@@ -239,8 +242,18 @@ def derive_outerloop_control():
239242 p_term = ca .if_else (p_norm > p_norm_max , p_norm_max * p_term / p_norm , p_term )
240243
241244 # throttle integral
242- z_i_2 = z_i + zeta [2 ] * dt
243- z_i_2 = saturate (z_i_2 , - ca .vertcat (z_integral_max ), ca .vertcat (z_integral_max ))
245+ z_i_2 = z_i + zeta [0 :3 ] * dt
246+ z_i_2 = saturatem (
247+ z_i_2 ,
248+ - thrust_trim
249+ * ca .vertcat (
250+ x_integral_max / ki_x , y_integral_max / ki_y , z_integral_max / ki_z
251+ ),
252+ thrust_trim
253+ * ca .vertcat (
254+ x_integral_max / ki_x , y_integral_max / ki_y , z_integral_max / ki_z
255+ ),
256+ )
244257
245258 # trim throttle
246259 T = p_term + thrust_trim * zW + ki_z * z_i * zW
0 commit comments