From d4c788e8bbf34e5c40901a34652da68bfe6f43b0 Mon Sep 17 00:00:00 2001 From: thetazero Date: Tue, 10 Oct 2023 15:28:43 -0400 Subject: [PATCH 1/2] Control limit experiment --- simulator_test/detumble.jl | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/simulator_test/detumble.jl b/simulator_test/detumble.jl index 1a37e19..433a853 100644 --- a/simulator_test/detumble.jl +++ b/simulator_test/detumble.jl @@ -32,6 +32,18 @@ Detumble = Controller( py4_dipole_limits ) +δ=0.053130000000000004*0.01 + +function saturate(x, r) + if abs(x) <= δ + return r + elseif x > δ + return r + else # x < -δ + return -r + end +end + function control_law(measurement, t) (state, params) = measurement @@ -39,8 +51,14 @@ function control_law(measurement, t) m = Detumble.get_control(state.angular_velocity, ᵇQⁿ * params.b) + for i in 1:3 + m[i] = saturate(m[i], py4_dipole_limits[i]) + end + + @assert clamp.(m, -py4_dipole_limits, py4_dipole_limits) ≈ m + return SP.Control( - clamp.(m, -py4_dipole_limits, py4_dipole_limits) + m ) end @@ -68,7 +86,7 @@ function slow_rotation(state, params, t, i) return norm(state.angular_velocity) < deg2rad(0.1) end -day = 60 * 60 * 24 +day = 60 * 60 time_step = 0.1 @time (data, time) = SP.simulate(control_law, max_iterations=day / time_step, dt=time_step, log_init=log_init, log_step=log_step, log_end=log_end, initial_condition=x0, terminal_condition=slow_rotation) @@ -79,4 +97,4 @@ time /= 60 data = rad2deg.(data) -display(plot(time, data, title="DeTumbling", xlabel="Time (minutes)", ylabel="Angular Velocity (deg/s)", labels=["ω1" "ω2" "ω3" "ω"])) +display(plot(time, data, title="DeTumbling with (δ = $δ)", xlabel="Time (minutes)", ylabel="Angular Velocity (deg/s)", labels=["ω1" "ω2" "ω3" "ω"])) From e4bfce26712837ce349db99133fd8bf2b8305616 Mon Sep 17 00:00:00 2001 From: thetazero Date: Tue, 10 Oct 2023 15:50:24 -0400 Subject: [PATCH 2/2] fixes --- simulator_test/detumble.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/simulator_test/detumble.jl b/simulator_test/detumble.jl index 433a853..d881589 100644 --- a/simulator_test/detumble.jl +++ b/simulator_test/detumble.jl @@ -32,16 +32,18 @@ Detumble = Controller( py4_dipole_limits ) -δ=0.053130000000000004*0.01 +δ=0.053130000000000004*0.0002 +# δ=0.2 function saturate(x, r) if abs(x) <= δ - return r + return 0 elseif x > δ return r - else # x < -δ + elseif x < -δ return -r end + return 0 end function control_law(measurement, t) @@ -64,7 +66,7 @@ end -down_sample_rate = 100 +down_sample_rate = 10 function log_state(state) return [state.angular_velocity; norm(state.angular_velocity)]