Tweak some physics, try to reduce pitch stabilization.
This commit is contained in:
parent
4a80554740
commit
2933dca90e
4 changed files with 25 additions and 17 deletions
|
@ -85,7 +85,7 @@ impl Default for CatControllerState {
|
|||
pitch_prev: Default::default(),
|
||||
decay_factor: 0.99,
|
||||
roll_limit: 1.5,
|
||||
pitch_limit: 0.2,
|
||||
pitch_limit: 0.1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,10 +48,10 @@ pub(super) fn falling_cat(
|
|||
let wright = xform.forward().cross(wup).normalize();
|
||||
|
||||
let roll_error = wright.dot(bike_up);
|
||||
let pitch_error = wup.dot(xform.back()) * PITCH_SCALE;
|
||||
let pitch_error = wup.dot(xform.back());
|
||||
|
||||
// only try to correct roll if we're not totally vertical
|
||||
if pitch_error.abs() < 0.8 {
|
||||
if pitch_error.abs() < 0.95 {
|
||||
let (derivative, integral) = control_vars.update_roll(roll_error, time.delta_seconds());
|
||||
let mag =
|
||||
(settings.kp * roll_error) + (settings.ki * integral) + (settings.kd * derivative);
|
||||
|
@ -61,17 +61,20 @@ pub(super) fn falling_cat(
|
|||
}
|
||||
|
||||
// we can do pitch correction any time, it's not coupled to roll
|
||||
let (derivative, integral) = control_vars.update_pitch(pitch_error, time.delta_seconds());
|
||||
let mag = (settings.kp * pitch_error) + (settings.ki * integral) + (settings.kd * derivative);
|
||||
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 += wright * mag * 0.25;
|
||||
forces.torque += wright * mag;
|
||||
}
|
||||
|
||||
#[cfg(feature = "inspector")]
|
||||
{
|
||||
let now = Instant::now();
|
||||
if (now - debug_instant.0).as_millis() > 500 {
|
||||
dbg!(roll_error, pitch_error, &control_vars, mag);
|
||||
if (now - debug_instant.0).as_millis() > 1000 {
|
||||
dbg!(&control_vars, mag);
|
||||
debug_instant.0 = now;
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +102,7 @@ pub(super) fn input_forces(
|
|||
|
||||
// brake
|
||||
for mut motor in braking_query.iter_mut() {
|
||||
let factor = if input.brake { 100.00 } else { 0.0 };
|
||||
let factor = if input.brake { 200.00 } else { 0.0 };
|
||||
motor.data = (*motor
|
||||
.data
|
||||
.as_revolute_mut()
|
||||
|
|
|
@ -23,6 +23,8 @@ pub struct WheelConfig {
|
|||
pub stiffness: f32,
|
||||
pub damping: f32,
|
||||
pub radius: f32,
|
||||
pub friction: f32,
|
||||
pub restitution: f32,
|
||||
}
|
||||
|
||||
impl Default for WheelConfig {
|
||||
|
@ -36,6 +38,8 @@ impl Default for WheelConfig {
|
|||
stiffness: 90.0,
|
||||
damping: 8.0,
|
||||
radius: 0.3,
|
||||
friction: 0.9,
|
||||
restitution: 0.8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,8 @@ pub fn spawn_tires(
|
|||
};
|
||||
|
||||
let friction = Friction {
|
||||
coefficient: 0.8,
|
||||
combine_rule: CoefficientCombineRule::Min,
|
||||
coefficient: conf.friction,
|
||||
combine_rule: CoefficientCombineRule::Average,
|
||||
};
|
||||
|
||||
let mut wheel_poses = Vec::with_capacity(2);
|
||||
|
@ -86,24 +86,25 @@ pub fn spawn_tires(
|
|||
let fork_rb_entity = commands
|
||||
.spawn(RigidBody::Dynamic)
|
||||
.insert(prismatic_joint)
|
||||
.insert(not_sleeping)
|
||||
.id();
|
||||
|
||||
let axel_parent = if let Some(steering) = steering {
|
||||
let axel_parent_entity = if let Some(steering) = steering {
|
||||
let neck_builder = RevoluteJointBuilder::new(Vec3::Y);
|
||||
let neck_joint = MultibodyJoint::new(fork_rb_entity, neck_builder);
|
||||
let hub = commands
|
||||
let neck = commands
|
||||
.spawn(RigidBody::Dynamic)
|
||||
.insert(neck_joint)
|
||||
.insert(steering)
|
||||
.insert(not_sleeping)
|
||||
.id();
|
||||
dbg!(hub);
|
||||
hub
|
||||
neck
|
||||
} else {
|
||||
fork_rb_entity
|
||||
};
|
||||
|
||||
let revolute_builder = RevoluteJointBuilder::new(Vec3::X);
|
||||
let axel_joint = MultibodyJoint::new(axel_parent, revolute_builder);
|
||||
let axel_joint = MultibodyJoint::new(axel_parent_entity, revolute_builder);
|
||||
|
||||
commands.spawn(pbr_bundle.clone()).insert((
|
||||
wheel_collider,
|
||||
|
@ -116,7 +117,7 @@ pub fn spawn_tires(
|
|||
friction,
|
||||
CyberWheel,
|
||||
ExternalForce::default(),
|
||||
Restitution::new(0.2),
|
||||
Restitution::new(conf.restitution),
|
||||
SpatialBundle::default(),
|
||||
TransformInterpolation::default(),
|
||||
RigidBody::Dynamic,
|
||||
|
|
Loading…
Reference in a new issue