Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Automatic Landing System

Discussion in 'Programming (In-game)' started by hungabal, Mar 10, 2020.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. hungabal Trainee Engineer

    Messages:
    7
    Hi,
    I try to build an Automatic Landing System but the code fails.
    During landing at a certain hight from sea level the space ships stops and does not continue descending.
    Here is my code:

    Code:
    using Sandbox.Game.EntityComponents;
    using Sandbox.ModAPI.Ingame;
    using Sandbox.ModAPI.Interfaces;
    using SpaceEngineers.Game.ModAPI.Ingame;
    using System.Collections.Generic;
    using System.Collections;
    using System.Linq;
    using System.Text;
    using System;
    using VRage.Collections;
    using VRage.Game.Components;
    using VRage.Game.GUI.TextPanel;
    using VRage.Game.ModAPI.Ingame.Utilities;
    using VRage.Game.ModAPI.Ingame;
    using VRage.Game.ObjectBuilders.Definitions;
    using VRage.Game;
    using VRage;
    using VRageMath;
    using Sandbox.Game.Entities;
    
    namespace IngameScript
    {
    	partial class Program : MyGridProgram
    	{
    		/*
    		 *
    		 * LEÍRÁS START:
    		 *
    		 *
    			Argument: (programozható blokk és időzítő blokk) ||| HA TÖBB AZ ARGUMENTUM AKKOR ; AZ ELVÁLASZTÁSHOZ
    
    			- atstartolas :beindítja a hajtóműveket max tolóerőn és vissza repül az űrbe a vészhelyzeti vektorhoz!
    			- indulasellenorzes :átellenőrzi a rakétát hogy minden be van-e állítva!
    			- forditas;50.0f :A rakéta fordítása kóddal (pitch,roll,yaw) és az értéke
    			- indulas :elindítja a rakétát az útjára. Át a koordinátákon majd a föld felé irányítja.
    			- eroltetettleszallas :kikapcsolja a rakétákat és szabad esésben a föld felé esünk. (csak ha nagyon közel vagyunk a földhöz!)
    			- precizios;20;0.5;0.8;felso :saját sebességet és G erőt állíthatunk be mind a közeledéshez(felso) mind a felszín felett(also)
    			- precizios;20;1.0;1.0;also :saját sebességet és G erőt állíthatunk be mind a közeledéshez(felso) mind a felszín felett(also)
    
    
    			npc.WorldMatrix.Down
    		 *
    		 *
    		 * :LEÍRÁS END
    		 * NEVEK START:
    		 *
    		 */
    		public string AI = "Távirányítás";//RemoteControl
    		public string tankHirdogen1 = "Hydrogen Tank";//GasTank
    		/*public string tankHirdogen2 = "";//GasTank*/
    		public string panellcd = "LCDPanel";//TextPanel
    		public string timerido = "timerido";//TimerBlock
    		public string talpak = "talpak";//LandingGear
    		public string giroszkop = "giroszkop";//Gyro
    		public string doorajto = "doorajto";//Door
    		public string kishajtomu = "kishajtomu";//SmallThruster - csak a lesszálláshoz használtat [hidrogén]
    		public string nagyhajtomu = "nagyhajtomu";//BigThruster - csak a lesszálláshoz használtat [hidrogén]
    		public string egyebhajtomu = "egyebhajtomu";//EgyebThruster - minden űrben folytatott mozgásra [energia]
    		public string erzekelo = "erzekelo";//Érzékelő ami a hajó alján van [sensor block]
    
    
    
    		public Vector3D ut0 = new Vector3D(15997.47, 107371.25, -118098.69);//1. Pont
    		public Vector3D ut1 = new Vector3D(6274.26, 68760.38, -84365.53);//2. Pont
    		public Vector3D ut2 = new Vector3D(6281.60, 67355.22, -83006.51);//3. Pont
    		public Vector3D ut3 = new Vector3D(6425.42, 66107.75, -81666.67);//4. Pont
    
    		public Vector3D parkolas = new Vector3D(6876.70, 67811.16, -82658.01);//vészhelyzeti vektor->a földtől nem messze,de kint az űrbe.Ide fog visszatérni a rakéta..
    		/*
    		 *
    		 * :NEVEK END
    		 *
    		 */
    
    		public String[] resz = new String[5];
    		public bool fold = false;
    		public float tavolsag = 50.0f;
    		public float forditasi_helyzet = 0.0f;
    		public Vector3D vegsopont;
    
    		IMyRemoteControl npc;
    
    		IMyGasTank hidrogentank1;
    		/*IMyGasTank hidrogentank2;*/
    
    		/*IMyGyro giro;*/
    		List<IMyTerminalBlock> GIROSZKOP_LISTA = new List<IMyTerminalBlock>();
    
    		List<IMyTerminalBlock> LANDINGGEAR_LISTA = new List<IMyTerminalBlock>();
    
    		IMyTimerBlock idozito1;
    
    		IMyTextPanel panel1;
    
    		IMyDoor ajto1;
    
    		IMySensorBlock szenzor;
    
    		List<IMyTerminalBlock> BIG_HIDROGEN_TRUSTER_LISTA = new List<IMyTerminalBlock>();
    		List<IMyTerminalBlock> SMALL_HIDROGEN_TRUSTER_LISTA = new List<IMyTerminalBlock>();
    
    		List<IMyTerminalBlock> EGYEB_TRUSTER_LISTA = new List<IMyTerminalBlock>();
    
    		public Program()
    		{
    			npc = GridTerminalSystem.GetBlockWithName(AI) as IMyRemoteControl;
    
    			hidrogentank1 = GridTerminalSystem.GetBlockWithName(tankHirdogen1) as IMyGasTank;
    			/*hidrogentank2 = GridTerminalSystem.GetBlockWithName(tankHirdogen2) as IMyGasTank;*/
    
    			idozito1 = GridTerminalSystem.GetBlockWithName(timerido) as IMyTimerBlock;
    
    			szenzor = GridTerminalSystem.GetBlockWithName(erzekelo) as IMySensorBlock;
    
    			ajto1 = GridTerminalSystem.GetBlockWithName(doorajto) as IMyDoor;
    
    			/*giro = GridTerminalSystem.GetBlockWithName(giroszkop) as IMyGyro;*/
    			GridTerminalSystem.GetBlockGroupWithName(giroszkop).GetBlocksOfType<IMyGyro>(GIROSZKOP_LISTA);
    
    			GridTerminalSystem.GetBlockGroupWithName(talpak).GetBlocksOfType<IMyLandingGear>(LANDINGGEAR_LISTA);
    
    			panel1 = GridTerminalSystem.GetBlockWithName(panellcd) as IMyTextPanel;
    
    			GridTerminalSystem.GetBlockGroupWithName(nagyhajtomu).GetBlocksOfType<IMyThrust>(BIG_HIDROGEN_TRUSTER_LISTA);
    			GridTerminalSystem.GetBlockGroupWithName(kishajtomu).GetBlocksOfType<IMyThrust>(SMALL_HIDROGEN_TRUSTER_LISTA);
    
    			GridTerminalSystem.GetBlockGroupWithName(egyebhajtomu).GetBlocksOfType<IMyThrust>(EGYEB_TRUSTER_LISTA);
    
    		}
    
    		public void Main(string argument)
    		{
    
    			//argument split függv.
    
    			if (argument.Contains(';'))
    			{
    				resz = argument.Split(';');// resz[0];resz[1];resz[2];resz[3];resz[4]
    			}
    
    			Vector3D jelenlegi = npc.GetPosition();
    
    			double grav = npc.GetNaturalGravity().Length() / 9.81;
    			grav = Math.Round(grav, 2);
    
    			double speed = npc.GetShipSpeed();
    			double gyorsasag = Math.Round(speed, 2);
    
    			int hidrogenszazalek1 = Convert.ToInt32(hidrogentank1.FilledRatio * 100);
    			/*int hidrogenszazalek2 = Convert.ToInt32(hidrogentank2.FilledRatio * 100);*/
    
    			for (int i = 0; i < hidrogenszazalek1; i++)
    			{
    				panel1.WriteText("|", true);
    			}
    			panel1.WriteText(" - Hidrogén1: " + hidrogenszazalek1.ToString() + " %" + "\n\n", true);
    
    			/*for (int i = 0; i < hidrogenszazalek2; i++)
    			{
    				panel1.WriteText("|", true);
    			}
    			panel1.WriteText(" - Hidrogén2: " + hidrogenszazalek2.ToString() + " %" + "\n\n", true);*/
    
    			if (argument == "atstartolas" || resz[0] == "atstartolas")
    			{
    
    				idozito1.StopCountdown();
    				idozito1.ApplyAction("OnOff_Off");
    
    				npc.ClearWaypoints();
    				npc.AddWaypoint(parkolas, "parkolas");
    				npc.SetValue<long>("FlightMode", 2);
    				npc.SetValue<long>("Direction", 0);
    				npc.SetValueBool("DockingMode", false);
    				npc.SetValueBool("CollisionAvoidance", false);
    				npc.ApplyAction("AutoPilot_On");
    				npc.SetAutoPilotEnabled(true);
    
    				panel1.WriteText("Átstartolás folyamatban...\n", true);
    
    			}
    			else if (argument == "forditas" || resz[0] == "forditas")
    			{
    
    				//resz[1]=Yaw/Roll/Pitch
    				//resz[2]=50.0f-->értéke
    				foreach (IMyGyro giro in GIROSZKOP_LISTA)
    				{
    					giro.SetValue<Single>(resz[1], float.Parse(resz[2]));
    					giro.ApplyAction("Override");
    					giro.SetValueBool("Override", true);
    				}
    
    				foreach (IMyGyro giro in GIROSZKOP_LISTA)
    				{
    					forditasi_helyzet = giro.GetValue<Single>("Yaw");
    				}
    
    				if (forditasi_helyzet == 180.0f)
    				{
    					foreach (IMyGyro giro in GIROSZKOP_LISTA)
    					{
    						giro.SetValue<Single>("Yaw", 0);
    						giro.ApplyAction("Override");
    						giro.SetValueBool("Override", true);
    					}
    				}
    
    			}
    			else if (argument == "indulasellenorzes" || resz[0] == "indulasellenorzes")
    			{
    
    				idozito1.StopCountdown();
    				idozito1.ApplyAction("OnOff_Off");
    
    				try
    				{
    					ajto1.ApplyAction("Open_Off");
    					panel1.WriteText("Az ajtó bezáródott!\n", true);
    
    					foreach (IMyLandingGear talp in LANDINGGEAR_LISTA)
    					{
    						talp.AutoLock = true;
    					}
    
    					panel1.WriteText("A talpakat beállítottuk automatikus elkapásra!\n", true);
    				}
    				catch (Exception e)
    				{
    					panel1.WriteText("Az ajtó hibás\n", true);
    					panel1.WriteText("A talpak hibásak\n", true);
    					return;
    				}
    
    				try
    				{
    					foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    					{
    						thrust.ApplyAction("OnOff_On");
    					}
    					foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    					{
    						thrust.ApplyAction("OnOff_On");
    					}
    
    					panel1.WriteText("A hajtóművek rendben vannak!\n", true);
    				}
    				catch (Exception e)
    				{
    					panel1.WriteText("A hajtóművek hibásak!\n", true);
    					return;
    				}
    
    				
    				/*if (hidrogenszazalek1>80 && hidrogenszazalek2 > 80)
    				{
    					panel1.WriteText(" - Hidrogén1: Megfelelő mennyiségű.\n", true);
    
    					panel1.WriteText(" - Hidrogén2: Megfelelő mennyiségű.\n", true);
    				}
    				else
    				{
    					panel1.WriteText(" - Hidrogén1: Kevés!\n", true);
    
    					panel1.WriteText(" - Hidrogén2: Kevés!\n", true);
    				} */
    
    			}
    			else if (argument == "indulas" || resz[0] == "indulas")
    			{
    
    				foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    				{
    					thrust.ApplyAction("OnOff_Off");
    				}
    				foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    				{
    					thrust.ApplyAction("OnOff_Off");
    				}
    
    				foreach (IMyThrust thrust in EGYEB_TRUSTER_LISTA)
    				{
    					thrust.ApplyAction("OnOff_On");
    				}
    
    				try
    				{
    
    					npc.ClearWaypoints();
    					npc.AddWaypoint(ut0, "ut0");
    					npc.SetValue<long>("FlightMode", 2);
    					npc.SetValue<long>("Direction", 0);
    					npc.SetValueBool("DockingMode", false);
    					npc.SetValueBool("CollisionAvoidance", false);
    					npc.ApplyAction("AutoPilot_On");
    					npc.SetAutoPilotEnabled(true);
    					panel1.WriteText("A robotpilóta elindult!\n", true);
    
    				}
    				catch (Exception e)
    				{
    					panel1.WriteText("A robotpilóta nem működik!\n", true);
    					return;
    				}
    
    				try
    				{
    					idozito1.ApplyAction("OnOff_On");
    					idozito1.SetValueFloat("TriggerDelay", 1.0f);
    					idozito1.StartCountdown();
    
    					panel1.WriteText("Az időzítő beindult!\n", true);
    				}
    				catch (Exception e)
    				{
    					panel1.WriteText("Az időzítő nem működik!\n", true);
    					return;
    				}
    
    			}
    			else if (argument == "eroltetettleszallas" || resz[0] == "eroltetettleszallas")
    			{
    
    				idozito1.StopCountdown();
    				idozito1.ApplyAction("OnOff_Off");
    
    				try
    				{
    					foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    					{
    						thrust.ApplyAction("OnOff_Off");
    					}
    					foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    					{
    						thrust.ApplyAction("OnOff_Off");
    					}
    
    					panel1.WriteText("A hajtóművek leálltak!\n", true);
    				}
    				catch (Exception e)
    				{
    					panel1.WriteText("A hajtóművek még működnek,a leszálláshoz manuális beavatkozás kell!\n", true);
    					return;
    				}
    			}
    			else if (argument == "precizios" || resz[0] == "precizios")//resz[0];resz[1];resz[2];resz[3];resz[4] == argument;sebbesség;G-erő-tól;G-erő-ig;felso vagy also
    			{
    
    				if (grav > Convert.ToDouble(resz[2]) && grav < Convert.ToDouble(resz[3]) && resz[4] == "felso")
    				{
    
    					panel1.WriteText("A gravitáció 0.8-at elérte!\n", true);
    
    					if (gyorsasag > Convert.ToDouble(resz[1]))
    					{
    
    						panel1.WriteText("A gyorsaság nagyobb mint "+ resz[1] + " m/s!\n", true);
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_On");
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_On");
    						}
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 5000000.0f);
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 5000000.0f);
    						}
    
    					}
    					else
    					{
    
    						panel1.WriteText("A gyorsaság kisebb mint "+ resz[1] + " m/s!\n", true);
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_Off");
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_Off");
    						}
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 0.0f);
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 0.0f);
    						}
    					}
    
    				}
    				else if (grav > Convert.ToDouble(resz[2]) || grav == Convert.ToDouble(resz[3]) && resz[4] == "also")
    				{
    
    					panel1.WriteText("A gravitáció elérte az "+ resz[2] + " -t!\n", true);
    
    					if (gyorsasag > Convert.ToDouble(resz[1]))
    					{
    
    						panel1.WriteText("A gyorsaság nagyobb mint "+ resz[1] + " m/s!\n", true);
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_On");
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_On");
    						}
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 5000000.0f);
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 5000000.0f);
    						}
    
    					}
    					else
    					{
    
    						panel1.WriteText("A gyorsaság kisebb mint "+ resz[1] + " m/s!\n", true);
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_Off");
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_Off");
    						}
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 0.0f);
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 0.0f);
    						}
    					}
    
    				}
    
    			}
    			else
    			{
    
    				//ÚT ELLENŐRZÉS:
    				if ((jelenlegi == ut0) || (jelenlegi.X < ut0.X + 50 && jelenlegi.X > ut0.X - 50) && (jelenlegi.Y < ut0.Y + 50 && jelenlegi.Y > ut0.Y - 50) && (jelenlegi.Z < ut0.Z + 50 && jelenlegi.Z > ut0.Z - 50))
    				{
    					npc.ClearWaypoints();
    					npc.AddWaypoint(ut1, "ut1");
    					npc.SetValue<long>("FlightMode", 2);
    					npc.SetValue<long>("Direction", 5);
    					npc.SetValueBool("DockingMode", false);
    					npc.SetValueBool("CollisionAvoidance", false);
    					npc.ApplyAction("AutoPilot_On");
    					npc.SetAutoPilotEnabled(true);
    					panel1.WriteText("\n\rElértük az ut 2-t!", true);
    				}
    
    				if ((jelenlegi == ut1) || (jelenlegi.X < ut1.X + 50 && jelenlegi.X > ut1.X - 50) && (jelenlegi.Y < ut1.Y + 50 && jelenlegi.Y > ut1.Y - 50) && (jelenlegi.Z < ut1.Z + 50 && jelenlegi.Z > ut1.Z - 50))
    				{
    					npc.ClearWaypoints();
    					npc.AddWaypoint(ut2, "ut2");
    					npc.SetValue<long>("FlightMode", 2);
    					npc.SetValue<long>("Direction", 5);
    					npc.SetValueBool("DockingMode", false);
    					npc.SetValueBool("CollisionAvoidance", false);
    					npc.ApplyAction("AutoPilot_On");
    					npc.SetAutoPilotEnabled(true);
    					panel1.WriteText("\n\rElértük az ut 2-t!", true);
    				}
    
    				if ((jelenlegi == ut2) || (jelenlegi.X < ut2.X + 50 && jelenlegi.X > ut2.X - 50) && (jelenlegi.Y < ut2.Y + 50 && jelenlegi.Y > ut2.Y - 50) && (jelenlegi.Z < ut2.Z + 50 && jelenlegi.Z > ut2.Z - 50))
    				{
    					npc.ClearWaypoints();
    					npc.AddWaypoint(ut3, "ut3");
    					npc.SetValue<long>("FlightMode", 2);
    					npc.SetValue<long>("Direction", 5);
    					npc.SetValueBool("DockingMode", false);
    					npc.SetValueBool("CollisionAvoidance", false);
    					npc.ApplyAction("AutoPilot_On");
    					npc.SetAutoPilotEnabled(true);
    					panel1.WriteText("\n\rElértük az ut 3-t!", true);
    				}
    
    				if ((jelenlegi == ut3) || (jelenlegi.X < ut3.X + 50 && jelenlegi.X > ut3.X - 50) && (jelenlegi.Y < ut3.Y + 50 && jelenlegi.Y > ut3.Y - 50) && (jelenlegi.Z < ut3.Z + 50 && jelenlegi.Z > ut3.Z - 50))
    				{
    					panel1.WriteText("\n\rElértük a végső pontot!", true);
    					npc.ApplyAction("AutoPilot_Off");
    
    					foreach (IMyThrust thrust in EGYEB_TRUSTER_LISTA)
    					{
    						thrust.ApplyAction("OnOff_Off");
    					}
    
    					foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    					{
    						thrust.ApplyAction("OnOff_On");
    					}
    
    					foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    					{
    						thrust.SetValueFloat("Override", 5000000.0f);
    					}
    
    				}
    
    				if (grav >= 0.5 && grav <= 0.7)
    				{
    					/*foreach (IMyGyro giro in GIROSZKOP_LISTA)
    					{
    						giro.SetValue<Single>(resz[1], float.Parse(resz[2]));
    						giro.ApplyAction("Override");
    						giro.SetValueBool("Override", true);
    					}*/
    
    					panel1.WriteText("180 fok fordítás!\n", true);
    				}
    
    				if (grav>=0.7 && grav<=0.8)
    				{
    					panel1.WriteText("A gravitáció 0.5-at elérte!\n", true);
    
    					if (gyorsasag > 50)
    					{
    
    						panel1.WriteText("A gyorsaság nagyobb mint 50 m/s!\n", true);
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_On");
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_On");
    						}
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 5000000.0f);
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 5000000.0f);
    						}
    
    					}
    					else
    					{
    
    						panel1.WriteText("A gyorsaság kisebb mint 50 m/s!\n", true);
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_Off");
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_Off");
    						}
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 0.0f);
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 0.0f);
    						}
    					}
    				}
    				else if (grav>0.8 && grav<1.0)
    				{
    
    					panel1.WriteText("A gravitáció 0.8-at elérte!\n", true);
    
    					if (gyorsasag>20)
    					{
    
    						panel1.WriteText("A gyorsaság nagyobb mint 20 m/s!\n", true);
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_On");
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_On");
    						}
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 5000000.0f);
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 5000000.0f);
    						}
    
    					}
    					else
    					{
    
    						panel1.WriteText("A gyorsaság kisebb mint 20 m/s!\n", true);
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_Off");
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_Off");
    						}
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 0.0f);
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 0.0f);
    						}
    					}
    
    				}
    				else if (grav > 1.0 || grav == 1.0 && fold == false)
    				{
    
    					panel1.WriteText("A gravitáció elérte az 1.0-t!\n", true);
    
    					if (gyorsasag > 20)
    					{
    
    						panel1.WriteText("A gyorsaság nagyobb mint 5 m/s!\n", true);
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_On");
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_On");
    						}
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 5000000.0f);
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 5000000.0f);
    						}
    
    					}
    					else
    					{
    
    						panel1.WriteText("A gyorsaság kisebb mint 5 m/s!\n", true);
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_Off");
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.ApplyAction("OnOff_Off");
    						}
    
    						foreach (IMyThrust thrust in BIG_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 0.0f);
    						}
    						foreach (IMyThrust thrust in SMALL_HIDROGEN_TRUSTER_LISTA)
    						{
    							thrust.SetValueFloat("Override", 0.0f);
    						}
    					}
    
    					fold = true;
    
    				}
    
    				if (grav == 1.0 && fold == true)
    				{
    					bool kozelseg_erzekelo = szenzor.IsActive;
    
    					if (kozelseg_erzekelo == true)
    					{
    						Vector3D ereszkedo_pont = npc.WorldMatrix.Down * 10 + jelenlegi;
    						tavolsag = tavolsag - 5.0f;
    
    						npc.ClearWaypoints();
    						npc.AddWaypoint(ereszkedo_pont, "ereszkedo_pont");
    						npc.SetValue<long>("FlightMode", 2);
    						npc.SetValue<long>("Direction", 5);
    						npc.SetValueFloat("SpeedLimit", 5.0f);
    						npc.SetValueBool("DockingMode", true);
    						npc.SetValueBool("CollisionAvoidance", true);
    						npc.ApplyAction("AutoPilot_On");
    						npc.SetAutoPilotEnabled(true);
    					}
    					else
    					{
    						Vector3D ereszkedo_pont = npc.WorldMatrix.Down * 10 + jelenlegi;
    
    						npc.ClearWaypoints();
    						npc.AddWaypoint(ereszkedo_pont, "ereszkedo_pont");
    						npc.SetValue<long>("FlightMode", 2);
    						npc.SetValue<long>("Direction", 5);
    						npc.SetValueFloat("SpeedLimit", 5.0f);
    						npc.SetValueBool("DockingMode", true);
    						npc.SetValueBool("CollisionAvoidance", true);
    						npc.ApplyAction("AutoPilot_On");
    						npc.SetAutoPilotEnabled(true);
    					}
    
    					/*var boundingBox = npc.WorldAABB;
    					var nearestPlanet = MyGamePruningStructure.GetClosestPlanet(ref boundingBox);
    					var position = nearestPlanet.PositionComp.GetPosition();
    
    					npc.ClearWaypoints();
    					npc.AddWaypoint(position, "position");
    					npc.SetValue<long>("FlightMode", 2);
    					npc.SetValue<long>("Direction", 1);
    					npc.SetValueFloat("SpeedLimit", 5.0f);
    					npc.SetValueBool("DockingMode", true);
    					npc.SetValueBool("CollisionAvoidance", true);
    					npc.ApplyAction("AutoPilot_On");
    					npc.SetAutoPilotEnabled(true);
    
    					bool kozelseg_erzekelo = szenzor.IsActive;
    
    					if (position == jelenlegi)
    					{
    						if (kozelseg_erzekelo == true)
    						{
    							if (tavolsag == 15.0f)
    							{
    								var mostanihely = npc.GetPosition();
    								npc.ClearWaypoints();
    								npc.AddWaypoint(mostanihely, "mostanihely");
    								npc.SetValue<long>("FlightMode", 2);
    								npc.SetValue<long>("Direction", 1);
    								npc.SetValueFloat("SpeedLimit", 5.0f);
    								npc.SetValueBool("DockingMode", true);
    								npc.SetValueBool("CollisionAvoidance", true);
    								npc.ApplyAction("AutoPilot_On");
    								npc.SetAutoPilotEnabled(true);
    								panel1.WriteText("TOLDD KI A TALPAKAT!\n", true);
    							}
    							else
    							{
    								tavolsag = tavolsag - 5.0f;
    								panel1.WriteText((int)tavolsag + " m-re!\n", true);
    							}
    						}
    					}
    					
    					Vector3D ujut = new Vector3D( jelenlegi.X-10,jelenlegi.Y,jelenlegi.Z );
    
    					Vector3D targetPosition = remote.WorldMatrix.Down * 10.0 + remote.GetPosition();
    
    					if(vektorok.Count < 1000 && indulas == true){
    
    						if(sensor.IsActive == true){
    
    						ujut = (npc.WorldMatrix.Up * 5.0) + (npc.WorldMatrix.Forward * 20.0) + jelenlegi;
    						vektorok.Add(ujut);
    
    						}else{
    
    						ujut = (npc.WorldMatrix.Forward * 20.0) + (npc.WorldMatrix.Down * 5.0) + jelenlegi;
    						vektorok.Add(ujut);
    
    						}
    
    						npc.ClearWaypoints();
    						npc.AddWaypoint(ujut, "ujut");
    						npc.SetValue<long>("Direction", 0);
    						npc.SetValueBool("DockingMode", true);
    						npc.SetValueBool("CollisionAvoidance", false);
    						npc.ApplyAction("AutoPilot_On");
    						npc.SetAutoPilotEnabled(true);
    
    					}
    					if(vektorok.Count > 1000){
    
    						npc.ClearWaypoints();
    						npc.AddWaypoint(kerberos, "kerberos");
    						npc.SetValue<long>("Direction", 0);
    						npc.SetValueBool("DockingMode", true);
    						npc.SetValueBool("CollisionAvoidance", false);
    						npc.ApplyAction("AutoPilot_On");
    						npc.SetAutoPilotEnabled(true);
    
    
    						indulas = false;
    
    					}
    
    					"Forward" = 0 | "Backward" = 1 | "Left" = 2 | "Right" = 3 | "Up" = 4 | "Down" = 5
    					*/
    				}
    
    				foreach(IMyLandingGear talp in LANDINGGEAR_LISTA)
    				{
    					if (talp.IsLocked)
    					{
    						panel1.WriteText("Leszállt!\n", true);
    						panel1.WriteText("Vedd fel a kapcsolatot az űrbázissal a műholdak összekötéséhez!\n", true);
    					}
    				}
    			}
    
    		}
    	}
    }
    
     
  2. Stardriver907 Master Engineer

    Messages:
    3,368
    I'm not familiar with the language, but you should know that when a character/remote block moves within a gravity field it makes a distinction between up and down. Just as your character will always stand perpendicular to the horizon in a gravity field, your remote will always attempt orient your ship so that it is right side up and level with the horizon. You can "re-educate" the remote as to which way is up if you need it to be different from actual up. Your remote might be fighting your script over which way is up.
     
  3. Malware Master Engineer

    Messages:
    9,861
    Doesn't the remote control have a minimum distance from sealevel? I don't think you can use the remote to land a ship...
     
  4. hungabal Trainee Engineer

    Messages:
    7
    What can i use to landing? Can you write some api code part or steps how to write this process?
    --- Automerge ---
    How can i re-educate the remote control where is the up and down?
     
  5. Stardriver907 Master Engineer

    Messages:
    3,368
    The remote works so well that my two main crew transfer vessels are named Otis and Kone, the two largest elevator manufacturers. I've set waypoints on the surface and in space and just had Otis on a loop for hours. I can't stress enough how much better the auto pilot flies the ship. The secret to the landing thing is that the auto pilot figures out when to start braking so that when it reaches the waypoint your speed is zero. It's able to figure out how much thrust you have available vs the mass of the vessel and so long as you have the same amount of thrust in all directions it always hits the mark.
    [​IMG]
    It's hard to tell but this ship is sitting on a pad. Before I landed the ship I built an armor block in the center, then I stood my character dead center on the top of the block and placed a waypoint. Now I had a waypoint dead center on the pad and 2.5 meters above it. My landing gear when extended reaches 2.5 meters, so when the ship stops on the waypoint the landing gear is just touching the pad. If I shut off the remote and disable dampening the ship just settles on it's gear.

    I also set a waypoint about 100 meters off each end of the pad about 50 meters up. The ship gets to the outer waypoint, stops, aligns itself to the pad waypoint then moves in for a perfect landing. I never land this ship manually.

    Or this one
    [​IMG]
    Same deal. Build a pad, set waypoints, let it land itself.

    With ships this size repairing damage gets really old. When I figured out how to use auto pilot to land this game got a lot better for me. Collision avoidance is awesome :D.

    You will find the way to do it in the remote's control panel. When programming the auto pilot you can have things happen when it reaches a waypoint, such as changing the "forward" direction.

    I feel like I should do a video about it.
     
  6. Malware Master Engineer

    Messages:
    9,861
    @Stardriver907 Whenever I have tried to use the autopilot for landing in the past I've experienced exactly what OP describes here... The aircraft simply refuses to go below a certain altitude. In addition to that the damn thing is excessively wasteful with fuel, firing all thrusters more or less randomly, making it utterly useless for me...

    So how the flying f**k have you managed to get it to behave?!?
     
  7. Stardriver907 Master Engineer

    Messages:
    3,368
    You'll have to tell me what "in the past" means. Back when the remote control block was new I think there might have been a limit. That was before planets. Also, auto pilot did act strange on planets at first if I recall. If you tried and failed today I don't really know what to tell you. The only thing that comes to mind is maybe you have collision avoidance on? It should be off by default.

    I have been working on another project in SE and I haven't flown a ship since October. I'm going to start a new session and take Otis down to the surface. They broke auto pilot once before, they can do it again.

    I'm aware of the fuel issue. After all, it was designed before planets and hydrogen thrusters. In Creative there are no problems, but I know things are different in Normal (Survival). When I use Otis in "elevator mode", which means it's going to run back and forth to the same spots on the surface and in space, I can "setup actions" to turn the hydrogen engines on at the altitude the atmospheric engines become ineffective. That would work better using timer blocks or a script but I haven't taken the time to figure out the steps.

    So, I guess I'll be streaming about twelve hours from now :D
     
  8. Malware Master Engineer

    Messages:
    9,861
    @Stardriver907 I last tried a good while ago, yes, but we're not talking years here. One or two majors ago. Three at the most but I don't think so.


    No, CA wouldn't be on - I'd have tested every possible configuration before giving up. It's how I do.

    But... let's just say this; people have spent who knows how much time writing their own autopilot in the programmable block, because of the limitations of the RC.

    Keen, just give me the ability to decide which orientation my ship should be at, and fix the random thruster firing, please... :p
     
  9. hungabal Trainee Engineer

    Messages:
    7
    How can i re-educate the remote control where is the up and down?
     
  10. Wicorel Senior Engineer

    Messages:
    1,258
  11. hippybaker Trainee Engineer

    Messages:
    89
    I often use PAM for auto docking...
     
  12. Stardriver907 Master Engineer

    Messages:
    3,368
    I thought I answered this, but it appears I didn't. The "re-education" is in the remote control settings (control panel)

    And I was going to, then I ran into some of the problems described here. Someone appears to have maybe been making minor tweaks to the auto pilot, and some other things may have attributed to strange behavior. I've been working on figuring out what's happening since that last post and I think I know what's going on. Maybe.

    The first thing that happened was I hit that "water level" thing. I had started a fresh world and I forgot to turn some default-off things on like in-game scripts. I'm not sure if that was it, but after I turned them on the auto pilot behaved as I expected. I went on to set up some waypoints both in space and on the planet and I am now able to demonstrate how to get auto pilot to do what it does, and I believe I can explain most of the anomalous stuff. Maybe.

    The other thing is that just when conditions around here get just right for streaming, Xoc streams that WeaponCore stuff and that means I'll get zero viewers so...

    Soooo, the goal as of today (Sunday, Mar 29) is to do a stream by Wednesday. If you're interested, just keep a lookout for me on Twitch.

    Actually, Wednesday is April Fools Day, so maybe by Thursday ;)
     
  13. hungabal Trainee Engineer

    Messages:
    7
  14. Wicorel Senior Engineer

    Messages:
    1,258
    Let me know if you find any problems (which is likely) or have questions.

    The easiest way to find me is on Keen Discord.
     
Thread Status:
This last post in this thread was made more than 31 days old.