Skip to content

Commit ba2c43d

Browse files
committed
Use time to reach kick pose for sorting
1 parent 0f3c125 commit ba2c43d

File tree

3 files changed

+75
-69
lines changed

3 files changed

+75
-69
lines changed

crates/control/src/kick_selector.rs

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ use types::{
2626
parameters::{InWalkKickInfoParameters, InWalkKicksParameters, StepPlannerParameters},
2727
planned_path::direct_path,
2828
sensor_data::SensorData,
29+
step::Step,
2930
support_foot::Side,
3031
world_state::BallState,
3132
};
3233
use walking_engine::{
33-
kick_steps::KickSteps, mode::Mode, parameters::Parameters, step_plan::StepPlan, Context,
34+
kick_steps::KickSteps, mode::Mode, parameters::Parameters, step_plan::StepPlan,
35+
step_state::StepState, Context,
3436
};
3537

3638
use crate::motion::step_planner::step_plan_greedy;
@@ -64,7 +66,6 @@ pub struct CycleContext {
6466
center_of_mass: Input<Point3<Robot>, "center_of_mass">,
6567
sensor_data: Input<SensorData, "sensor_data">,
6668
robot_to_ground: Input<Option<Isometry3<Robot, Ground>>, "robot_to_ground?">,
67-
robot_orientation: RequiredInput<Option<Orientation3<Field>>, "robot_orientation?">,
6869
zero_moment_point: Input<Point2<Ground>, "zero_moment_point">,
6970
number_of_consecutive_cycles_zero_moment_point_outside_support_polygon:
7071
Input<i32, "number_of_consecutive_cycles_zero_moment_point_outside_support_polygon">,
@@ -148,17 +149,17 @@ impl KickSelector {
148149
+ arm_compensation),
149150
),
150151
);
151-
let walking_engine_context = Context {
152+
let mut walking_engine_context = Context {
152153
parameters: context.walking_engine_parameters,
153154
max_step_size: &context.step_planner_parameters.max_step_size,
154155
kick_steps: context.kick_steps,
155156
cycle_time: context.cycle_time,
156157
center_of_mass: context.center_of_mass,
157158
force_sensitive_resistors: &context.sensor_data.force_sensitive_resistors,
158-
robot_orientation: context.robot_orientation,
159+
robot_orientation: &Orientation3::default(),
159160
robot_to_ground: context.robot_to_ground,
160161
gyro: nalgebra::Vector3::zeros(),
161-
last_actuated_joints: BodyJoints::default(),
162+
last_actuated_joints: BodyJoints::default(), // TODO: Crude approximation
162163
measured_joints: context.sensor_data.positions.into(),
163164
robot_to_walk,
164165
obstacle_avoiding_arms: &ArmCommands::default(),
@@ -167,56 +168,60 @@ impl KickSelector {
167168
.number_of_consecutive_cycles_zero_moment_point_outside_support_polygon,
168169
};
169170

170-
let step_plans: Vec<_> = kick_decisions
171-
.iter()
172-
.map(|kick_decision| {
173-
let kick_pose_in_upcoming_support_ground =
174-
*context.ground_to_upcoming_support * kick_decision.kick_pose;
175-
let step_plan = step_plan_greedy(
176-
&direct_path(
177-
Point2::origin(),
178-
kick_pose_in_upcoming_support_ground.position(),
179-
),
180-
context.step_planner_parameters,
181-
Pose2::zero(),
182-
*context.walking_engine_mode,
183-
OrientationMode::Override(kick_pose_in_upcoming_support_ground.orientation()),
184-
*context.dribble_walk_speed,
185-
)
186-
.unwrap();
187-
188-
let support_side = context
189-
.walking_engine_mode
190-
.support_side()
191-
.unwrap_or(Side::Left);
192-
let walk_duration: Duration = step_plan
193-
.iter()
194-
.map(|step| {
195-
let step_plan = StepPlan::new_from_request(
196-
&walking_engine_context,
197-
*step,
198-
support_side,
199-
);
200-
step_plan.step_duration
201-
})
202-
.sum();
203-
204-
let distance = distance_to_kick_pose(
205-
*context.ground_to_upcoming_support * kick_decision.kick_pose,
206-
context.decision_parameters.angle_distance_weight,
207-
);
208-
209-
(distance, walk_duration)
210-
})
211-
.collect();
212-
dbg!(step_plans);
171+
let step = match *context.walking_engine_mode {
172+
Mode::Walking(walking) => walking.requested_step,
173+
_ => Step::default(),
174+
};
175+
let current_support_side = context
176+
.walking_engine_mode
177+
.support_side()
178+
.unwrap_or(Side::Left);
179+
let step_plan =
180+
StepPlan::new_from_request(&walking_engine_context, step, current_support_side);
181+
182+
walking_engine_context.last_actuated_joints =
183+
calculate_joints_at_end_of_step(step_plan, &walking_engine_context);
184+
185+
let rate_kick_decision = |kick_decision: &KickDecision| {
186+
let kick_pose_in_upcoming_support_ground =
187+
*context.ground_to_upcoming_support * kick_decision.kick_pose;
188+
let step_plan = step_plan_greedy(
189+
&direct_path(
190+
Point2::origin(),
191+
kick_pose_in_upcoming_support_ground.position(),
192+
),
193+
context.step_planner_parameters,
194+
Pose2::zero(),
195+
current_support_side.opposite(),
196+
OrientationMode::Override(kick_pose_in_upcoming_support_ground.orientation()),
197+
*context.dribble_walk_speed,
198+
)
199+
.unwrap();
200+
let mut walking_engine_context = walking_engine_context.clone();
201+
let walk_duration: Duration = step_plan
202+
.iter()
203+
.map(|(step, support_side)| {
204+
let step_plan =
205+
StepPlan::new_from_request(&walking_engine_context, *step, *support_side);
206+
walking_engine_context.last_actuated_joints =
207+
calculate_joints_at_end_of_step(step_plan, &walking_engine_context);
208+
step_plan.step_duration
209+
})
210+
.sum();
211+
212+
walk_duration
213+
};
214+
215+
// let step_plans: Vec<_> = kick_decisions.iter().map(rate_kick_decision).collect();
216+
// dbg!(step_plans);
213217

214218
kick_decisions.sort_by(|left, right| {
215219
compare_decisions(
216220
left,
217221
right,
222+
rate_kick_decision(left),
223+
rate_kick_decision(right),
218224
ball_position,
219-
*context.ground_to_upcoming_support,
220225
context.obstacles,
221226
context.decision_parameters,
222227
)
@@ -236,8 +241,9 @@ impl KickSelector {
236241
compare_decisions(
237242
left,
238243
right,
244+
rate_kick_decision(left),
245+
rate_kick_decision(right),
239246
ball_position,
240-
*context.ground_to_upcoming_support,
241247
context.obstacles,
242248
context.decision_parameters,
243249
)
@@ -250,6 +256,16 @@ impl KickSelector {
250256
}
251257
}
252258

259+
fn calculate_joints_at_end_of_step(
260+
step_plan: StepPlan,
261+
walking_engine_context: &Context<'_>,
262+
) -> BodyJoints {
263+
let mut step_state = StepState::new(step_plan);
264+
step_state.time_since_start = step_plan.step_duration;
265+
266+
step_state.compute_joints(walking_engine_context)
267+
}
268+
253269
fn is_ball_in_opponents_corners(
254270
ball_position: Point2<Field>,
255271
field_dimensions: &FieldDimensions,
@@ -374,8 +390,9 @@ fn generate_penalty_shot_kick_targets(context: &CycleContext) -> Vec<Point2<Grou
374390
fn compare_decisions(
375391
left: &KickDecision,
376392
right: &KickDecision,
393+
time_to_reach_left: Duration,
394+
time_to_reach_right: Duration,
377395
ball_position: Point2<Ground>,
378-
ground_to_upcoming_support: Isometry2<Ground, UpcomingSupport>,
379396
obstacles: &[Obstacle],
380397
parameters: &DecisionParameters,
381398
) -> Ordering {
@@ -385,14 +402,6 @@ fn compare_decisions(
385402
is_intersecting_with_an_obstacle(obstacles, ball_position, left.target, parameters);
386403
let right_is_intersecting_with_obstacle =
387404
is_intersecting_with_an_obstacle(obstacles, ball_position, right.target, parameters);
388-
let distance_to_left = distance_to_kick_pose(
389-
ground_to_upcoming_support * left.kick_pose,
390-
parameters.angle_distance_weight,
391-
);
392-
let distance_to_right = distance_to_kick_pose(
393-
ground_to_upcoming_support * right.kick_pose,
394-
parameters.angle_distance_weight,
395-
);
396405

397406
match (
398407
left_in_obstacle,
@@ -404,7 +413,7 @@ fn compare_decisions(
404413
(true, false, _, _) => Ordering::Greater,
405414
(_, _, false, true) => Ordering::Less,
406415
(_, _, true, false) => Ordering::Greater,
407-
_ => distance_to_left.total_cmp(&distance_to_right),
416+
_ => time_to_reach_left.cmp(&time_to_reach_right),
408417
}
409418
}
410419

crates/control/src/motion/step_planner.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,13 @@ pub fn step_plan_greedy<Frame>(
206206
path: &[PathSegment<Frame>],
207207
parameters: &StepPlannerParameters,
208208
mut pose: Pose2<Frame>,
209-
walking_engine_mode: Mode,
209+
initial_support_side: Side,
210210
orientation_mode: OrientationMode<Frame>,
211211
speed: WalkSpeed,
212-
) -> Result<Vec<Step>> {
212+
) -> Result<Vec<(Step, Side)>> {
213213
let mut steps = Vec::new();
214214
let mut last_planned_step = Step::default();
215-
let mut support_side = walking_engine_mode
216-
.support_side()
217-
.unwrap_or(Side::Left)
218-
.opposite();
215+
let mut support_side = initial_support_side;
219216

220217
let destination = match path.last() {
221218
Some(PathSegment::Arc(arc)) => arc.end_point(),
@@ -278,10 +275,9 @@ pub fn step_plan_greedy<Frame>(
278275

279276
pose = pose.as_transform() * step_rotation * step_translation.as_pose();
280277
last_planned_step = step;
278+
steps.push((step, support_side));
281279
support_side = support_side.opposite();
282280

283-
steps.push(step);
284-
285281
if (destination - pose.position()).norm_squared() > 0.01 {
286282
continue;
287283
}

crates/walking_engine/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ pub mod kick_steps;
2323
pub mod mode;
2424
pub mod parameters;
2525
pub mod step_plan;
26-
mod step_state;
26+
pub mod step_state;
2727
mod stiffness;
2828

2929
/// # WalkingEngine
3030
/// This node generates foot positions and thus leg angles for the robot to execute a walk.
3131
/// The algorithm to compute the feet trajectories is loosely based on the work of Bernhard Hengst
3232
/// at the team rUNSWift. An explanation of this algorithm can be found in the team's research
3333
/// report from 2014 (<http://cgi.cse.unsw.edu.au/~robocup/2014ChampionTeamPaperReports/20140930-Bernhard.Hengst-Walk2014Report.pdf>).
34+
#[derive(Debug, Clone)]
3435
pub struct Context<'a> {
3536
pub parameters: &'a Parameters,
3637
pub max_step_size: &'a Step,

0 commit comments

Comments
 (0)