1- use color_eyre:: { eyre :: WrapErr , Result } ;
1+ use color_eyre:: Result ;
22use context_attribute:: context;
3- use framework:: { MainOutput , PerceptionInput } ;
3+ use coordinate_systems:: Ground ;
4+ use framework:: MainOutput ;
45use serde:: { Deserialize , Serialize } ;
5- use types:: cycle_time:: CycleTime ;
6- use types:: world_state:: BallState ;
7- use types:: {
8- camera_position:: CameraPosition ,
9- motion_command:: { HeadMotion , ImageRegion , MotionCommand } ,
10- parameters:: DribblingParameters ,
11- world_state:: WorldState ,
12- } ;
6+ use types:: ball_position:: BallPosition ;
7+ use types:: motion_command:: { HeadMotion , ImageRegion , MotionCommand } ;
138
149#[ derive( Deserialize , Serialize ) ]
1510pub struct WalkToBall { }
@@ -19,11 +14,7 @@ pub struct CreationContext {}
1914
2015#[ context]
2116pub struct CycleContext {
22- cycle_time : Input < CycleTime , "cycle_time" > ,
23- world_state : Input < WorldState , "world_state" > ,
24- ball_state : Input < BallState , "World_state" , "ball_state" > ,
25- // dribble_walk_speed: Parameter<WalkSpeed, "walk_speed.dribble">,
26- // parameters: Parameter<BehaviorParameters, "behavior">,
17+ ball_position : Input < Option < BallPosition < Ground > > , "World_state" , "ball_position" > ,
2718}
2819
2920#[ context]
@@ -38,20 +29,26 @@ impl WalkToBall {
3829 }
3930
4031 pub fn cycle ( & mut self , context : CycleContext ) -> Result < MainOutputs > {
41- let ball_position = context. ball_state . ball_in_ground ;
42- let head = HeadMotion :: LookAt {
43- target : ball_position,
44- image_region_target : ImageRegion :: Center ,
45- camera : Some ( CameraPosition :: Bottom ) ,
32+ let next_motion_command = match context. ball_position {
33+ Some ( ball_position) => {
34+ let ball_coordinates_in_ground = ball_position. position . coords ( ) ;
35+ let head = HeadMotion :: LookAt {
36+ target : ball_coordinates_in_ground. as_point ( ) ,
37+ image_region_target : ImageRegion :: Center ,
38+ } ;
39+ MotionCommand :: WalkWithVelocity {
40+ head,
41+ velocity : ball_coordinates_in_ground. normalize ( ) * 0.1 , // TODO: parameterize
42+ angular_velocity : ball_coordinates_in_ground. y ( ) . clamp ( -0.25 , 0.25 ) , // TODO: parameterize
43+ }
44+ }
45+ None => MotionCommand :: Stand {
46+ head : HeadMotion :: LookAround ,
47+ } ,
4648 } ;
4749
4850 Ok ( MainOutputs {
49- motion_command : MotionCommand :: WalkWithVelocity {
50- head,
51- velocity : ball_position. coords ( ) . normalize ( ) * 0.1 ,
52- angular_velocity : ball_position. coords ( ) . y ( ) . clamp ( -0.25 , 0.25 ) , // TODO: parameterize
53- }
54- . into ( ) ,
51+ motion_command : next_motion_command. into ( ) ,
5552 } )
5653 }
5754}
0 commit comments