Jump to content

Setting SAS lock direction (How does VesselSAS work))


Recommended Posts

Okay. I'm pretty sure this is really a question about quanterions, but for the record what I am doing is trying to set the SAS lock vector.

I am working in the VesselSAS class and there are 2 things of note in the object brower:

LockHeading(quanterion); <- Method to set the direction of the SAS lock direction
referenceHeading <-quanterion property that is the SAS 'zero'

When I do a referenceHeading.euler it returns 0,90,0 and when I set the LockHeading to a zero'd quanterion (0,0,0,0), my vessel locks heading to due east when on the KSC pad so I believe the referenceHeading.euler I can turn into a world co-ordinate vector.

I then have a world direction Vector3 with an origin at my vessel.transform.position that is the direction I want to set the SAS heading too, but I can't get this to work.

I'm pretty sure I need to get the rotation between the SAS reference position (a quanterion) and my desired heading, then apply it to a new, zero'd quanterion, then set my lock heading to that quanterion after I rotate it.

My problem is how do I get the rotation I need from the Vector 3 as a quanterion?

D.

Edited by Diazo
Link to comment
Share on other sites

Alright, this is absolutely stonewalling me.

Does anyone know of a mod that has worked with the VesselSAS class that I could use for pointers? A quick glance at both MechJeb and kOS's source code makes it look like they don't use it, they point the vessel with their own code.

D.

Link to comment
Share on other sites

Hi Diazo,

I've been looking at SAS aswell. You can create the quaternation in the direction of the vector using: quaternation.lookRotation(vector3).

You can also look at the source of Mechjeb, MechJebModuleAttitudeController.cs. It has a bit with the stock SAS. I don't exactly get what they are doing, but maby you can figure it out:)

Regards,

Link to comment
Share on other sites

I ended up getting this working, but it was more trial and error then anything.

https://github.com/SirDiazo/RCSLandAid/blob/master/RCSLandAid/RCSLandAid.cs#L193 is my code for reference but I ended up using:

FlightGlobals.ActiveVessel.VesselSAS.LockHeading(refQuant, true);

The true is a boolean meaning I am using Manual Lock, whatever that is. It works so I'm not arguing.

refQuant is a quaterion, but the up direction matters. I also could not figure out how the direction works.

To lock the SAS straight up for a typical rocket, refQuant is

Quaternion.LookRotation(worldUp, vslUpRef) * vslRefQuant;

where worldUp is a Vector3 from the planet's CoM through the vessel's CoM, vslUpRef is FlightGlobal.ActiveVessel.transform.up and vslRefQuant is Quaternion.Euler(90, 0, 0).

It took a lot of guess and test to reach that and I don't really get what is all means.

I was able to shortcut because using only the 90° axis angles makes things simple, but this was still a big headache to figure out.

D.

Link to comment
Share on other sites

After playing around with it some more today, I came up with pretty much the same solution. And I also haven't got a clue what the manual lock is:)

The mechjeb code also uses the Quaternation.Euler(90,0,0), so i gues that is the right way.

I did find a way prevent the SAS to go mad when you set it:

currentHeading = Quaternion.LookRotation(vessel.transform.up) * Quaternion.Euler(90,0,0);
targetHeading = Quaternion.LookRotation(targetVector) * Quaternion.Euler(90,0,0);

if (Quaternion.Angle(currentHeading, targetHeading) > 10)
{
target = Quaternion.RotateTowards(currentHeading, targetHeading, 2f);
}
else
{
target = Quaternion.LookRotation(targetHeading);
}

part.vessel.VesselSAS.LockHeading(target, true);

Hope this makes sense.

Link to comment
Share on other sites

  • 2 months later...
After playing around with it some more today, I came up with pretty much the same solution. And I also haven't got a clue what the manual lock is:)

The mechjeb code also uses the Quaternation.Euler(90,0,0), so i gues that is the right way.

I did find a way prevent the SAS to go mad when you set it:

currentHeading = Quaternion.LookRotation(vessel.transform.up) * Quaternion.Euler(90,0,0);
targetHeading = Quaternion.LookRotation(targetVector) * Quaternion.Euler(90,0,0);

if (Quaternion.Angle(currentHeading, targetHeading) > 10)
{
target = Quaternion.RotateTowards(currentHeading, targetHeading, 2f);
}
else
{
target = Quaternion.LookRotation(targetHeading);
}

part.vessel.VesselSAS.LockHeading(target, true);

Hope this makes sense.

Hi, what kind of values does your "targetVector" take ? Are they basically navball values ?

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