aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
diff options
context:
space:
mode:
authorMelanie2012-12-23 18:05:17 +0000
committerMelanie2012-12-23 18:05:17 +0000
commita126097d6be209ba4e30b5573195c04bcf2d8c1e (patch)
treebce8220f560827a332155ca84e16de94677ca235 /OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
parentMerge branch 'avination' into careminster (diff)
parentBulletSim: modify avatar motor code to make falling movement better. Clean up... (diff)
downloadopensim-SC-a126097d6be209ba4e30b5573195c04bcf2d8c1e.zip
opensim-SC-a126097d6be209ba4e30b5573195c04bcf2d8c1e.tar.gz
opensim-SC-a126097d6be209ba4e30b5573195c04bcf2d8c1e.tar.bz2
opensim-SC-a126097d6be209ba4e30b5573195c04bcf2d8c1e.tar.xz
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSMotors.cs32
1 files changed, 26 insertions, 6 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
index 34a87c6..9e1a9ba 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
@@ -43,7 +43,9 @@ public abstract class BSMotor
43 { 43 {
44 UseName = useName; 44 UseName = useName;
45 PhysicsScene = null; 45 PhysicsScene = null;
46 Enabled = true;
46 } 47 }
48 public virtual bool Enabled { get; set; }
47 public virtual void Reset() { } 49 public virtual void Reset() { }
48 public virtual void Zero() { } 50 public virtual void Zero() { }
49 public virtual void GenerateTestOutput(float timeStep) { } 51 public virtual void GenerateTestOutput(float timeStep) { }
@@ -98,6 +100,12 @@ public class BSVMotor : BSMotor
98 public virtual Vector3 CurrentValue { get; protected set; } 100 public virtual Vector3 CurrentValue { get; protected set; }
99 public virtual Vector3 LastError { get; protected set; } 101 public virtual Vector3 LastError { get; protected set; }
100 102
103 public virtual bool ErrorIsZero
104 { get {
105 return (LastError == Vector3.Zero || LastError.LengthSquared() <= ErrorZeroThreshold);
106 }
107 }
108
101 public BSVMotor(string useName) 109 public BSVMotor(string useName)
102 : base(useName) 110 : base(useName)
103 { 111 {
@@ -105,7 +113,7 @@ public class BSVMotor : BSMotor
105 Efficiency = 1f; 113 Efficiency = 1f;
106 FrictionTimescale = BSMotor.InfiniteVector; 114 FrictionTimescale = BSMotor.InfiniteVector;
107 CurrentValue = TargetValue = Vector3.Zero; 115 CurrentValue = TargetValue = Vector3.Zero;
108 ErrorZeroThreshold = 0.01f; 116 ErrorZeroThreshold = 0.001f;
109 } 117 }
110 public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency) 118 public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency)
111 : this(useName) 119 : this(useName)
@@ -133,6 +141,8 @@ public class BSVMotor : BSMotor
133 // Compute the next step and return the new current value 141 // Compute the next step and return the new current value
134 public virtual Vector3 Step(float timeStep) 142 public virtual Vector3 Step(float timeStep)
135 { 143 {
144 if (!Enabled) return TargetValue;
145
136 Vector3 origTarget = TargetValue; // DEBUG 146 Vector3 origTarget = TargetValue; // DEBUG
137 Vector3 origCurrVal = CurrentValue; // DEBUG 147 Vector3 origCurrVal = CurrentValue; // DEBUG
138 148
@@ -178,7 +188,7 @@ public class BSVMotor : BSMotor
178 { 188 {
179 // Difference between what we have and target is small. Motor is done. 189 // Difference between what we have and target is small. Motor is done.
180 CurrentValue = TargetValue; 190 CurrentValue = TargetValue;
181 MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={2}", 191 MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}",
182 BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue); 192 BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue);
183 } 193 }
184 194
@@ -186,6 +196,8 @@ public class BSVMotor : BSMotor
186 } 196 }
187 public virtual Vector3 Step(float timeStep, Vector3 error) 197 public virtual Vector3 Step(float timeStep, Vector3 error)
188 { 198 {
199 if (!Enabled) return Vector3.Zero;
200
189 LastError = error; 201 LastError = error;
190 Vector3 returnCorrection = Vector3.Zero; 202 Vector3 returnCorrection = Vector3.Zero;
191 if (!error.ApproxEquals(Vector3.Zero, ErrorZeroThreshold)) 203 if (!error.ApproxEquals(Vector3.Zero, ErrorZeroThreshold))
@@ -268,12 +280,14 @@ public class BSPIDVMotor : BSVMotor
268 public Vector3 proportionFactor { get; set; } 280 public Vector3 proportionFactor { get; set; }
269 public Vector3 integralFactor { get; set; } 281 public Vector3 integralFactor { get; set; }
270 public Vector3 derivFactor { get; set; } 282 public Vector3 derivFactor { get; set; }
283
271 // Arbritrary factor range. 284 // Arbritrary factor range.
272 // EfficiencyHigh means move quickly to the correct number. EfficiencyLow means might over correct. 285 // EfficiencyHigh means move quickly to the correct number. EfficiencyLow means might over correct.
273 public float EfficiencyHigh = 0.4f; 286 public float EfficiencyHigh = 0.4f;
274 public float EfficiencyLow = 4.0f; 287 public float EfficiencyLow = 4.0f;
275 288
276 Vector3 IntegralFactor { get; set; } 289 // Running integration of the error
290 Vector3 RunningIntegration { get; set; }
277 291
278 public BSPIDVMotor(string useName) 292 public BSPIDVMotor(string useName)
279 : base(useName) 293 : base(useName)
@@ -281,7 +295,7 @@ public class BSPIDVMotor : BSVMotor
281 proportionFactor = new Vector3(1.00f, 1.00f, 1.00f); 295 proportionFactor = new Vector3(1.00f, 1.00f, 1.00f);
282 integralFactor = new Vector3(1.00f, 1.00f, 1.00f); 296 integralFactor = new Vector3(1.00f, 1.00f, 1.00f);
283 derivFactor = new Vector3(1.00f, 1.00f, 1.00f); 297 derivFactor = new Vector3(1.00f, 1.00f, 1.00f);
284 IntegralFactor = Vector3.Zero; 298 RunningIntegration = Vector3.Zero;
285 LastError = Vector3.Zero; 299 LastError = Vector3.Zero;
286 } 300 }
287 301
@@ -311,15 +325,21 @@ public class BSPIDVMotor : BSVMotor
311 // Ignore Current and Target Values and just advance the PID computation on this error. 325 // Ignore Current and Target Values and just advance the PID computation on this error.
312 public override Vector3 Step(float timeStep, Vector3 error) 326 public override Vector3 Step(float timeStep, Vector3 error)
313 { 327 {
328 if (!Enabled) return Vector3.Zero;
329
314 // Add up the error so we can integrate over the accumulated errors 330 // Add up the error so we can integrate over the accumulated errors
315 IntegralFactor += error * timeStep; 331 RunningIntegration += error * timeStep;
316 332
317 // A simple derivitive is the rate of change from the last error. 333 // A simple derivitive is the rate of change from the last error.
318 Vector3 derivFactor = (error - LastError) * timeStep; 334 Vector3 derivFactor = (error - LastError) * timeStep;
319 LastError = error; 335 LastError = error;
320 336
321 // Correction = -(proportionOfPresentError + accumulationOfPastError + rateOfChangeOfError) 337 // Correction = -(proportionOfPresentError + accumulationOfPastError + rateOfChangeOfError)
322 Vector3 ret = -(error * proportionFactor + IntegralFactor * integralFactor + derivFactor * derivFactor); 338 Vector3 ret = -(
339 error * proportionFactor
340 + RunningIntegration * integralFactor
341 + derivFactor * derivFactor
342 );
323 343
324 return ret; 344 return ret;
325 } 345 }