Space Engineers

Space Engineers

Wico NAV Autopilot [OBSOLETE]
Wicorel  [developer] 24 Sep, 2015 @ 11:58am
Example Code/usage
This is the navigation code I use in my mk3 miner.

Here is some of the code blocks I use to communicate with this NAV script:

void startNavWaypoint(Vector3D vWaypoint, bool bOrient = false, int iRange = 10) { string sNav; sNav = "NAV: D " + iRange + "; "; if (bOrient) sNav += "O "; else sNav += "W "; sNav += Vector3DToString(vWaypoint); if (navCommand == null || navStatus == null) { setAlertState(ALERT_ATTENTION); throw new OurException("No nav Command/Status blocks found"); } navCommand.SetCustomName(sNav); navStatus.SetCustomName("NAV Status: Command Set"); if (navEnable != null) navEnable.ApplyAction("OnOff_On"); if (navTriggerTimer != null) navTriggerTimer.ApplyAction("Start"); } void startNavRotate(Vector3D vWaypoint) { string sNav; sNav = "NAV: "; sNav += "r "; sNav += Vector3DToString(vWaypoint); navCommand.SetCustomName(sNav); navStatus.SetCustomName("NAV Status: Command Set"); navEnable.ApplyAction("OnOff_On"); navTriggerTimer.ApplyAction("Start"); }
< >
Showing 1-1 of 1 comments
Wicorel  [developer] 24 Sep, 2015 @ 12:11pm 
More example usage. This is the code from my miner's SEARCH ORIENT mode where it turns 180 degrees after exiting a mining bore.

void StartSearchOrient() { StatusLog(DateTime.Now.ToString() + " StartSearchOrient", getTextBlock(longStatus), true); bUsingNav = true; dtStartSearch = dtStartNav = DateTime.Now; ResetMotion(); if (cargopcent > 99) { ActionGoHome(); return; } double dist = (vCurrentPos - vLastContact).Length(); if (dist < 14) { StartSearchVerify(); return; } current_state = 0; setMode(MODE_SEARCHORIENT); Serialize(); } void doModeSearchOrient() { if (current_state == 0) { ResetMotion(); if (velocityShip < 0.2f) { startNavWaypoint(vLastContact, true); StatusLog(DateTime.Now.ToString() + " Aiming at " + Vector3DToString(vLastContact), getTextBlock(longStatus), true); current_state = 1; } else Echo("Waiting for motion"); } else { if (navStatus == null) { ResetToIdle(); setAlertState(ALERT_ATTENTION); throw new OurException("No nav Status block found"); } string sStatus = navStatus.CustomName; if (sStatus.Contains("Done")) { vLastExit = gpsCenter.GetPosition(); StartSearchShift(); } } }

The first is handling a requested mode change.

The second handles the ORIENT mode.

The first secion (current_state == 0) waits until ship motion is slowed. Then it starts the orient by calling the routines posted above.

The second section checks for the NAV being completed and then starts SEARCH SHIFT mode for the miner.
Last edited by Wicorel; 24 Sep, 2015 @ 6:13pm
< >
Showing 1-1 of 1 comments
Per page: 1530 50