Skip to content

Commit 0cac41e

Browse files
pejotejoJackyBloxx
andauthored
reintroduce node.rs (HULKs#2217)
* add noders to worldstate Co-authored-by: JackyBlox <90517319+JackyBloxx@users.noreply.github.com> * trying to make clippy happy --------- Co-authored-by: JackyBlox <90517319+JackyBloxx@users.noreply.github.com>
1 parent 0aa0f93 commit 0cac41e

5 files changed

Lines changed: 101 additions & 101 deletions

File tree

crates/hulk_manifest/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn collect_hulk_cyclers(root: impl AsRef<Path>) -> Result<Cyclers, Error> {
5252
nodes: vec![
5353
"world_state::ball_filter",
5454
"world_state::ball_projector",
55-
"world_state::behavior::walk_to_ball",
55+
"world_state::behavior::node",
5656
"world_state::camera_matrix_calculator",
5757
"world_state::game_controller_filter",
5858
"world_state::game_controller_state_filter",

crates/types/src/action.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use path_serde::{PathDeserialize, PathIntrospect, PathSerialize};
22
use serde::{Deserialize, Serialize};
33

4-
use crate::field_dimensions::Side;
5-
64
#[derive(
75
Debug,
86
Clone,
@@ -16,34 +14,5 @@ use crate::field_dimensions::Side;
1614
Eq,
1715
)]
1816
pub enum Action {
19-
Animation,
20-
Calibrate,
21-
DefendGoal,
22-
DefendKickOff,
23-
DefendLeft,
24-
DefendPenaltyKick,
25-
DefendRight,
26-
DefendOpponentCornerKick { side: Side },
27-
Dribble,
28-
FallSafely,
29-
Initial,
30-
InterceptBall,
31-
Jump,
32-
LookAround,
33-
LookAtReferee,
34-
NoGroundContact,
35-
Penalize,
36-
PrepareJump,
37-
Search,
38-
SearchForLostBall,
39-
SitDown,
40-
Stand,
41-
StandUp,
42-
KeeperMotion,
43-
SupportLeft,
44-
SupportRight,
45-
SupportStriker,
46-
Unstiff,
47-
WalkToKickOff,
48-
WalkToPenaltyKick,
17+
WalkToBall,
4918
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pub mod node;
12
pub mod walk_to_ball;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use color_eyre::Result;
2+
use serde::{Deserialize, Serialize};
3+
4+
use context_attribute::context;
5+
use coordinate_systems::Ground;
6+
use framework::{AdditionalOutput, MainOutput};
7+
use types::{
8+
action::Action, ball_position::BallPosition, motion_command::MotionCommand,
9+
parameters::WalkWithVelocityParameters,
10+
};
11+
12+
use crate::behavior::walk_to_ball;
13+
14+
#[derive(Deserialize, Serialize)]
15+
pub struct Behavior {}
16+
17+
#[context]
18+
pub struct CreationContext {}
19+
20+
#[context]
21+
pub struct CycleContext {
22+
ball_position: Input<Option<BallPosition<Ground>>, "ball_position?">,
23+
walk_with_velocity_parameter:
24+
Parameter<WalkWithVelocityParameters, "behavior.walk_with_velocity">,
25+
active_action_output: AdditionalOutput<Action, "active_action">,
26+
last_motion_command: CyclerState<MotionCommand, "last_motion_command">,
27+
}
28+
29+
#[context]
30+
#[derive(Default)]
31+
pub struct MainOutputs {
32+
pub motion_command: MainOutput<MotionCommand>,
33+
}
34+
35+
impl Behavior {
36+
pub fn new(_context: CreationContext) -> Result<Self> {
37+
Ok(Self {})
38+
}
39+
40+
pub fn cycle(&mut self, mut context: CycleContext) -> Result<MainOutputs> {
41+
#[allow(clippy::useless_vec, unused_mut)]
42+
let mut actions = vec![Action::WalkToBall];
43+
44+
let (action, motion_command) = actions
45+
.iter()
46+
.find_map(|action| {
47+
let motion_command = match action {
48+
Action::WalkToBall => walk_to_ball::execute(
49+
context.ball_position.copied(),
50+
context.walk_with_velocity_parameter.clone(),
51+
),
52+
}?;
53+
Some((action, motion_command))
54+
})
55+
.unwrap_or_else(|| panic!("there has to be at least one action available",));
56+
context.active_action_output.fill_if_subscribed(|| *action);
57+
58+
*context.last_motion_command = motion_command.clone();
59+
60+
Ok(MainOutputs {
61+
motion_command: motion_command.into(),
62+
})
63+
}
64+
}
Lines changed: 34 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,40 @@
11
use std::f32::consts::PI;
22

3-
use color_eyre::Result;
4-
use context_attribute::context;
53
use coordinate_systems::Ground;
6-
use framework::MainOutput;
74
use linear_algebra::{Rotation2, Vector2};
8-
use serde::{Deserialize, Serialize};
9-
use types::ball_position::BallPosition;
10-
use types::motion_command::{HeadMotion, ImageRegion, MotionCommand};
11-
use types::parameters::WalkWithVelocityParameters;
12-
13-
#[derive(Deserialize, Serialize)]
14-
pub struct WalkToBall {}
15-
16-
#[context]
17-
pub struct CreationContext {}
18-
19-
#[context]
20-
pub struct CycleContext {
21-
ball_position: Input<Option<BallPosition<Ground>>, "ball_position?">,
22-
23-
walk_with_velocity_parameter:
24-
Parameter<WalkWithVelocityParameters, "behavior.walk_with_velocity">,
25-
}
26-
27-
#[context]
28-
#[derive(Default)]
29-
pub struct MainOutputs {
30-
pub motion_command: MainOutput<MotionCommand>,
31-
}
32-
33-
impl WalkToBall {
34-
pub fn new(_context: CreationContext) -> Result<Self> {
35-
Ok(Self {})
36-
}
37-
38-
pub fn cycle(&mut self, context: CycleContext) -> Result<MainOutputs> {
39-
let next_motion_command = match context.ball_position {
40-
Some(ball_position) => {
41-
let ball_coordinates_in_ground = ball_position.position.coords();
42-
let head = HeadMotion::LookAt {
43-
target: ball_position.position,
44-
image_region_target: ImageRegion::Center,
45-
};
46-
let max_angular_velocity_abs = context
47-
.walk_with_velocity_parameter
48-
.max_angular_velocity
49-
.abs();
50-
let normalized_angle_to_ball =
51-
Rotation2::rotation_between(Vector2::x_axis(), ball_coordinates_in_ground)
52-
.angle()
53-
/ (0.5 * PI);
54-
MotionCommand::WalkWithVelocity {
55-
head,
56-
velocity: ball_coordinates_in_ground.normalize()
57-
* context.walk_with_velocity_parameter.max_velocity,
58-
angular_velocity: (normalized_angle_to_ball
59-
* context
60-
.walk_with_velocity_parameter
61-
.angular_velocity_scaling_factor)
62-
.clamp(-max_angular_velocity_abs, max_angular_velocity_abs),
63-
}
5+
use types::{
6+
ball_position::BallPosition,
7+
motion_command::{HeadMotion, ImageRegion, MotionCommand},
8+
parameters::WalkWithVelocityParameters,
9+
};
10+
11+
pub fn execute(
12+
ball_position: Option<BallPosition<Ground>>,
13+
walk_with_velocity_parameter: WalkWithVelocityParameters,
14+
) -> Option<MotionCommand> {
15+
let next_motion_command = match ball_position {
16+
Some(ball_position) => {
17+
let ball_coordinates_in_ground = ball_position.position.coords();
18+
let head = HeadMotion::LookAt {
19+
target: ball_position.position,
20+
image_region_target: ImageRegion::Center,
21+
};
22+
let max_angular_velocity_abs = walk_with_velocity_parameter.max_angular_velocity.abs();
23+
let normalized_angle_to_ball =
24+
Rotation2::rotation_between(Vector2::x_axis(), ball_coordinates_in_ground).angle()
25+
/ (0.5 * PI);
26+
MotionCommand::WalkWithVelocity {
27+
head,
28+
velocity: ball_coordinates_in_ground.normalize()
29+
* walk_with_velocity_parameter.max_velocity,
30+
angular_velocity: (normalized_angle_to_ball
31+
* walk_with_velocity_parameter.angular_velocity_scaling_factor)
32+
.clamp(-max_angular_velocity_abs, max_angular_velocity_abs),
6433
}
65-
None => MotionCommand::Stand {
66-
head: HeadMotion::Center,
67-
},
68-
};
69-
70-
Ok(MainOutputs {
71-
motion_command: next_motion_command.into(),
72-
})
73-
}
34+
}
35+
None => MotionCommand::Stand {
36+
head: HeadMotion::Center,
37+
},
38+
};
39+
Some(next_motion_command)
7440
}

0 commit comments

Comments
 (0)