public void ThrustToVelocity(Vector3D velocity) { if (thrustPidController == null) { throw new Exception("wat de neuk thrustPid is null"); } if (thrustControl == null) { throw new Exception("wat de neuk thrustControl is null"); } if (ingameTime == null) { throw new Exception("wat de neuk ingameTime is null"); } Vector3D difference = velocity - ControlVelocity; double differenceMag = difference.Normalize(); double percent = thrustPidController.NextValue(differenceMag, (lastTime - ingameTime.Time).TotalSeconds); percent = MathHelperD.Clamp(percent, 0, 1); thrustControl.ApplyForce(difference, percent); lastTime = ingameTime.Time; }
public void Main() { if (accelerateTarget == null || accelerateTarget == Vector3D.Zero || accelerateTarget == Vector3D.PositiveInfinity || PID_Controller == null || !accelerateTarget.IsValid()) { return; } Vector3D accelerateTargetNormalized = accelerateTarget; double accelerateTargetLength = accelerateTargetNormalized.Normalize(); double error = Vector3D.Dot(control.WorldMatrix.Forward, accelerateTarget) + accelerateTargetLength; double multiplier = Math.Abs(PID_Controller.NextValue(error, 0.016)); if (accelerateTargetLength < negligible) { accelerateTargetNormalized = Vector3D.Normalize(control.GetShipVelocities().LinearVelocity); } GyroUtils.PointInDirection(gyros, control, accelerateTargetNormalized, multiplier); //ThrustUtils.SetThrustBasedDot(thrusters, accelerateTargetNormalized, multiplier); autopilotModule.ThrustToVelocity(control.GetShipVelocities().LinearVelocity + accelerateTarget); if (accelerateInDirection && control.GetShipSpeed() >= (speedLimit - 0.01)) { accelerateTarget = Vector3D.Zero; BoostForward(0); accelerateInDirection = false; } }
public void PointInDirection(List <IMyGyro> gyros, MatrixD reference, Vector3D direction, Vector3D up) { double yaw, pitch, roll; GyroUtils.DirectionToPitchYawRoll(reference, direction, up, out yaw, out pitch, out roll); double timeSinceLast = (ingameTime.Time - lastTime).TotalSeconds; lastTime = ingameTime.Time; yaw = yawPid.NextValue(yaw, timeSinceLast); pitch = pitchPid.NextValue(pitch, timeSinceLast); roll = rollPid.NextValue(roll, timeSinceLast); GyroUtils.ApplyGyroOverride(gyros, reference, pitch, yaw, roll, onlyUpdateOne); }
public void ThrustToVelocity(Vector3D velocity) { Vector3D difference = velocity - ControlVelocity; double differenceMag = difference.Normalize(); double percent = thrustPidController.NextValue(differenceMag, (lastTime - ingameTime.Time).TotalSeconds); percent = MathHelperD.Clamp(percent, 0, 1); thrustControl.ApplyForce(difference, percent); lastTime = ingameTime.Time; }