Jump to content

Cant set SAS autopilot mode programmatically?


Recommended Posts

I am trying to set the SAS autopilot mode programatically, i am calling:

 ActiveVessel.Autopilot.SetMode((VesselAutopilot.AutopilotMode) Mode );

However this does not change the mode. I have looked at the kOS code, and it's also changing the mode with  Autopilot.SetMode();

Could anyone shed some light on this?

I have tried adding the following: (From https://github.com/Mihara/RasterPropMonitor/blob/6d322ad430d6496450c5415e5d57f44f13a7b86f/RasterPropMonitor/Handlers/JSIInternalRPMButtons.cs#L220 )

UIStateToggleButton[] SASbtns = UnityEngine.Object.FindObjectOfType<VesselAutopilotUI>().modeButtons;
                        SASbtns.ElementAt<UIStateToggleButton>((int)KSPSerialPort.VControls.AutoPilotData).SetState(true);

Didn't help.

Edited by c4ooo
Link to comment
Share on other sites

Do you have a probe core or pilot on board? That method you are using does not bypass the requirements for SAS to be usable.

You can tell by checking the SAS icons down by the navball, only the icons visible can be activated by that method.

I do exactly what you are looking for here: https://github.com/SirDiazo/ModActions/blob/master/ModActions/Execute.cs#L216

Note I check the mode is available first a couple lines beforehand.

D.

Link to comment
Share on other sites

Yes, i have made sure that i am actually able to change the SAS mode (i set it manually).

Anyways, maybe its because i am doing 

ActiveVessel.Autopilot.SetMode((VesselAutopilot.AutopilotMode) BYTE_REPRESENTING_MODE);

Instead of something like:

switch(BYTE_REPRESENTING_MODE){
	case 0:
		ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.StabilityAssist);
		break;
	case 1:
		ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.ProGrade);
		break;
	case 2:
		ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.RetroGrade);
		break;

	etc...
}

(Never done C# until yesterday)

 

Once i get back to my code in ~6 hours i will update the post :)

Edited by c4ooo
Link to comment
Share on other sites

Your code looks correct to me otherwise, the only thing that isn't clear is what reference is ActiveVessel? I assumed you'd referenced this earlier in your code because the full reference using the static Squad gave us is "FlightGlobals.ActiveVessel", not just "ActiveVessel".

There's no errors in the log file?

D.

Link to comment
Share on other sites

As far as i understand, ActiveVessal should be the same as  FlightGlobals.ActiveVessel (This isn't my code that i am modifying).

Anyways, i guess it doesn't like that i am casting a number to (VesselAutopilot.AutopilotMode) or something, becouse i can change the mode fine with "ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.RadialOut);" etc.

Edit: "ActiveVessel.Autopilot.SetMode((VesselAutopilot.AutopilotMode) ((int) SOME_BYTE));" works but "ActiveVessel.Autopilot.SetMode((VesselAutopilot.AutopilotMode) (SOME_BYTE));"? Can someone confirm that this and that its not just some other part in my code that was messing stuff up?

Edited by c4ooo
Link to comment
Share on other sites

Is that not throwing an error?

My guess would be that when you just type in SOME_BYTE, it defaults to type FLOAT which the AutopilotMode Enum doesn't recognize. But when you explicitly cast to INT, the AutopiloeMode can recognize that and works correctly.

But I've always worked with the names in the enum, I've never tried setting it by number as you are so I'm just guessing here.

D.

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...