1- use std:: cmp:: Ordering ;
1+ use std:: { cmp:: Ordering , time :: Duration } ;
22
33use color_eyre:: Result ;
44use itertools:: iproduct;
55use serde:: { Deserialize , Serialize } ;
66
77use context_attribute:: context;
8- use coordinate_systems:: { Field , Ground , UpcomingSupport } ;
8+ use coordinate_systems:: { Field , Ground , Robot , UpcomingSupport } ;
99use framework:: { AdditionalOutput , MainOutput } ;
1010use geometry:: { circle:: Circle , line_segment:: LineSegment , look_at:: LookAt } ;
1111use linear_algebra:: {
12- distance, point, vector, IntoFramed , Isometry2 , Orientation2 , Point , Point2 , Pose2 , Rotation2 ,
13- Vector2 ,
12+ distance, point, vector, IntoFramed , Isometry2 , Isometry3 , Orientation2 , Orientation3 , Point ,
13+ Point2 , Point3 , Pose2 , Rotation2 , Vector2 , Vector3 ,
1414} ;
1515use spl_network_messages:: { GamePhase , SubState , Team } ;
1616use types:: {
17+ cycle_time:: CycleTime ,
1718 field_dimensions:: { self , FieldDimensions , Half } ,
1819 filtered_game_controller_state:: FilteredGameControllerState ,
1920 filtered_game_state:: FilteredGameState ,
21+ joints:: body:: BodyJoints ,
2022 kick_decision:: { DecisionParameters , KickDecision , PlayingSituation } ,
2123 motion_command:: { KickVariant , OrientationMode , WalkSpeed } ,
24+ obstacle_avoiding_arms:: ArmCommands ,
2225 obstacles:: Obstacle ,
2326 parameters:: { InWalkKickInfoParameters , InWalkKicksParameters , StepPlannerParameters } ,
2427 planned_path:: direct_path,
28+ sensor_data:: SensorData ,
2529 support_foot:: Side ,
2630 world_state:: BallState ,
2731} ;
28- use walking_engine:: mode:: Mode ;
32+ use walking_engine:: {
33+ kick_steps:: KickSteps , mode:: Mode , parameters:: Parameters , step_plan:: StepPlan , Context ,
34+ } ;
2935
3036use crate :: motion:: step_planner:: step_plan_greedy;
3137
@@ -48,10 +54,21 @@ pub struct CycleContext {
4854
4955 decision_parameters : Parameter < DecisionParameters , "kick_selector" > ,
5056 step_planner_parameters : Parameter < StepPlannerParameters , "step_planner" > ,
57+ kick_steps : Parameter < KickSteps , "kick_steps" > ,
58+ walking_engine_parameters : Parameter < Parameters , "walking_engine" > ,
5159 field_dimensions : Parameter < FieldDimensions , "field_dimensions" > ,
5260 in_walk_kicks : Parameter < InWalkKicksParameters , "in_walk_kicks" > ,
5361 dribble_walk_speed : Parameter < WalkSpeed , "walk_speed.dribble" > ,
5462
63+ cycle_time : Input < CycleTime , "cycle_time" > ,
64+ center_of_mass : Input < Point3 < Robot > , "center_of_mass" > ,
65+ sensor_data : Input < SensorData , "sensor_data" > ,
66+ robot_to_ground : Input < Option < Isometry3 < Robot , Ground > > , "robot_to_ground?" > ,
67+ robot_orientation : RequiredInput < Option < Orientation3 < Field > > , "robot_orientation?" > ,
68+ zero_moment_point : Input < Point2 < Ground > , "zero_moment_point" > ,
69+ number_of_consecutive_cycles_zero_moment_point_outside_support_polygon :
70+ Input < i32 , "number_of_consecutive_cycles_zero_moment_point_outside_support_polygon" > ,
71+
5572 playing_situation : AdditionalOutput < PlayingSituation , "playing_situation" > ,
5673}
5774
@@ -116,12 +133,46 @@ impl KickSelector {
116133 context. in_walk_kicks ,
117134 ) ;
118135
136+ let arm_compensation = 0.0 ;
137+ let step_compensation = 0.0 ;
138+ let robot_to_walk = Isometry3 :: from_parts (
139+ vector ! [
140+ context. walking_engine_parameters. base. torso_offset,
141+ 0.0 ,
142+ context. walking_engine_parameters. base. walk_height,
143+ ] ,
144+ Orientation3 :: new (
145+ Vector3 :: y_axis ( )
146+ * ( context. walking_engine_parameters . base . torso_tilt_base
147+ + step_compensation
148+ + arm_compensation) ,
149+ ) ,
150+ ) ;
151+ let walking_engine_context = Context {
152+ parameters : context. walking_engine_parameters ,
153+ max_step_size : & context. step_planner_parameters . max_step_size ,
154+ kick_steps : context. kick_steps ,
155+ cycle_time : context. cycle_time ,
156+ center_of_mass : context. center_of_mass ,
157+ force_sensitive_resistors : & context. sensor_data . force_sensitive_resistors ,
158+ robot_orientation : context. robot_orientation ,
159+ robot_to_ground : context. robot_to_ground ,
160+ gyro : nalgebra:: Vector3 :: zeros ( ) ,
161+ last_actuated_joints : BodyJoints :: default ( ) ,
162+ measured_joints : context. sensor_data . positions . into ( ) ,
163+ robot_to_walk,
164+ obstacle_avoiding_arms : & ArmCommands :: default ( ) ,
165+ zero_moment_point : context. zero_moment_point ,
166+ number_of_consecutive_cycles_zero_moment_point_outside_support_polygon : context
167+ . number_of_consecutive_cycles_zero_moment_point_outside_support_polygon ,
168+ } ;
169+
119170 let step_plans: Vec < _ > = kick_decisions
120171 . iter ( )
121172 . map ( |kick_decision| {
122173 let kick_pose_in_upcoming_support_ground =
123174 * context. ground_to_upcoming_support * kick_decision. kick_pose ;
124- step_plan_greedy (
175+ let step_plan = step_plan_greedy (
125176 & direct_path (
126177 Point2 :: origin ( ) ,
127178 kick_pose_in_upcoming_support_ground. position ( ) ,
@@ -132,7 +183,30 @@ impl KickSelector {
132183 OrientationMode :: Override ( kick_pose_in_upcoming_support_ground. orientation ( ) ) ,
133184 * context. dribble_walk_speed ,
134185 )
135- . unwrap ( )
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)
136210 } )
137211 . collect ( ) ;
138212 dbg ! ( step_plans) ;
0 commit comments