From a22f6ea16c96f695165c98cd9b65f07f3682d1fa Mon Sep 17 00:00:00 2001
From: Michiel Cottaar <MichielCottaar@protonmail.com>
Date: Tue, 30 Jul 2024 16:38:01 +0100
Subject: [PATCH] Ensure slew rate cost function is always a number

---
 src/parts/trapezoids.jl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/parts/trapezoids.jl b/src/parts/trapezoids.jl
index c9f6b5b..ef33bbc 100644
--- a/src/parts/trapezoids.jl
+++ b/src/parts/trapezoids.jl
@@ -74,6 +74,7 @@ function (::Type{Trapezoid})(; orientation=nothing, rise_time=nothing, flat_time
             get_free_variable.(slew_rate),
             group
         )
+        add_cost_function!(-sum(abs(res.slew_rate)))
     else
         res = Trapezoid1D(
             get_free_variable(rise_time),
@@ -83,13 +84,13 @@ function (::Type{Trapezoid})(; orientation=nothing, rise_time=nothing, flat_time
             group
         )
         apply_simple_constraint!(res.slew_rate, :>=, 0)
+        add_cost_function!(-res.slew_rate)
     end
 
     set_simple_constraints!(res, kwargs)
 
     apply_simple_constraint!(res.flat_time, :>=, 0)
     apply_simple_constraint!(res.rise_time, :>=, 0)
-    add_cost_function!(-res.slew_rate)
     scanner_constraints!(res)
     return res
 end
-- 
GitLab