コード例 #1
0
            /// <summary>Class that allow some high level control over the wheels. To be controlled, the wheels must be on the same grid than <paramref name="controller"/> and contain the keyword "Power"</summary>
            /// <param name="command">Command line where the commands will be registered</param>
            /// <param name="controller">Controller on the same grid than the wheels to get some physics information</param>
            /// <param name="gts">To retrieve the wheels</param>
            /// <param name="ini">Contains some serialized information for persistence</param>
            /// <param name="manager">To spawn the updater process</param>
            /// <param name="transformer">Transformer that transform world coordinates into the vehicules coordinate: Z must be parallel to the vehicle's forward direction an Y must be parallel to the vehicle's up direction</param>
            public WheelsController(CommandLine command, IMyShipController controller, IMyGridTerminalSystem gts, MyIni ini, ISaveManager manager, CoordinatesTransformer transformer)
            {
                this.transformer = transformer;
                this.controller  = controller;
                var wheels = new List <IMyMotorSuspension>();

                gts.GetBlocksOfType(wheels, w => w.CubeGrid == controller.CubeGrid && w.DisplayNameText.Contains("Power"));
                this.wheels = wheels.Select(w => new PowerWheel(w, this.WheelBase, transformer)).ToList();
                this.wheels.Sort((w1, w2) => Math.Sign(w1.Position.Z - w2.Position.Z)); // needed for calibration

                this.registerCommands(command);
                manager.Spawn(this.updateWheels, "wheels-controller", period: 10);
                manager.AddOnSave(this.save);

                if (ini.ContainsKey(SECTION, "cal-weight"))
                {
                    this.calibration = new Calibration()
                    {
                        Weight  = ini.Get(SECTION, "cal-weight").ToSingle(),
                        MinZ    = ini.Get(SECTION, "cal-min-z").ToDouble(),
                        MaxZ    = ini.Get(SECTION, "cal-max-z").ToDouble(),
                        MinMult = ini.Get(SECTION, "cal-min-mult").ToSingle(),
                        MaxMult = ini.Get(SECTION, "cal-max-mult").ToSingle()
                    };
                }

                this.targetRatio = ini.Get(SECTION, "target-ratio").ToSingle(0.35f);
                this.WheelBase.CenterOfTurnZOffset = ini.Get(SECTION, "turn-center-offset").ToDouble();
                this.WheelBase.TurnRadiusOverride  = ini.Get(SECTION, "turn-radius").ToDouble();
            }
コード例 #2
0
            public ArmController(MyIni ini, MyGridProgram p, CommandLine cmd, IMyShipController cont, WheelsController wCont, ISaveManager manager)
            {
                var rotors = new List <IMyMotorStator>();

                p.GridTerminalSystem.GetBlocksOfType(rotors, r => r.CubeGrid == p.Me.CubeGrid && r.DisplayNameText.Contains("Arm Rotor"));
                this.rotors = rotors.Select(r => new ArmRotor(r, r.WorldMatrix.Up.Dot(cont.WorldMatrix.Right) > 0)).ToList();
                var keys = new List <MyIniKey>();

                ini.GetKeys(SECTION, keys);
                this.pos               = keys.Where(k => !k.Name.StartsWith("$")).ToDictionary(k => k.Name, k => new ArmPos(ini.Get(k).ToString()));
                this.pos["$top"]       = new ArmPos(this.rotors[0].Max);
                this.pos["$mid"]       = new ArmPos(0.2f);
                this.pos["$bottom"]    = new ArmPos(this.rotors[0].Min);
                this.pos["$auto-high"] = new ArmPos(ArmPos.R_ELEVATION, 0);
                this.pos["$auto-low"]  = new ArmPos(ArmPos.L_ELEVATION, 0);
                var tools = new List <IMyFunctionalBlock>();

                p.GridTerminalSystem.GetBlocksOfType(tools, t => t.IsSameConstructAs(cont) && (t is IMyShipToolBase || t is IMyShipDrill));
                this.autoCont = new ArmAutoControl(ini, this.Angle, wCont, tools);

                cmd.RegisterCommand(new Command("arm-del", Command.Wrap(this.deletePosition), "Deletes a saved position of the arm", nArgs: 1));
                cmd.RegisterCommand(new Command("arm-elevation", Command.Wrap(this.autoElevate), "Makes the arm elevate at the correct position", detailedHelp: @"First argument is elevation ('high'/'low'/float)
Second argument is angle", maxArgs: 2));
                cmd.RegisterCommand(new Command("arm-drill", Command.Wrap(this.drill), "Engages the drills and move slowly to position", nArgs: 1));
                cmd.RegisterCommand(new Command("arm-recall", Command.Wrap(this.recallPosition), "Recalls a saved position of the arm", nArgs: 1));
                cmd.RegisterCommand(new Command("arm-save", Command.Wrap(this.savePosition), "Saves the current position of the arm", nArgs: 1));
                manager.Spawn(pc => this.updateRotors(cont), "arm-handle");
                manager.AddOnSave(this.save);
            }
コード例 #3
0
            public MiningRoutines(MyIni ini, CommandLine cmd, Autopilot ap, ISaveManager manager)
            {
                this.ap = ap;
                var keys = new List <MyIniKey>();

                ini.GetKeys("mining-routine", keys);
                keys.ForEach(k => this.miningRoutes[k.Name] = ini.Get(k).ToInt32());
                cmd.RegisterCommand(new Command("mine-recall", Command.Wrap(this._recall), "Goes to the given mining position", nArgs: 1));
                cmd.RegisterCommand(new Command("mine-save", Command.Wrap(this._savePos), "Saves the current mining position", nArgs: 1));
                manager.AddOnSave(_save);
            }
コード例 #4
0
ファイル: PilotAssist.cs プロジェクト: Schwartzmorn/SEScripts
 /// <summary>Creates a PilotAssist</summary>
 /// <param name="gts">To get the different blocks</param>
 /// <param name="ini">Parsed ini that contains the configuration. See <see cref="Read(Ini)"/> for more information</param>
 /// <param name="logger">Optional logger</param>
 /// <param name="manager">Used to schedule itself</param>
 /// <param name="wc">Wheel controller used to actually controll the wheels</param>
 public PilotAssist(IMyGridTerminalSystem gts, IniWatcher ini, Action <string> logger, ISaveManager manager, WheelsController wc)
 {
     this.logger           = logger;
     this.wheelControllers = wc;
     this.gts = gts;
     this.Read(ini);
     this.ManuallyBraked          = !this.shouldBrake() && this.Braked;
     this.wasPreviouslyAutoBraked = this.shouldBrake();
     manager.Spawn(this.handle, "pilot-assist");
     manager.AddOnSave(this.save);
     ini.Add(this);
 }
コード例 #5
0
ファイル: Autopilot.cs プロジェクト: Schwartzmorn/SEScripts
            /// <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);
            }
コード例 #6
0
            public SolarManager(Program p, CommandLine command, ISaveManager manager, Action <string> logger)
            {
                this.logger = logger;
                var ini = new MyIni();

                ini.TryParse(p.Me.CustomData);
                this.keyword   = ini.GetThrow(SECTION, "keyword").ToString("Solar Rotor");
                this.nightMode = ini.Get(SECTION, "night-mode").ToBoolean();
                Process main = manager.Spawn(process => this.main(), "solar-manager", period: 50);

                this.updator = new SolarUpdator(p, logger);
                this.update();
                main.Spawn(process => this.update(), "solar-manager-update", period: 10000);
                manager.AddOnSave(this.save);
                command.RegisterCommand(new Command("solar-adjust", Command.Wrap(this.adjust), "adjusts the position of a rotor", minArgs: 2, maxArgs: 3,
                                                    detailedHelp: @"first argument is the offset in degree
second argument is the id of the rotor
third (optional) is the id of the auxilliary rotor"));
                command.RegisterCommand(new Command("solar-track", Command.Wrap(this.track), "forces an idle rotor to start tracking", nArgs: 1));
            }