Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haaaaaaaalt stop #1353

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions crates/control/src/behavior/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ impl Behavior {

pub fn cycle(&mut self, mut context: CycleContext) -> Result<MainOutputs> {
let world_state = context.world_state;
if let Some(command) = &context.parameters.injected_motion_command {
return Ok(MainOutputs {
motion_command: command.clone().into(),
dribble_path: None.into(),
});

if world_state.robot.primary_state == PrimaryState::Playing {
if let Some(command) = &context.parameters.injected_motion_command {
return Ok(MainOutputs {
motion_command: command.clone().into(),
dribble_path: None.into(),
});
}
}

if let Some(ball_state) = &world_state.ball {
Expand Down
25 changes: 23 additions & 2 deletions tools/twix/src/panels/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use communication::messages::TextOrBinary;
use eframe::egui::Widget;
use gilrs::{Axis, Button, Gamepad, GamepadId, Gilrs};
use serde_json::{json, Value};
use types::{joints::head::HeadJoints, step_plan::Step};
use types::{joints::head::HeadJoints, motion_command::MotionCommand, step_plan::Step};

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

Expand Down Expand Up @@ -58,6 +58,13 @@ impl RemotePanel {
)
}

fn update_motion_command(&self, motion_command: Value) {
self.nao.write(
"parameters.behavior.injected_motion_command",
TextOrBinary::Text(motion_command),
)
}

fn update_look_at_angle(&self, joints: Value) {
self.nao.write(
"parameters.head_motion.injected_head_joints",
Expand All @@ -71,6 +78,7 @@ impl Widget for &mut RemotePanel {
const UPDATE_DELAY: Duration = Duration::from_millis(100);
const HEAD_PITCH_SCALE: f32 = 1.0;
const HEAD_YAW_SCALE: f32 = 1.0;
const DEADZONE: f32 = 0.1;

self.gilrs.inc();

Expand Down Expand Up @@ -118,6 +126,15 @@ impl Widget for &mut RemotePanel {
turn,
};

let injected_motion_command =
if step.forward.abs() < DEADZONE && step.left.abs() < DEADZONE {
Some(MotionCommand::Stand {
head: types::motion_command::HeadMotion::ZeroAngles,
})
} else {
None
};

if self.enabled {
let now = SystemTime::now();
if now
Expand All @@ -128,14 +145,18 @@ impl Widget for &mut RemotePanel {
self.last_update = now;
self.update_step(serde_json::to_value(step).unwrap());
self.update_look_at_angle(serde_json::to_value(injected_head_joints).unwrap());
self.update_motion_command(
serde_json::to_value(&injected_motion_command).unwrap(),
);
}
}

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

label_1.union(label_2)
label_1.union(label_2).union(label_3)
})
.inner
} else {
Expand Down