/// <summary>Creates a new Autopilot</summary> /// <param name="ini"></param> /// <param name="wheels"></param> /// <param name="cmd"></param> /// <param name="remote"></param> /// <param name="logger"></param> /// <param name="manager"></param> public Autopilot(MyIni ini, WheelsController wheels, CommandLine cmd, IMyRemoteControl remote, Action <string> logger, ISaveManager manager) { this.activated = ini.Get("auto-pilot", "activated").ToBoolean(); this.logger = logger; Process p = manager.Spawn(this.handle, "ap-handle"); this.Network = new WPNetwork(remote, logger, p); this.remote = remote; this.transformer = new CoordinatesTransformer(remote, p); this.wheels = wheels; cmd.RegisterCommand(new Command("ap-move", Command.Wrap(this.move), "Move forward", minArgs: 1, maxArgs: 2)); cmd.RegisterCommand(new Command("ap-goto", Command.Wrap(this.GoTo), "Go to the waypoint", nArgs: 1)); cmd.RegisterCommand(new Command("ap-switch", Command.Wrap(this.Switch), "Switches the autopilot on/off", nArgs: 1)); cmd.RegisterCommand(new Command("ap-save", Command.Wrap(this.Save), "Save the current position", nArgs: 1)); manager.AddOnSave(this.save); }
/// <summary>Translates the list of waypoint names from the ini string to a list of actual <see cref="APWaypoint"/></summary> /// <param name="network">Network that contains all the waypoints</param> /// <param name="logger">Optional logger</param> public void Update(WPNetwork network, Action <string> logger) { if (this.waypointsNames != null) { int notFound = 0; foreach (string wpName in this.waypointsNames) { APWaypoint wp = network.GetWaypoint(wpName); if (wp == null) { ++notFound; } else { this.LinkedWps.Add(wp); } } if (notFound != 0) { logger?.Invoke($"Waypoint '{this.Name}' links to {notFound} unknown waypoints"); } } }