uknowmyname Posted September 6, 2016 Share Posted September 6, 2016 (edited) 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 September 6, 2016 by uknowmyname Link to comment Share on other sites More sharing options...
Crzyrndm Posted September 6, 2016 Share Posted September 6, 2016 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 More sharing options...
Harrie Posted September 6, 2016 Share Posted September 6, 2016 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 More sharing options...
Harrie Posted September 6, 2016 Share Posted September 6, 2016 Never mind, just had a proper look through that and realised what it does. Link to comment Share on other sites More sharing options...
Crzyrndm Posted September 7, 2016 Share Posted September 7, 2016 (edited) 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 September 7, 2016 by Crzyrndm Link to comment Share on other sites More sharing options...
Harrie Posted September 7, 2016 Share Posted September 7, 2016 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 More sharing options...
Crzyrndm Posted September 8, 2016 Share Posted September 8, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now