add pitch_scale for pid controller

This commit is contained in:
Joe Ardent 2023-02-17 21:53:34 -08:00
parent adc6be7c7b
commit 4a80554740
2 changed files with 4 additions and 2 deletions

View File

@ -85,7 +85,7 @@ impl Default for CatControllerState {
pitch_prev: Default::default(), pitch_prev: Default::default(),
decay_factor: 0.99, decay_factor: 0.99,
roll_limit: 1.5, roll_limit: 1.5,
pitch_limit: 0.8, pitch_limit: 0.2,
} }
} }
} }

View File

@ -16,6 +16,8 @@ use crate::{
input::InputState, input::InputState,
}; };
const PITCH_SCALE: f32 = 0.2;
/// Disable gravity in Rapier. /// Disable gravity in Rapier.
pub(super) fn zero_gravity(mut config: ResMut<RapierConfiguration>) { pub(super) fn zero_gravity(mut config: ResMut<RapierConfiguration>) {
config.gravity = Vec3::ZERO; config.gravity = Vec3::ZERO;
@ -46,7 +48,7 @@ pub(super) fn falling_cat(
let wright = xform.forward().cross(wup).normalize(); let wright = xform.forward().cross(wup).normalize();
let roll_error = wright.dot(bike_up); let roll_error = wright.dot(bike_up);
let pitch_error = wup.dot(xform.back()); let pitch_error = wup.dot(xform.back()) * PITCH_SCALE;
// only try to correct roll if we're not totally vertical // only try to correct roll if we're not totally vertical
if pitch_error.abs() < 0.8 { if pitch_error.abs() < 0.8 {