From 3b0df52d10c157cd2711d64ef9007d2afccbd468 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 20 Jan 2013 09:33:13 -0800 Subject: BulletSim: modify motors to return correction rather than current value to better use them for incremental updates. Modify prim and character to use the new motors. Simplify the vehicle linear movement code to just update the velocity directly or the basic movement. --- OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | 25 +++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index 6d0db2e..82fd2d2 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs @@ -138,7 +138,8 @@ public class BSVMotor : BSMotor CurrentValue = TargetValue = Vector3.Zero; } - // Compute the next step and return the new current value + // Compute the next step and return the new current value. + // Returns the correction needed to move 'current' to 'target'. public virtual Vector3 Step(float timeStep) { if (!Enabled) return TargetValue; @@ -150,7 +151,7 @@ public class BSVMotor : BSMotor Vector3 error = TargetValue - CurrentValue; if (!ErrorIsZero(error)) { - correction = Step(timeStep, error); + correction = StepError(timeStep, error); CurrentValue += correction; @@ -187,14 +188,20 @@ public class BSVMotor : BSMotor else { // Difference between what we have and target is small. Motor is done. - CurrentValue = TargetValue; + CurrentValue = TargetValue = Vector3.Zero; MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}", BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); } - return CurrentValue; + return correction; + } + // version of step that sets the current value before doing the step + public virtual Vector3 Step(float timeStep, Vector3 current) + { + CurrentValue = current; + return Step(timeStep); } - public virtual Vector3 Step(float timeStep, Vector3 error) + public virtual Vector3 StepError(float timeStep, Vector3 error) { if (!Enabled) return Vector3.Zero; @@ -304,7 +311,7 @@ public class BSFMotor : BSMotor float error = TargetValue - CurrentValue; if (!ErrorIsZero(error)) { - correction = Step(timeStep, error); + correction = StepError(timeStep, error); CurrentValue += correction; @@ -347,7 +354,7 @@ public class BSFMotor : BSMotor return CurrentValue; } - public virtual float Step(float timeStep, float error) + public virtual float StepError(float timeStep, float error) { if (!Enabled) return 0f; @@ -440,8 +447,8 @@ public class BSPIDVMotor : BSVMotor } } - // Ignore Current and Target Values and just advance the PID computation on this error. - public override Vector3 Step(float timeStep, Vector3 error) + // Advance the PID computation on this error. + public override Vector3 StepError(float timeStep, Vector3 error) { if (!Enabled) return Vector3.Zero; -- cgit v1.1 From 52b341e2e24384395fddc7d32fd66358f5062468 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 20 Jan 2013 22:35:42 -0800 Subject: BulletSim: More aggressive as setting character velocity to zero when should be standing. Modify angular force routines to be the same pattern as linear force routines. BulletSim vehicle turning is scaled like SL and is DIFFERENT THAN ODE!! Fix some bugs in BSMotor dealing with the motor going to zero. Add a bunch of parameters: MaxLinearVelocity, MaxAngularVelocity, MaxAddForceMagnitude, VehicleMaxLinearVelocity, VehicleMaxAngularVelocity, and most of the values are defaulted to values that are larger than in SL. Use the new parameters in BSPrim, BSCharacter and BSDynamic. --- OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | 26 +++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index 82fd2d2..9501e2d 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs @@ -149,6 +149,7 @@ public class BSVMotor : BSMotor Vector3 correction = Vector3.Zero; Vector3 error = TargetValue - CurrentValue; + LastError = error; if (!ErrorIsZero(error)) { correction = StepError(timeStep, error); @@ -188,9 +189,15 @@ public class BSVMotor : BSMotor else { // Difference between what we have and target is small. Motor is done. - CurrentValue = TargetValue = Vector3.Zero; - MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}", - BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); + if (TargetValue.ApproxEquals(Vector3.Zero, ErrorZeroThreshold)) + { + // The target can step down to nearly zero but not get there. If close to zero + // it is really zero. + TargetValue = Vector3.Zero; + } + CurrentValue = TargetValue; + MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},currTgt={4},currCurr={5}", + BSScene.DetailLogZero, UseName, origCurrVal, origTarget, TargetValue, CurrentValue); } return correction; @@ -205,9 +212,8 @@ public class BSVMotor : BSMotor { if (!Enabled) return Vector3.Zero; - LastError = error; Vector3 returnCorrection = Vector3.Zero; - if (!ErrorIsZero()) + if (!ErrorIsZero(error)) { // correction = error / secondsItShouldTakeToCorrect Vector3 correctionAmount; @@ -309,6 +315,7 @@ public class BSFMotor : BSMotor float correction = 0f; float error = TargetValue - CurrentValue; + LastError = error; if (!ErrorIsZero(error)) { correction = StepError(timeStep, error); @@ -346,6 +353,12 @@ public class BSFMotor : BSMotor else { // Difference between what we have and target is small. Motor is done. + if (Util.InRange(TargetValue, -ErrorZeroThreshold, ErrorZeroThreshold)) + { + // The target can step down to nearly zero but not get there. If close to zero + // it is really zero. + TargetValue = 0f; + } CurrentValue = TargetValue; MDetailLog("{0}, BSFMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}", BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); @@ -358,9 +371,8 @@ public class BSFMotor : BSMotor { if (!Enabled) return 0f; - LastError = error; float returnCorrection = 0f; - if (!ErrorIsZero()) + if (!ErrorIsZero(error)) { // correction = error / secondsItShouldTakeToCorrect float correctionAmount; -- cgit v1.1