diff options
author | Robert Adams | 2012-12-22 17:06:13 -0800 |
---|---|---|
committer | Robert Adams | 2012-12-22 17:06:13 -0800 |
commit | 16e49035f7420979aa7f77ac63b951a32aa0bd6b (patch) | |
tree | 4a7f42ea62a6b7a207502a668085fbd5fd55c33f | |
parent | Add helper routine Util.InRange() (diff) | |
download | opensim-SC-16e49035f7420979aa7f77ac63b951a32aa0bd6b.zip opensim-SC-16e49035f7420979aa7f77ac63b951a32aa0bd6b.tar.gz opensim-SC-16e49035f7420979aa7f77ac63b951a32aa0bd6b.tar.bz2 opensim-SC-16e49035f7420979aa7f77ac63b951a32aa0bd6b.tar.xz |
BulletSim: add Enabled parameter and operation to motors.
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index 8781fe9..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)) |
@@ -313,6 +325,8 @@ public class BSPIDVMotor : BSVMotor | |||
313 | // 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. |
314 | public override Vector3 Step(float timeStep, Vector3 error) | 326 | public override Vector3 Step(float timeStep, Vector3 error) |
315 | { | 327 | { |
328 | if (!Enabled) return Vector3.Zero; | ||
329 | |||
316 | // 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 |
317 | RunningIntegration += error * timeStep; | 331 | RunningIntegration += error * timeStep; |
318 | 332 | ||