File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -265,9 +265,9 @@ where
265265 }
266266}
267267
268- /// Saturating the input `value` according the absolute `limit` (`-limit <= output <= limit`).
268+ /// Saturating the input `value` according the absolute `limit` (`-abs( limit) <= output <= abs( limit) `).
269269fn apply_limit < T : Number > ( limit : T , value : T ) -> T {
270- num_traits:: clamp ( value, -limit, limit)
270+ num_traits:: clamp ( value, -limit. abs ( ) , limit. abs ( ) )
271271}
272272
273273#[ cfg( test) ]
@@ -442,4 +442,17 @@ mod tests {
442442 }
443443 ) ;
444444 }
445+
446+ /// Make sure negative limits don't break the controller
447+ #[ test]
448+ fn negative_limits ( ) {
449+ let mut pid = Pid :: new ( 10.0f32 , -10.0 ) ;
450+ pid. p ( 1.0 , -50.0 ) . i ( 1.0 , -50.0 ) . d ( 1.0 , -50.0 ) ;
451+
452+ let out = pid. next_control_output ( 0.0 ) ;
453+ assert_eq ! ( out. p, 10.0 ) ;
454+ assert_eq ! ( out. i, 10.0 ) ;
455+ assert_eq ! ( out. d, 0.0 ) ;
456+ assert_eq ! ( out. output, 10.0 ) ;
457+ }
445458}
You can’t perform that action at this time.
0 commit comments