Skip to content

Commit 560c271

Browse files
authored
Stand up slowly (#1900)
* added stand_up_count to world.state and to stand_up.rs * edit aditional autput and CyclerState * edit match statement for slower motions * added slow_speed in Motion_command * edit facing up * build new Slow Motions Types * changed from bool to enum * cleaned up * fixed it * edit speed_factor * changed fast to deafult * made the Match statemant better and cleaner * deletet the aditional output
1 parent 92e678c commit 560c271

16 files changed

Lines changed: 353 additions & 16 deletions
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
use types::{fall_state::FallState, motion_command::MotionCommand, world_state::WorldState};
1+
use types::{
2+
fall_state::{FallState, Kind, StandUpSpeed},
3+
motion_command::MotionCommand,
4+
world_state::WorldState,
5+
};
26

37
pub fn execute(world_state: &WorldState) -> Option<MotionCommand> {
4-
match world_state.robot.fall_state {
5-
FallState::Fallen { kind } => Some(MotionCommand::StandUp { kind }),
6-
FallState::StandingUp { kind, .. } => Some(MotionCommand::StandUp { kind }),
7-
_ => None,
8-
}
8+
let kind = match world_state.robot.fall_state {
9+
FallState::Fallen { kind } => kind,
10+
FallState::StandingUp { kind, .. } => kind,
11+
_ => return None,
12+
};
13+
let speed = match (kind, world_state.robot.stand_up_count) {
14+
(_, 0) => StandUpSpeed::Default,
15+
(Kind::Sitting, 1) => StandUpSpeed::Default,
16+
(Kind::Sitting, _) => StandUpSpeed::Slow,
17+
(Kind::FacingDown, _) => StandUpSpeed::Slow,
18+
(Kind::FacingUp, _) => StandUpSpeed::Default,
19+
};
20+
Some(MotionCommand::StandUp { kind, speed })
921
}

crates/control/src/localization.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ pub struct CycleContext {
110110
CyclerState<RemainingStandUpDuration, "stand_up_front_estimated_remaining_duration">,
111111
stand_up_sitting_estimated_remaining_duration:
112112
CyclerState<RemainingStandUpDuration, "stand_up_sitting_estimated_remaining_duration">,
113+
stand_up_front_slow_estimated_remaining_duration:
114+
CyclerState<RemainingStandUpDuration, "stand_up_front_slow_estimated_remaining_duration">,
115+
stand_up_sitting_slow_estimated_remaining_duration:
116+
CyclerState<RemainingStandUpDuration, "stand_up_sitting_slow_estimated_remaining_duration">,
113117
cycle_time: Input<CycleTime, "cycle_time">,
114118
}
115119

@@ -308,6 +312,12 @@ impl Localization {
308312
.is_running()
309313
|| context
310314
.stand_up_sitting_estimated_remaining_duration
315+
.is_running()
316+
|| context
317+
.stand_up_front_slow_estimated_remaining_duration
318+
.is_running()
319+
|| context
320+
.stand_up_sitting_slow_estimated_remaining_duration
311321
.is_running();
312322

313323
context.measured_lines_in_field.fill_if_subscribed(Vec::new);

crates/control/src/motion/dispatching_interpolator.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub struct CycleContext {
3737
stand_up_back_positions: Input<Joints<f32>, "stand_up_back_positions">,
3838
stand_up_front_positions: Input<Joints<f32>, "stand_up_front_positions">,
3939
stand_up_sitting_positions: Input<Joints<f32>, "stand_up_sitting_positions">,
40+
stand_up_front_slow_positions: Input<Joints<f32>, "stand_up_front_slow_positions">,
41+
stand_up_sitting_slow_positions: Input<Joints<f32>, "stand_up_sitting_slow_positions">,
4042
wide_stance_positions: Input<Joints<f32>, "wide_stance_positions">,
4143
keeper_jump_left_motor_commands:
4244
Input<MotorCommands<Joints<f32>>, "keeper_jump_left_motor_commands">,
@@ -111,6 +113,8 @@ impl DispatchingInterpolator {
111113
MotionType::StandUpBack => *context.stand_up_back_positions,
112114
MotionType::StandUpFront => *context.stand_up_front_positions,
113115
MotionType::StandUpSitting => *context.stand_up_sitting_positions,
116+
MotionType::StandUpFrontSlow => *context.stand_up_front_slow_positions,
117+
MotionType::StandUpSittingSlow => *context.stand_up_sitting_slow_positions,
114118
MotionType::WideStance => *context.wide_stance_positions,
115119
MotionType::KeeperJumpLeft => context.keeper_jump_left_motor_commands.positions,
116120
MotionType::KeeperJumpRight => context.keeper_jump_right_motor_commands.positions,

crates/control/src/motion/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub mod obstacle_avoiding_arms;
1919
pub mod sit_down;
2020
pub mod stand_up_back;
2121
pub mod stand_up_front;
22+
pub mod stand_up_front_slow;
2223
pub mod stand_up_sitting;
24+
pub mod stand_up_sitting_slow;
2325
pub mod step_planner;
2426
pub mod walk_manager;
2527
pub mod walking_engine;

crates/control/src/motion/motion_selector.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use color_eyre::Result;
22
use context_attribute::context;
3-
use framework::{AdditionalOutput, MainOutput};
3+
use framework::MainOutput;
44
use serde::{Deserialize, Serialize};
55
use types::{
6-
fall_state::Kind,
6+
fall_state::{Kind, StandUpSpeed},
77
motion_command::{JumpDirection, MotionCommand},
88
motion_selection::{MotionSafeExits, MotionSelection, MotionType},
99
};
@@ -23,7 +23,7 @@ pub struct CycleContext {
2323
has_ground_contact: Input<bool, "has_ground_contact">,
2424

2525
motion_safe_exits: CyclerState<MotionSafeExits, "motion_safe_exits">,
26-
stand_up_count: AdditionalOutput<u32, "stand_up_count">,
26+
stand_up_count: CyclerState<u32, "stand_up_count">,
2727
}
2828

2929
#[context]
@@ -40,7 +40,7 @@ impl MotionSelector {
4040
})
4141
}
4242

43-
pub fn cycle(&mut self, mut context: CycleContext) -> Result<MainOutputs> {
43+
pub fn cycle(&mut self, context: CycleContext) -> Result<MainOutputs> {
4444
let motion_safe_to_exit = context.motion_safe_exits[self.last_motion];
4545
let requested_motion = motion_type_from_command(context.motion_command);
4646

@@ -54,10 +54,6 @@ impl MotionSelector {
5454
self.stand_up_count =
5555
stand_up_counting(self.last_motion, current_motion, self.stand_up_count);
5656

57-
context
58-
.stand_up_count
59-
.fill_if_subscribed(|| self.stand_up_count);
60-
6157
let dispatching_motion = if current_motion == MotionType::Dispatching {
6258
if requested_motion == MotionType::Unstiff {
6359
Some(MotionType::SitDown)
@@ -68,6 +64,8 @@ impl MotionSelector {
6864
None
6965
};
7066

67+
*context.stand_up_count = self.stand_up_count;
68+
7169
self.last_motion = current_motion;
7270
Ok(MainOutputs {
7371
motion_selection: MotionSelection {
@@ -93,11 +91,22 @@ fn motion_type_from_command(command: &MotionCommand) -> MotionType {
9391
MotionCommand::Penalized => MotionType::Penalized,
9492
MotionCommand::SitDown { .. } => MotionType::SitDown,
9593
MotionCommand::Stand { .. } => MotionType::Stand,
96-
MotionCommand::StandUp { kind } => match kind {
94+
MotionCommand::StandUp {
95+
kind,
96+
speed: StandUpSpeed::Default,
97+
} => match kind {
9798
Kind::FacingDown => MotionType::StandUpFront,
9899
Kind::FacingUp => MotionType::StandUpBack,
99100
Kind::Sitting => MotionType::StandUpSitting,
100101
},
102+
MotionCommand::StandUp {
103+
kind,
104+
speed: StandUpSpeed::Slow,
105+
} => match kind {
106+
Kind::FacingDown => MotionType::StandUpFrontSlow,
107+
Kind::FacingUp => MotionType::StandUpBack,
108+
Kind::Sitting => MotionType::StandUpSittingSlow,
109+
},
101110
MotionCommand::KeeperMotion { direction } => match direction {
102111
JumpDirection::Left => MotionType::KeeperJumpLeft,
103112
JumpDirection::Right => MotionType::KeeperJumpRight,

crates/control/src/motion/motor_commands_collector.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub struct CycleContext {
4242
stand_up_back_positions: Input<Joints<f32>, "stand_up_back_positions">,
4343
stand_up_front_positions: Input<Joints<f32>, "stand_up_front_positions">,
4444
stand_up_sitting_positions: Input<Joints<f32>, "stand_up_sitting_positions">,
45+
stand_up_front_slow_positions: Input<Joints<f32>, "stand_up_front_slow_positions">,
46+
stand_up_sitting_slow_positions: Input<Joints<f32>, "stand_up_sitting_slow_positions">,
4547
wide_stance_positions: Input<Joints<f32>, "wide_stance_positions">,
4648
keeper_jump_left_motor_commands:
4749
Input<MotorCommands<Joints<f32>>, "keeper_jump_left_motor_commands">,
@@ -93,6 +95,8 @@ impl MotorCommandCollector {
9395
let stand_up_back_positions = context.stand_up_back_positions;
9496
let stand_up_front_positions = context.stand_up_front_positions;
9597
let stand_up_sitting_positions = context.stand_up_sitting_positions;
98+
let stand_up_front_slow_positions = context.stand_up_front_slow_positions;
99+
let stand_up_sitting_slow_positions = context.stand_up_sitting_slow_positions;
96100
let wide_stance_positions = context.wide_stance_positions;
97101
let keeper_jump_left = context.keeper_jump_left_motor_commands;
98102
let keeper_jump_right = context.keeper_jump_right_motor_commands;
@@ -199,6 +203,18 @@ impl MotorCommandCollector {
199203
},
200204
),
201205
),
206+
MotionType::StandUpFrontSlow => (
207+
*stand_up_front_slow_positions,
208+
Joints::from_head_and_body(
209+
HeadJoints::fill(*context.stand_up_stiffness_upper_body),
210+
BodyJoints {
211+
left_arm: ArmJoints::fill(*context.stand_up_stiffness_upper_body),
212+
right_arm: ArmJoints::fill(*context.stand_up_stiffness_upper_body),
213+
left_leg: LegJoints::fill(1.0),
214+
right_leg: LegJoints::fill(1.0),
215+
},
216+
),
217+
),
202218
MotionType::StandUpSitting => (
203219
*stand_up_sitting_positions,
204220
Joints::from_head_and_body(
@@ -211,6 +227,18 @@ impl MotorCommandCollector {
211227
},
212228
),
213229
),
230+
MotionType::StandUpSittingSlow => (
231+
*stand_up_sitting_slow_positions,
232+
Joints::from_head_and_body(
233+
HeadJoints::fill(*context.stand_up_stiffness_upper_body),
234+
BodyJoints {
235+
left_arm: ArmJoints::fill(*context.stand_up_stiffness_upper_body),
236+
right_arm: ArmJoints::fill(*context.stand_up_stiffness_upper_body),
237+
left_leg: LegJoints::fill(1.0),
238+
right_leg: LegJoints::fill(1.0),
239+
},
240+
),
241+
),
214242
MotionType::WideStance => (
215243
*wide_stance_positions,
216244
Joints::from_head_and_body(
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
use color_eyre::Result;
2+
use serde::{Deserialize, Serialize};
3+
4+
use context_attribute::context;
5+
use coordinate_systems::Robot;
6+
use filtering::low_pass_filter::LowPassFilter;
7+
use framework::deserialize_not_implemented;
8+
use framework::MainOutput;
9+
use hardware::PathsInterface;
10+
use linear_algebra::Vector3;
11+
use motionfile::{InterpolatorState, MotionFile, MotionInterpolator};
12+
use types::{
13+
condition_input::ConditionInput,
14+
cycle_time::CycleTime,
15+
joints::Joints,
16+
motion_selection::{MotionSafeExits, MotionSelection, MotionType},
17+
stand_up::RemainingStandUpDuration,
18+
};
19+
20+
#[derive(Deserialize, Serialize)]
21+
pub struct StandUpFrontSlow {
22+
#[serde(skip, default = "deserialize_not_implemented")]
23+
interpolator: MotionInterpolator<Joints<f32>>,
24+
state: InterpolatorState<Joints<f32>>,
25+
filtered_gyro: LowPassFilter<nalgebra::Vector3<f32>>,
26+
}
27+
28+
#[context]
29+
pub struct CreationContext {
30+
hardware_interface: HardwareInterface,
31+
gyro_low_pass_factor: Parameter<f32, "stand_up_front_slow.gyro_low_pass_factor">,
32+
}
33+
34+
#[context]
35+
pub struct CycleContext {
36+
leg_balancing_factor:
37+
Parameter<nalgebra::Vector2<f32>, "stand_up_front_slow.leg_balancing_factor">,
38+
speed_factor: Parameter<f32, "stand_up_front_slow.speed_factor">,
39+
condition_input: Input<ConditionInput, "condition_input">,
40+
cycle_time: Input<CycleTime, "cycle_time">,
41+
motion_selection: Input<MotionSelection, "motion_selection">,
42+
angular_velocity:
43+
Input<Vector3<Robot>, "sensor_data.inertial_measurement_unit.angular_velocity">,
44+
45+
motion_safe_exits: CyclerState<MotionSafeExits, "motion_safe_exits">,
46+
stand_up_front_slow_estimated_remaining_duration:
47+
CyclerState<RemainingStandUpDuration, "stand_up_front_slow_estimated_remaining_duration">,
48+
}
49+
50+
#[context]
51+
#[derive(Default)]
52+
pub struct MainOutputs {
53+
pub stand_up_front_slow_positions: MainOutput<Joints<f32>>,
54+
}
55+
56+
impl StandUpFrontSlow {
57+
pub fn new(context: CreationContext<impl PathsInterface>) -> Result<Self> {
58+
let paths = context.hardware_interface.get_paths();
59+
Ok(Self {
60+
interpolator: MotionFile::from_path(paths.motions.join("stand_up_front.json"))?
61+
.try_into()?,
62+
state: InterpolatorState::INITIAL,
63+
filtered_gyro: LowPassFilter::with_smoothing_factor(
64+
nalgebra::Vector3::zeros(),
65+
*context.gyro_low_pass_factor,
66+
),
67+
})
68+
}
69+
70+
pub fn cycle(&mut self, context: CycleContext) -> Result<MainOutputs> {
71+
let estimated_remaining_duration = if context.motion_selection.current_motion
72+
== MotionType::StandUpFrontSlow
73+
{
74+
let last_cycle_duration = context
75+
.cycle_time
76+
.last_cycle_duration
77+
.div_f32(*context.speed_factor);
78+
let condition_input = context.condition_input;
79+
80+
self.interpolator
81+
.advance_state(&mut self.state, last_cycle_duration, condition_input);
82+
83+
RemainingStandUpDuration::Running(
84+
self.interpolator
85+
.estimated_remaining_duration(self.state)
86+
.mul_f32(*context.speed_factor),
87+
)
88+
} else {
89+
self.state.reset();
90+
RemainingStandUpDuration::NotRunning
91+
};
92+
context.motion_safe_exits[MotionType::StandUpFrontSlow] = self.state.is_finished();
93+
94+
self.filtered_gyro.update(context.angular_velocity.inner);
95+
let gyro = self.filtered_gyro.state();
96+
97+
let mut positions = self.interpolator.value(self.state);
98+
positions.left_leg.ankle_pitch += context.leg_balancing_factor.y * gyro.y;
99+
positions.left_leg.ankle_roll += context.leg_balancing_factor.x * gyro.x;
100+
positions.left_leg.hip_yaw_pitch += context.leg_balancing_factor.x * gyro.x;
101+
positions.right_leg.ankle_pitch += context.leg_balancing_factor.y * gyro.y;
102+
positions.right_leg.ankle_roll += context.leg_balancing_factor.x * gyro.x;
103+
positions.right_leg.hip_yaw_pitch += context.leg_balancing_factor.x * gyro.x;
104+
105+
*context.stand_up_front_slow_estimated_remaining_duration = estimated_remaining_duration;
106+
107+
Ok(MainOutputs {
108+
stand_up_front_slow_positions: positions.into(),
109+
})
110+
}
111+
}

0 commit comments

Comments
 (0)