Jump to content

Changing the rotation of the current vessel?


Recommended Posts

Hello,

I'm creating a relatively simple mod that allows the user to point at a certain position on the navball, and it is proving way harder than I thought. I've looked at mechjeb's smart A.S.S code and can't make any sense of it due to the way it calls vars from other classes. I'm essentially wanting to move from one point on the navball to the other. I've tried a bunch of things (including inverting quaternions to manage differences between srfRot and worldRot) but I'm getting nowhere. The vehicle just seems to move around randomly and sometimes fails to work altogether. 

Can anybody point me to a thread/ github repo/ their personal experience?

I don't want the vessel to jump to the specified angle, it should move to it, much like pointing at prograde or any other vector using SAS

Super confused on this one.

Thanks in advance!

Edited by uknowmyname
Link to comment
Share on other sites

https://github.com/Crzyrndm/TweakableSAS/blob/master/TweakableSAS/TweakableSAS.cs#L197-L313
I haven't updated it recently (was intening to port the control core to PA, but never got around to it), but all the maths you'll need is in that ~100 lines (and the majority of that is the various targets...). Outside that, both MJ and ^^ use a PID controller to handle the actual actuation (the maths is just to calc the rotational error :P)

The ArrowPointer class is very helpful for visualising vectors ingame 

Be warned, this is an area where the Quaternion rules supreme. Things can get bent out of shape really quickly so take it slow when making changes

Link to comment
Share on other sites

Hey Crzyrndm,

I was just looking at the code you linked above. How necessary is the updateAttitude() method in VesselData? Does this perform the actual attitude adjustment or is that done within the TweakableSAS class? I assume you use the VesselData class as a storage for vars, but the updateAttitude method is called at the beginning of your SASControl method. Can you provide any guidance?

 

Thanks!

Link to comment
Share on other sites

Oops, missed that one.

VesselData is where I store all the extra bits of information that the control system required for vessel speed/position/orientation/etc. that have to be calculated. Update attitude gets called once per physics frame to keep those values up to date.

The vessel control update happens in the calls to "setCtrlState". The function SASControl is a callback that gets called by the vessel every physics frame and hands the function a reference to the control outputs that are to be applied this frame. There are actually three of them now ( <OnPre/On/OnPost>AutoPilotUpdate ) which can be quite useful, but the only one that will reliably overwrite stock SAS is OnPost 

Edited by Crzyrndm
Link to comment
Share on other sites

Am I right in thinking that this code is used to change the attitude of the vessel? Looking through again, I don't see a point where you specify a pitch and heading to point towards. Am I just understanding this totally wrong?

Link to comment
Share on other sites

The direction (pitch/heading, no bank) to point towards is a subset of that represented by the vector ( TargetModeSwitch() * Vector3d.forward  ). Everything after that is all about making the vessel point in that direction (calculate error on each axis, output control inputs). In TargetModeSwitch, the StabilityAssist->Surface mode is where the pitch/yaw are input as a value in degrees (output as a Quat, then evaluated for control purposes)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...