@@ -734,8 +734,10 @@ impl MoveSequence {
734
734
pub struct PrinterLimits {
735
735
pub max_velocity : f64 ,
736
736
pub max_acceleration : f64 ,
737
- #[ serde( flatten) ]
738
- pub max_accel_to_decel : AccelToDecel ,
737
+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
738
+ pub max_accel_to_decel : Option < f64 > ,
739
+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
740
+ pub minimum_cruise_ratio : Option < f64 > ,
739
741
pub square_corner_velocity : f64 ,
740
742
#[ serde( skip) ]
741
743
pub junction_deviation : f64 ,
@@ -749,29 +751,13 @@ pub struct PrinterLimits {
749
751
pub move_checkers : Vec < MoveChecker > ,
750
752
}
751
753
752
- #[ derive( Debug , Copy , Clone , Serialize , Deserialize , PartialEq ) ]
753
- pub enum AccelToDecel {
754
- #[ serde( rename = "max_accel_to_decel" ) ]
755
- Static ( f64 ) ,
756
- #[ serde( rename = "minimum_cruise_ratio" ) ]
757
- CruiseRatio ( f64 ) ,
758
- }
759
-
760
- impl AccelToDecel {
761
- pub fn to_absolute ( & self , accel : f64 ) -> f64 {
762
- match self {
763
- Self :: Static ( v) => v. min ( accel) ,
764
- Self :: CruiseRatio ( v) => accel * ( 1.0 - v. clamp ( 0.0 , 1.0 ) ) ,
765
- }
766
- }
767
- }
768
-
769
754
impl Default for PrinterLimits {
770
755
fn default ( ) -> Self {
771
756
PrinterLimits {
772
757
max_velocity : 100.0 ,
773
758
max_acceleration : 100.0 ,
774
- max_accel_to_decel : AccelToDecel :: Static ( 50.0 ) ,
759
+ max_accel_to_decel : Some ( 50.0 ) ,
760
+ minimum_cruise_ratio : None ,
775
761
square_corner_velocity : 5.0 ,
776
762
junction_deviation : Self :: scv_to_jd ( 5.0 , 100000.0 ) ,
777
763
accel_to_decel : 50.0 ,
@@ -796,15 +782,18 @@ impl PrinterLimits {
796
782
pub fn set_max_acceleration ( & mut self , v : f64 ) {
797
783
self . max_acceleration = v;
798
784
self . update_junction_deviation ( ) ;
785
+ self . update_accel_to_decel ( ) ;
799
786
}
800
787
801
788
pub fn set_max_accel_to_decel ( & mut self , v : f64 ) {
802
- self . max_accel_to_decel = AccelToDecel :: Static ( v) ;
789
+ self . max_accel_to_decel = Some ( v) ;
790
+ self . minimum_cruise_ratio = None ;
803
791
self . update_accel_to_decel ( ) ;
804
792
}
805
793
806
794
pub fn set_minimum_cruise_ratio ( & mut self , v : f64 ) {
807
- self . max_accel_to_decel = AccelToDecel :: CruiseRatio ( v. clamp ( 0.0 , 1.0 ) ) ;
795
+ self . max_accel_to_decel = None ;
796
+ self . minimum_cruise_ratio = Some ( v. clamp ( 0.0 , 1.0 ) ) ;
808
797
self . update_accel_to_decel ( ) ;
809
798
}
810
799
@@ -828,7 +817,11 @@ impl PrinterLimits {
828
817
}
829
818
830
819
fn update_accel_to_decel ( & mut self ) {
831
- self . accel_to_decel = self . max_accel_to_decel . to_absolute ( self . max_acceleration ) ;
820
+ self . accel_to_decel = match ( self . minimum_cruise_ratio , self . max_accel_to_decel ) {
821
+ ( Some ( v) , _) => self . max_acceleration * ( 1.0 - v. clamp ( 0.0 , 1.0 ) ) ,
822
+ ( _, Some ( v) ) => v. min ( self . max_acceleration ) ,
823
+ _ => 50.0f64 . min ( self . max_acceleration ) ,
824
+ }
832
825
}
833
826
}
834
827
0 commit comments