Skip to content

Commit d74f983

Browse files
committed
Send MotionCommand::Stand when not moving with remote panel
1 parent 04368b8 commit d74f983

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tools/twix/src/panels/remote.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use communication::messages::TextOrBinary;
77
use eframe::egui::Widget;
88
use gilrs::{Axis, Button, Gamepad, GamepadId, Gilrs};
99
use serde_json::{json, Value};
10-
use types::{joints::head::HeadJoints, step_plan::Step};
10+
use types::{joints::head::HeadJoints, motion_command::MotionCommand, step_plan::Step};
1111

1212
use crate::{nao::Nao, panel::Panel};
1313

@@ -58,6 +58,13 @@ impl RemotePanel {
5858
)
5959
}
6060

61+
fn update_motion_command(&self, motion_command: Value) {
62+
self.nao.write(
63+
"parameters.behavior.injected_motion_command",
64+
TextOrBinary::Text(motion_command),
65+
)
66+
}
67+
6168
fn update_look_at_angle(&self, joints: Value) {
6269
self.nao.write(
6370
"parameters.head_motion.injected_head_joints",
@@ -71,6 +78,7 @@ impl Widget for &mut RemotePanel {
7178
const UPDATE_DELAY: Duration = Duration::from_millis(100);
7279
const HEAD_PITCH_SCALE: f32 = 1.0;
7380
const HEAD_YAW_SCALE: f32 = 1.0;
81+
const DEADZONE: f32 = 0.1;
7482

7583
self.gilrs.inc();
7684

@@ -118,6 +126,15 @@ impl Widget for &mut RemotePanel {
118126
turn,
119127
};
120128

129+
let injected_motion_command =
130+
if step.forward.abs() < DEADZONE && step.left.abs() < DEADZONE {
131+
Some(MotionCommand::Stand {
132+
head: types::motion_command::HeadMotion::ZeroAngles,
133+
})
134+
} else {
135+
None
136+
};
137+
121138
if self.enabled {
122139
let now = SystemTime::now();
123140
if now
@@ -128,14 +145,18 @@ impl Widget for &mut RemotePanel {
128145
self.last_update = now;
129146
self.update_step(serde_json::to_value(step).unwrap());
130147
self.update_look_at_angle(serde_json::to_value(injected_head_joints).unwrap());
148+
self.update_motion_command(
149+
serde_json::to_value(&injected_motion_command).unwrap(),
150+
);
131151
}
132152
}
133153

134154
ui.vertical(|ui| {
135155
let label_1 = ui.label(&format!("{:#?}", step));
136156
let label_2 = ui.label(&format!("{:#?}", injected_head_joints));
157+
let label_3 = ui.label(&format!("{:#?}", injected_motion_command));
137158

138-
label_1.union(label_2)
159+
label_1.union(label_2).union(label_3)
139160
})
140161
.inner
141162
} else {

0 commit comments

Comments
 (0)