-
Notifications
You must be signed in to change notification settings - Fork 57
Safe crash #1825
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
base: main
Are you sure you want to change the base?
Safe crash #1825
Conversation
if (position.right_knee_pitch <= 90.0_f32.to_radians() | ||
|| position.left_knee_pitch <= 90.0_f32.to_radians()) | ||
&& (position.left_hip_pitch >= -40.0_f32.to_radians() | ||
|| position.right_hip_pitch >= -40.0_f32.to_radians()) | ||
&& inertial_measurement_unit.accelerometer.z < -8.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you extract this to a variable with a name like is_...
to properly name what you want to check here
sit_down_interpolator.advance_by( | ||
loop_duration, | ||
&ConditionInput { | ||
filtered_angular_velocity: Vector3::zeros(), | ||
ground_contact: true, | ||
fall_state: FallState::Upright, | ||
}, | ||
); | ||
|
||
let sit_down_joints_command = MotorCommands { | ||
positions: sit_down_interpolator.value(), | ||
stiffnesses: Joints::fill(0.8), | ||
}; | ||
|
||
send_sit_down( | ||
&mut writer, | ||
sit_down_joints_command.positions, | ||
sit_down_joints_command.stiffnesses, | ||
) | ||
.wrap_err("failed to send sit down command to LoLA")?; | ||
|
||
if sit_down_interpolator.is_finished() { | ||
operation_state = OperationState::GuestsInControl; | ||
sit_down_interpolator.reset(); | ||
} | ||
} else if !connections | ||
.values() | ||
.any(|connection| connection.is_sending_control_frames) | ||
{ | ||
let battery = self.shared_state.lock().unwrap().battery; | ||
send_idle(&mut writer, battery).wrap_err( | ||
let shared_state = self.shared_state.lock().unwrap(); | ||
if let (Some(position), Some(inertial_measurement_unit)) = ( | ||
shared_state.position, | ||
shared_state.inertial_measurement_unit, | ||
) { | ||
if (position.right_knee_pitch <= 90.0_f32.to_radians() | ||
|| position.left_knee_pitch <= 90.0_f32.to_radians()) | ||
&& (position.left_hip_pitch >= -40.0_f32.to_radians() | ||
|| position.right_hip_pitch >= -40.0_f32.to_radians()) | ||
&& inertial_measurement_unit.accelerometer.z < -8.0 | ||
{ | ||
operation_state = OperationState::SittingDown; | ||
} | ||
} | ||
send_idle(&mut writer, shared_state.battery).wrap_err( | ||
"a shadowy flight into the dangerous world of a man who does not exist", | ||
)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function is getting really long, can you split it up into smaller sub-tasks?
#[derive(Deserialize, Serialize)] | ||
pub struct SitDown {} | ||
|
||
pub fn sit_down() -> bool { | ||
interpolator: MotionFile::from_path(paths.motions.join("sit_down.json"))?.try_into()?, | ||
|
||
|
||
let last_cycle_duration = context.cycle_time.last_cycle_duration; | ||
|
||
self.interpolator | ||
.advance_by(last_cycle_duration, context.condition_input); | ||
|
||
context.motion_safe_exits[MotionType::SitDown] = self.interpolator.is_finished(); | ||
|
||
Ok(MainOutputs { | ||
sit_down_joints_command: MotorCommands { | ||
positions: self.interpolator.value(), | ||
stiffnesses: Joints::fill(0.8), | ||
} | ||
.into(), | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this? Added accidentally?
Why? What?
Describe here why you created this PR and what it does
Fixes #
ToDo / Known Issues
If this is a WIP describe which problems are to be fixed.
Ideas for Next Iterations (Not This PR)
If there are some improvements that could be done in a next iteration, describe them here.
How to Test
Describe how to test your changes. (For the reviewer)