diff options
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index 91255bd..6d0db2e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | |||
@@ -388,6 +388,12 @@ public class BSPIDVMotor : BSVMotor | |||
388 | public Vector3 integralFactor { get; set; } | 388 | public Vector3 integralFactor { get; set; } |
389 | public Vector3 derivFactor { get; set; } | 389 | public Vector3 derivFactor { get; set; } |
390 | 390 | ||
391 | // The factors are vectors for the three dimensions. This is the proportional of each | ||
392 | // that is applied. This could be multiplied through the actual factors but it | ||
393 | // is sometimes easier to manipulate the factors and their mix separately. | ||
394 | // to | ||
395 | public Vector3 FactorMix; | ||
396 | |||
391 | // Arbritrary factor range. | 397 | // Arbritrary factor range. |
392 | // EfficiencyHigh means move quickly to the correct number. EfficiencyLow means might over correct. | 398 | // EfficiencyHigh means move quickly to the correct number. EfficiencyLow means might over correct. |
393 | public float EfficiencyHigh = 0.4f; | 399 | public float EfficiencyHigh = 0.4f; |
@@ -402,6 +408,7 @@ public class BSPIDVMotor : BSVMotor | |||
402 | proportionFactor = new Vector3(1.00f, 1.00f, 1.00f); | 408 | proportionFactor = new Vector3(1.00f, 1.00f, 1.00f); |
403 | integralFactor = new Vector3(1.00f, 1.00f, 1.00f); | 409 | integralFactor = new Vector3(1.00f, 1.00f, 1.00f); |
404 | derivFactor = new Vector3(1.00f, 1.00f, 1.00f); | 410 | derivFactor = new Vector3(1.00f, 1.00f, 1.00f); |
411 | FactorMix = new Vector3(0.5f, 0.25f, 0.25f); | ||
405 | RunningIntegration = Vector3.Zero; | 412 | RunningIntegration = Vector3.Zero; |
406 | LastError = Vector3.Zero; | 413 | LastError = Vector3.Zero; |
407 | } | 414 | } |
@@ -417,15 +424,18 @@ public class BSPIDVMotor : BSVMotor | |||
417 | set | 424 | set |
418 | { | 425 | { |
419 | base.Efficiency = Util.Clamp(value, 0f, 1f); | 426 | base.Efficiency = Util.Clamp(value, 0f, 1f); |
427 | |||
420 | // Compute factors based on efficiency. | 428 | // Compute factors based on efficiency. |
421 | // If efficiency is high (1f), use a factor value that moves the error value to zero with little overshoot. | 429 | // If efficiency is high (1f), use a factor value that moves the error value to zero with little overshoot. |
422 | // If efficiency is low (0f), use a factor value that overcorrects. | 430 | // If efficiency is low (0f), use a factor value that overcorrects. |
423 | // TODO: might want to vary contribution of different factor depending on efficiency. | 431 | // TODO: might want to vary contribution of different factor depending on efficiency. |
424 | float factor = ((1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow) / 3f; | 432 | float factor = ((1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow) / 3f; |
425 | // float factor = (1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow; | 433 | // float factor = (1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow; |
434 | |||
426 | proportionFactor = new Vector3(factor, factor, factor); | 435 | proportionFactor = new Vector3(factor, factor, factor); |
427 | integralFactor = new Vector3(factor, factor, factor); | 436 | integralFactor = new Vector3(factor, factor, factor); |
428 | derivFactor = new Vector3(factor, factor, factor); | 437 | derivFactor = new Vector3(factor, factor, factor); |
438 | |||
429 | MDetailLog("{0},BSPIDVMotor.setEfficiency,eff={1},factor={2}", BSScene.DetailLogZero, Efficiency, factor); | 439 | MDetailLog("{0},BSPIDVMotor.setEfficiency,eff={1},factor={2}", BSScene.DetailLogZero, Efficiency, factor); |
430 | } | 440 | } |
431 | } | 441 | } |
@@ -439,18 +449,17 @@ public class BSPIDVMotor : BSVMotor | |||
439 | RunningIntegration += error * timeStep; | 449 | RunningIntegration += error * timeStep; |
440 | 450 | ||
441 | // A simple derivitive is the rate of change from the last error. | 451 | // A simple derivitive is the rate of change from the last error. |
442 | Vector3 derivFactor = (error - LastError) * timeStep; | 452 | Vector3 derivitive = (error - LastError) * timeStep; |
443 | LastError = error; | 453 | LastError = error; |
444 | 454 | ||
445 | // Correction = -(proportionOfPresentError + accumulationOfPastError + rateOfChangeOfError) | 455 | // Correction = (proportionOfPresentError + accumulationOfPastError + rateOfChangeOfError) |
446 | Vector3 ret = -( | 456 | Vector3 ret = error * timeStep * proportionFactor * FactorMix.X |
447 | error * proportionFactor | 457 | + RunningIntegration * integralFactor * FactorMix.Y |
448 | + RunningIntegration * integralFactor | 458 | + derivitive * derivFactor * FactorMix.Z |
449 | + derivFactor * derivFactor | 459 | ; |
450 | ); | ||
451 | 460 | ||
452 | MDetailLog("{0},BSPIDVMotor.step,ts={1},err={2},runnInt={3},derivFact={4},ret={5}", | 461 | MDetailLog("{0},BSPIDVMotor.step,ts={1},err={2},runnInt={3},deriv={4},ret={5}", |
453 | BSScene.DetailLogZero, timeStep, error, RunningIntegration, derivFactor, ret); | 462 | BSScene.DetailLogZero, timeStep, error, RunningIntegration, derivitive, ret); |
454 | 463 | ||
455 | return ret; | 464 | return ret; |
456 | } | 465 | } |