Skip to content

Commit d49f993

Browse files
authored
Gamepad (#2145)
* add motion crate * add motion crate * --wip-- * add new remotecontrol behavior for new motion comman * implement motioncommand changes * move type definition * implement get remote_motion_comman as separate node * remove unneccesary variables and fmt * remove unnecessary stuff * fix rebase conflicts * fix: last gait progress * gamepad in thread * add start to start gamepad back * fix rebase * fix format und konrads changes * add robot and controler step * review changes: connectionerror and step based loop * fmt * rename file * fix controller reseting when joustick snaps * dead zones * round dead zones * match label no data
1 parent 3e91d73 commit d49f993

10 files changed

Lines changed: 280 additions & 165 deletions

File tree

crates/control/src/motion/booster_walking.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ use color_eyre::Result;
33
use context_attribute::context;
44
use framework::{AdditionalOutput, MainOutput};
55
use hardware::PathsInterface;
6-
use linear_algebra::vector;
76
use serde::{Deserialize, Serialize};
87
use types::{
98
cycle_time::CycleTime,
109
joints::Joints,
11-
motion_command::{HeadMotion, MotionCommand},
10+
motion_command::MotionCommand,
1211
parameters::{MotorCommandParameters, RLWalkingParameters},
1312
};
1413
use walking_inference::{inference::WalkingInference, inputs::WalkingInferenceInputs};
@@ -36,6 +35,7 @@ pub struct CycleContext {
3635
imu_state: Input<ImuState, "imu_state">,
3736
serial_motor_states: Input<Joints<MotorState>, "serial_motor_states">,
3837
cycle_time: Input<CycleTime, "cycle_time">,
38+
motion_command: Input<MotionCommand, "motion_command">,
3939
}
4040

4141
#[context]
@@ -63,19 +63,10 @@ impl RLWalking {
6363
}
6464

6565
pub fn cycle(&mut self, mut context: CycleContext) -> Result<MainOutputs> {
66-
let motion_command = &MotionCommand::WalkWithVelocity {
67-
velocity: vector!(
68-
context.walking_parameters.walk_command[0],
69-
context.walking_parameters.walk_command[1]
70-
),
71-
angular_velocity: context.walking_parameters.walk_command[2],
72-
head: HeadMotion::Center,
73-
};
74-
7566
let (walking_inference_inputs, inference_output_positions) =
7667
self.walking_inference.do_inference(
7768
*context.cycle_time,
78-
motion_command,
69+
context.motion_command,
7970
context.imu_state,
8071
*context.serial_motor_states,
8172
context.walking_parameters,

crates/control/src/motion/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ pub mod look_around;
1515
pub mod look_at;
1616
pub mod motion_selector;
1717
pub mod motor_commands_collector;
18+
pub mod remote_control;
1819
pub mod sit_down;
1920
pub mod wide_stance;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use color_eyre::Result;
2+
use context_attribute::context;
3+
4+
use framework::MainOutput;
5+
use linear_algebra::vector;
6+
use serde::{Deserialize, Serialize};
7+
use types::{
8+
motion_command::{HeadMotion, MotionCommand},
9+
parameters::RemoteControlParameters,
10+
};
11+
12+
#[context]
13+
pub struct CreationContext {}
14+
15+
#[context]
16+
pub struct CycleContext {
17+
remote_control_parameters: Parameter<RemoteControlParameters, "remote_control_parameters">,
18+
}
19+
20+
#[derive(Deserialize, Serialize)]
21+
pub struct RemoteControl {}
22+
23+
#[context]
24+
#[derive(Default)]
25+
pub struct MainOutputs {
26+
pub motion_command: MainOutput<MotionCommand>,
27+
}
28+
29+
impl RemoteControl {
30+
pub fn new(_context: CreationContext) -> Result<Self> {
31+
Ok(RemoteControl {})
32+
}
33+
34+
pub fn cycle(&mut self, context: CycleContext) -> Result<MainOutputs> {
35+
let motion_command = MotionCommand::WalkWithVelocity {
36+
head: HeadMotion::Center,
37+
velocity: vector![
38+
context.remote_control_parameters.walk.forward,
39+
context.remote_control_parameters.walk.left,
40+
],
41+
angular_velocity: context.remote_control_parameters.walk.turn,
42+
};
43+
44+
Ok(MainOutputs {
45+
motion_command: motion_command.into(),
46+
})
47+
}
48+
}

crates/hulk_manifest/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub fn collect_hulk_cyclers(root: impl AsRef<Path>) -> Result<Cyclers, Error> {
7272
// "control::motion::center_jump",
7373
"control::motion::command_sender",
7474
"control::motion::booster_walking",
75+
"control::motion::remote_control",
7576
// "control::motion::condition_input_provider",
7677
// "control::motion::dispatching_interpolator",
7778
// "control::motion::fall_protector",

crates/types/src/parameters.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ use crate::{
1515
joints::Joints,
1616
motion_command::{KickVariant, MotionCommand},
1717
roles::Role,
18+
step::Step,
1819
};
1920

21+
#[derive(
22+
Clone, Debug, Default, Deserialize, Serialize, PathSerialize, PathDeserialize, PathIntrospect,
23+
)]
24+
pub struct RemoteControlParameters {
25+
pub walk: Step,
26+
}
27+
2028
#[derive(
2129
Clone, Debug, Default, Deserialize, Serialize, PathSerialize, PathDeserialize, PathIntrospect,
2230
)]

crates/walking_inference/src/inputs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ impl WalkingInferenceInputs {
7474
_ => todo!(),
7575
};
7676

77-
let gait_frequency =
77+
let (gait_frequency, last_gait_progress) =
7878
if linear_velocity_command.norm() < 1e-5 && angular_velocity_command.abs() < 1e-5 {
79-
0.0
79+
(0.0, 0.0)
8080
} else {
81-
walking_parameters.gait_frequency
81+
(walking_parameters.gait_frequency, last_gait_progress)
8282
};
8383
let gait_progress =
8484
last_gait_progress + gait_frequency * cycle_time.last_cycle_duration.as_secs_f32();

etc/parameters/default.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,12 @@
266266
"ankle_down": 1
267267
}
268268
}
269+
},
270+
"remote_control_parameters": {
271+
"walk": {
272+
"forward": 0.0,
273+
"left": 0.0,
274+
"turn": 0.0
275+
}
269276
}
270277
}

tools/twix/src/panels/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod map;
1212
mod mujoco_simulator;
1313
mod parameter;
1414
mod plot;
15-
mod remote;
15+
mod remote_control;
1616
mod text;
1717
mod vision_tuner;
1818

@@ -32,6 +32,6 @@ pub use map::MapPanel;
3232
pub use mujoco_simulator::MujocoSimulatorPanel;
3333
pub use parameter::ParameterPanel;
3434
pub use plot::PlotPanel;
35-
pub use remote::RemotePanel;
35+
pub use remote_control::RemotePanel;
3636
pub use text::TextPanel;
3737
pub use vision_tuner::VisionTunerPanel;

tools/twix/src/panels/remote.rs

Lines changed: 0 additions & 148 deletions
This file was deleted.

0 commit comments

Comments
 (0)