Skip to content

Commit 5e6328a

Browse files
authored
Initial side step fix (#1808)
* remove fuckup * initial side_bonus only after zero step * intitial side bonus only if step before was zero, additional output, use variable max_step_size in path filtering
1 parent b777f62 commit 5e6328a

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

crates/control/src/motion/step_planner.rs

+30-27
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub struct CycleContext {
4343

4444
ground_to_upcoming_support_out:
4545
AdditionalOutput<Isometry2<Ground, UpcomingSupport>, "ground_to_upcoming_support">,
46+
max_step_size_output: AdditionalOutput<Step, "max_step_size">,
4647
}
4748

4849
#[context]
@@ -64,6 +65,7 @@ impl StepPlanner {
6465
} else {
6566
None
6667
};
68+
6769
let (max_turn_left, max_turn_right) = if let Some(support_side) = support_side {
6870
if support_side == Side::Left {
6971
(-*context.max_inside_turn, context.max_step_size.turn)
@@ -87,20 +89,41 @@ impl StepPlanner {
8789
} => (path, orientation_mode, speed),
8890
_ => {
8991
return Ok(MainOutputs {
90-
planned_step: Step {
91-
forward: 0.0,
92-
left: 0.0,
93-
turn: 0.0,
94-
}
95-
.into(),
92+
planned_step: Step::default().into(),
9693
})
9794
}
9895
};
9996

97+
let initial_side_bonus = if self.last_planned_step.forward.abs()
98+
+ self.last_planned_step.left.abs()
99+
+ self.last_planned_step.turn.abs()
100+
<= f32::EPSILON
101+
{
102+
Step {
103+
forward: 0.0,
104+
left: *context.initial_side_bonus,
105+
turn: 0.0,
106+
}
107+
} else {
108+
Step::default()
109+
};
110+
111+
let max_step_size = match speed {
112+
WalkSpeed::Slow => *context.max_step_size + *context.step_size_delta_slow,
113+
WalkSpeed::Normal => *context.max_step_size + initial_side_bonus,
114+
WalkSpeed::Fast => {
115+
*context.max_step_size + *context.step_size_delta_fast + initial_side_bonus
116+
}
117+
};
118+
119+
context
120+
.max_step_size_output
121+
.fill_if_subscribed(|| max_step_size);
122+
100123
let segment = path
101124
.iter()
102125
.scan(0.0f32, |distance, segment| {
103-
let result = if *distance < context.max_step_size.forward {
126+
let result = if *distance < max_step_size.forward {
104127
Some(segment)
105128
} else {
106129
None
@@ -161,25 +184,6 @@ impl StepPlanner {
161184
step = *injected_step;
162185
}
163186

164-
let initial_side_bonus = if self.last_planned_step.left.abs() <= f32::EPSILON {
165-
Step {
166-
forward: 0.0,
167-
left: *context.initial_side_bonus,
168-
turn: 0.0,
169-
}
170-
} else {
171-
Step::default()
172-
};
173-
step += initial_side_bonus;
174-
175-
let max_step_size = match speed {
176-
WalkSpeed::Slow => *context.max_step_size + *context.step_size_delta_slow,
177-
WalkSpeed::Normal => *context.max_step_size + initial_side_bonus,
178-
WalkSpeed::Fast => {
179-
*context.max_step_size + *context.step_size_delta_fast + initial_side_bonus
180-
}
181-
};
182-
183187
let step = clamp_step_to_walk_volume(
184188
step,
185189
&max_step_size,
@@ -210,7 +214,6 @@ fn clamp_step_to_walk_volume(
210214
// Values in range [-1..1]
211215
let clamped_turn = request.turn.clamp(max_turn_left, max_turn_right);
212216

213-
// let =
214217
let request = Step {
215218
forward: request.forward,
216219
left: request.left,

0 commit comments

Comments
 (0)