Jump to content

Enable/Disable autopilot


Recommended Posts

I tried to explicitly enable or disable the autopilot with the following functions:

bool result = FlightGlobals.ActiveVessel.Autopilot.Enable ();

and

bool result = FlightGlobals.ActiveVessel.Autopilot.Disable ();

They always return true (at least when I tried on a vessel where autopilot is working), but do nothing. Toggling the autopilot with T works as expected. This also works:

FlightGlobals.ActiveVessel.Autopilot.SetMode (mode);

Anyone has any idea what am I missing here?

Edited by petersohn
Link to comment
Share on other sites

Not sure what exactly those .Enable and Disable methods do.

To disable SAS is the following I do the following:

FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, false);

To set Stability Assist is:

pm.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true);
pm.vessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.StabilityAssist);
if (pm.vessel == FlightGlobals.ActiveVessel)
{
   MonoBehaviorMethods.setSASUI(0); //You have to set the UI icon manually for some reason.
}

Note that you can only set available modes that have icons visible next to the navball so make sure a high enough level pilot/probe core is along.

D.

Link to comment
Share on other sites

Thanks, that works. Actually, my findings are the following:

If SAS is already enabled, this can be used to set the mode:

FlightGlobals.ActiveVessel.Autopilot.SetMode (mode);

To enable or disable SAS, this have to be used:

FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, value);

To enable SAS and set the mode at the same time, this does not work:

FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true);
FlightGlobals.ActiveVessel.Autopilot.SetMode (mode);

However, this does:

FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true);
FlightGlobals.ActiveVessel.Autopilot.Enable (mode);

It seems to be some kind of API bug, which may or may not be fixed in some later update.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...