remove pitch stabilizing
This commit is contained in:
parent
881e6858de
commit
b6fed0ea4d
2 changed files with 1 additions and 33 deletions
|
@ -81,11 +81,8 @@ impl Default for CatControllerSettings {
|
||||||
pub struct CatControllerState {
|
pub struct CatControllerState {
|
||||||
pub roll_integral: f32,
|
pub roll_integral: f32,
|
||||||
pub roll_prev: f32,
|
pub roll_prev: f32,
|
||||||
pub pitch_integral: f32,
|
|
||||||
pub pitch_prev: f32,
|
|
||||||
decay_factor: f32,
|
decay_factor: f32,
|
||||||
roll_limit: f32,
|
roll_limit: f32,
|
||||||
pitch_limit: f32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CatControllerState {
|
impl Default for CatControllerState {
|
||||||
|
@ -93,11 +90,8 @@ impl Default for CatControllerState {
|
||||||
Self {
|
Self {
|
||||||
roll_integral: Default::default(),
|
roll_integral: Default::default(),
|
||||||
roll_prev: Default::default(),
|
roll_prev: Default::default(),
|
||||||
pitch_integral: 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.1,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,9 +101,6 @@ impl CatControllerState {
|
||||||
if self.roll_integral.abs() > 0.001 {
|
if self.roll_integral.abs() > 0.001 {
|
||||||
self.roll_integral *= self.decay_factor;
|
self.roll_integral *= self.decay_factor;
|
||||||
}
|
}
|
||||||
if self.pitch_integral.abs() > 0.001 {
|
|
||||||
self.pitch_integral *= self.decay_factor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_roll(&mut self, error: f32, dt: f32) -> (f32, f32) {
|
pub fn update_roll(&mut self, error: f32, dt: f32) -> (f32, f32) {
|
||||||
|
@ -120,16 +111,7 @@ impl CatControllerState {
|
||||||
(derivative, self.roll_integral)
|
(derivative, self.roll_integral)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_pitch(&mut self, error: f32, dt: f32) -> (f32, f32) {
|
pub fn set_integral_limits(&mut self, roll: f32) {
|
||||||
let lim = self.pitch_limit;
|
|
||||||
self.pitch_integral = (self.pitch_integral + (error * dt)).min(lim).max(-lim);
|
|
||||||
let derivative = (error - self.pitch_prev) / dt;
|
|
||||||
self.pitch_prev = error;
|
|
||||||
(derivative, self.pitch_integral)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_integral_limits(&mut self, roll: f32, pitch: f32) {
|
|
||||||
self.roll_limit = roll;
|
self.roll_limit = roll;
|
||||||
self.pitch_limit = pitch;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,6 @@ use crate::{
|
||||||
input::InputState,
|
input::InputState,
|
||||||
};
|
};
|
||||||
|
|
||||||
const PITCH_SCALE: f32 = 0.2;
|
|
||||||
|
|
||||||
fn yaw_to_angle(yaw: f32) -> f32 {
|
fn yaw_to_angle(yaw: f32) -> f32 {
|
||||||
yaw.powi(3) * FRAC_PI_4
|
yaw.powi(3) * FRAC_PI_4
|
||||||
}
|
}
|
||||||
|
@ -86,8 +84,6 @@ pub(super) fn falling_cat(
|
||||||
|
|
||||||
let bike_right = xform.right();
|
let bike_right = xform.right();
|
||||||
|
|
||||||
let world_right = xform.forward().cross(world_up).normalize();
|
|
||||||
|
|
||||||
let roll_error = bike_right.dot(target_up);
|
let roll_error = bike_right.dot(target_up);
|
||||||
let pitch_error = world_up.dot(xform.back());
|
let pitch_error = world_up.dot(xform.back());
|
||||||
|
|
||||||
|
@ -107,16 +103,6 @@ pub(super) fn falling_cat(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we can do pitch correction any time, it's not coupled to roll
|
|
||||||
let scaled_pitch_error = pitch_error * PITCH_SCALE;
|
|
||||||
let (derivative, integral) =
|
|
||||||
control_vars.update_pitch(scaled_pitch_error, time.delta_seconds());
|
|
||||||
let mag =
|
|
||||||
(settings.kp * scaled_pitch_error) + (settings.ki * integral) + (settings.kd * derivative);
|
|
||||||
if mag.is_finite() {
|
|
||||||
forces.torque += world_right * mag;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply forces to the cyberbike as a result of input.
|
/// Apply forces to the cyberbike as a result of input.
|
||||||
|
|
Loading…
Reference in a new issue