public HoverModule(CustomDataConfig config, GyroController gyroController, IMyShipController cockpit) { this.config = config; this.gyroController = gyroController; this.cockpit = cockpit; gyroResponsiveness = config.Get <int>("gyroResponsiveness"); maxPitch = config.Get <double>("maxPitch"); maxRoll = config.Get <double>("maxRoll"); AddAction("disabled", (args) => { gyroController.SetGyroOverride(false); }, null); AddAction("smart", (string[] args) => { smartDelayTimer = 0; setSpeed = (args.Length > 0 && args[0] != null) ? Int32.Parse(args[0]) : 0; }, () => { if (cockpit.MoveIndicator.Length() > 0.0f || cockpit.RotationIndicator.Length() > 0.0f) { desiredPitch = -(pitch - 90); desiredRoll = (roll - 90); gyroController.SetGyroOverride(false); smartDelayTimer = 0; } else if (smartDelayTimer > config.Get <int>("smartDelayTime")) { gyroController.SetGyroOverride(true); desiredPitch = Math.Atan((worldSpeedForward - setSpeed) / gyroResponsiveness) / Helpers.halfPi * maxPitch; desiredRoll = Math.Atan(worldSpeedRight / gyroResponsiveness) / Helpers.halfPi * maxRoll; } else { smartDelayTimer++; } }); AddAction("stop", null, () => { desiredPitch = Math.Atan(worldSpeedForward / gyroResponsiveness) / Helpers.halfPi * maxPitch; desiredRoll = Math.Atan(worldSpeedRight / gyroResponsiveness) / Helpers.halfPi * maxRoll; }); AddAction("glide", null, () => { desiredPitch = 0; desiredRoll = Math.Atan(worldSpeedRight / gyroResponsiveness) / Helpers.halfPi * maxRoll; }); AddAction("freeglide", null, () => { desiredPitch = 0; desiredRoll = 0; }); }
private void ProcessCommand(string argument) { string[] args = argument.Split(' '); if (args.Length < 1) { return; } switch (args[0].ToLower()) { case "hover": activeModule = hoverModule; break; case "vector": activeModule = vectorModule; break; case "stop": activeModule = null; gyroController.SetGyroOverride(false); break; case "reset": configReader.InitializeConfig(); break; } if (activeModule != null) { activeModule.ProcessCommand(args); } }
protected override void OnSetAction() { gyroController.SetGyroOverride(action?.execute != null); if (action?.execute != null) { cockpit.DampenersOverride = true; } }
public VectorModule(CustomDataConfig config, GyroController gyroController, IMyShipController cockpit) { this.gyroController = gyroController; this.cockpit = cockpit; thrustVector = GetThrustVector(config.Get <string>("spaceMainThrust")); AddAction("disabled", (args) => { gyroController.SetGyroOverride(false); }, null); AddAction("brake", (args) => { startSpeed = cockpit.GetShipSpeed(); cockpit.DampenersOverride = false; }, SpaceBrake); AddAction("prograde", null, () => { TargetOrientation(-Vector3D.Normalize(cockpit.GetShipVelocities().LinearVelocity)); }); AddAction("retrograde", null, () => { TargetOrientation(Vector3D.Normalize(cockpit.GetShipVelocities().LinearVelocity)); }); }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update1; configReader = new CustomDataConfig(Me, defaultConfig); GetBlocks(); gyroController = new GyroController(gyros, cockpit); hoverModule = new HoverModule(configReader, gyroController, cockpit); vectorModule = new VectorModule(configReader, gyroController, cockpit); string startCommand = configReader.Get <string>("startCommand"); if (startCommand != null) { ProcessCommand(startCommand); } else { gyroController.SetGyroOverride(false); } }
protected override void OnSetAction() { gyroController.SetGyroOverride(action?.execute != null); }
public void Main(string argument, UpdateType updateSource) { // execute user interaction if ((updateSource & UpdateType.Trigger) != 0 || (updateSource & UpdateType.Terminal) != 0) { if (argument.Contains("enable")) { disabled_ = false; } else if (argument.Contains("disable")) { gyroController_.ResetGyro(); disabled_ = true; } } // check landing landingInProgress_ = false; foreach (var gear in gears_) { if (gear.LockMode == LandingGearMode.Locked || gear.LockMode == LandingGearMode.ReadyToLock) { landingInProgress_ = true; break; } } // run normal iteration if ((updateSource & UpdateType.Update10) != 0) { // check natural gravity if (cockpit_.GetNaturalGravity().Length() == 0.0) { naturalGravity_ = false; gyroController_.SetGyroOverride(false); return; } else { naturalGravity_ = true; } if (landingInProgress_ == false && disabled_ == false) { // update all orientation parameters UpdateOrientationParameters(); // update gyroController gyroController_.Tick(); if (cockpit_.MoveIndicator.Length() > 0.0 || cockpit_.RotationIndicator.Length() > 0.0) { desiredPitch_ = -(pitch_ - 90); desiredRoll_ = (roll_ - 90); gyroController_.SetGyroOverride(false); } else { gyroController_.SetGyroOverride(true); desiredPitch_ = Math.Atan((worldSpeedForward_ - setSpeed_) / gyroResponsiveness_) / HalfPi * maxPitch_; desiredRoll_ = Math.Atan(worldSpeedRight_ / gyroResponsiveness_) / HalfPi * maxRoll_; } if (gyroController_.GyroOverride) { ExecuteManeuver(); } } } // generate lcd output and print them on messages_.Flush(); statistics_.tick(this); }