@@ -71,15 +71,20 @@ impl StepPlanning<'_> {
7171
7272 let progress = self . path . progress ( pose. position ) ;
7373 let path_length = self . path . length ( ) ;
74+ let distance_to_target = path_length - progress;
75+ let target_alignment_importance = self . target_alignment_importance ( distance_to_target) ;
76+ let walk_alignment_importance = 1.0 - target_alignment_importance;
7477
7578 let path_progress_cost =
7679 self . path_progress ( ) . cost ( progress, path_length) * cost_factors. path_progress ;
7780 let path_distance_cost =
7881 self . path_distance ( ) . cost ( pose. position ) * cost_factors. path_distance ;
79- let walk_orientation_cost =
80- self . walk_orientation ( ) . cost ( pose. clone ( ) ) * cost_factors. walk_orientation ;
81- let target_orientation_cost = self . target_orientation ( ) . cost ( pose, progress, path_length)
82- * cost_factors. target_orientation ;
82+ let walk_orientation_cost = self . walk_orientation ( ) . cost ( pose. clone ( ) )
83+ * cost_factors. walk_orientation
84+ * walk_alignment_importance;
85+ let target_orientation_cost = self . target_orientation ( ) . cost ( pose)
86+ * cost_factors. target_orientation
87+ * target_alignment_importance;
8388
8489 path_progress_cost + path_distance_cost + walk_orientation_cost + target_orientation_cost
8590 }
@@ -90,16 +95,20 @@ impl StepPlanning<'_> {
9095 let progress = self . path . progress ( pose. position ) ;
9196 let forward = self . path . forward ( pose. position ) ;
9297 let path_length = self . path . length ( ) ;
98+ let distance_to_target = path_length - progress;
99+ let target_alignment_importance = self . target_alignment_importance ( distance_to_target) ;
100+ let walk_alignment_importance = 1.0 - target_alignment_importance;
93101
94102 let path_progress_gradient =
95103 self . path_progress ( ) . grad ( progress, forward, path_length) * cost_factors. path_progress ;
96104 let path_distance_gradient =
97105 self . path_distance ( ) . grad ( pose. position ) * cost_factors. path_distance ;
98- let walk_orientation_gradient =
99- self . walk_orientation ( ) . grad ( pose. clone ( ) ) * cost_factors. walk_orientation ;
100- let target_orientation_gradient =
101- self . target_orientation ( ) . grad ( pose, progress, path_length)
102- * cost_factors. target_orientation ;
106+ let walk_orientation_gradient = self . walk_orientation ( ) . grad ( pose. clone ( ) )
107+ * cost_factors. walk_orientation
108+ * walk_alignment_importance;
109+ let target_orientation_gradient = self . target_orientation ( ) . grad ( pose)
110+ * cost_factors. target_orientation
111+ * target_alignment_importance;
103112
104113 PoseGradient {
105114 position : path_progress_gradient + path_distance_gradient,
@@ -108,6 +117,14 @@ impl StepPlanning<'_> {
108117 + target_orientation_gradient
109118 }
110119
120+ // https://www.desmos.com/calculator/mzuvbmrxym
121+ fn target_alignment_importance ( & self , distance_to_target : f32 ) -> f32 {
122+ ( 1.0 - f32:: tanh (
123+ ( distance_to_target - self . parameters . alignment_start_distance )
124+ * self . parameters . alignment_ramp_steepness ,
125+ ) ) / 2.0
126+ }
127+
111128 fn path_distance ( & self ) -> PathDistanceField < ' _ > {
112129 PathDistanceField { path : self . path }
113130 }
@@ -127,8 +144,6 @@ impl StepPlanning<'_> {
127144 fn target_orientation ( & self ) -> TargetOrientationField {
128145 TargetOrientationField {
129146 target_orientation : Angle ( self . target_orientation . angle ( ) ) ,
130- alignment_start_distance : self . parameters . alignment_start_distance ,
131- ramp_width : self . parameters . alignment_start_smoothness ,
132147 }
133148 }
134149}
0 commit comments