Jump to content

Frage: kOS autolaunch script mit heading. Schon mal gemacht?


inoculator

Recommended Posts

Tach zusammen,

ich habe mal ganz grob durch das deutsche Forum gesucht, aber nichts Passendes gefunden und auch die englisch sprachigen Teile sind mir da nicht wirklich hilfreich.

Wie wahrscheinlich schon Tausende ;-) vor mir, versuche ich mich an kOS.

Ich habe ein Grundgerüst für ein Autolaunch Script soweit erfolgreich fertig.

Es übernimmt die Geschwindigkeit in Relation zur Höhe, kann unterschiedliche Orbithöhen anfliegen und zirkulieren, und das Staging ist ebenfalls dabei.

Angefangen habe ich mit einem einfachen 90° Script, welches nur äquatorial fliegt.

Dann kam eine Kopie des Scriptes für den polaren Orbit.

Jetzt möchte ich diese Beiden vereinen und eine variable Lage des Orbits ermöglichen.

Also in etwa so:

run autolaunch(650000,56)

Was einen Orbit in 650km Höhe und einer Neigung von 56°N relativ zum KSC (Startpunkt) bringen soll.

Und damit begannen meine Probleme.

Wer den Kompass im Verlaufe eines geneigten Orbits verfolgt, sieht, daß sich das Heading dabei ständig ändert.

Ich kann also im Verlaufe des Scriptes nicht von einem einmal festen Wert ausgehen, sondern muss das Heading dynamisch und permanent neu berechnen.

Nachdem ich mir dann auch ein paar Lektüren zu Quaternionen angetan habe, komme ich dennoch keinen Schritt weiter.

Die Dokumentation des Variablen und Vectoren zu diesem Thema ist grottenschlecht.

Ich hoffe einigermaßen verständlich mein Problem beschrieben zu haben.

Wer kann mich hier mal in die richtige Richtung schubsen?

Gruss

Carsten

Link to comment
Share on other sites

  • 1 month later...

Hey ich hab mir das mal eben angeschaut :D 

eine relativ einfach Möglichkeit wäre ein Script schrieben was als erste mit den werten ein Orbit macht. 

Hab mir das so überlegt das du beim Start deiner Rakete eine Neigung vorgibst. 

Z.B: LOCK STEERING TO HEADING(56,90).

Die 90° müssen durch das Script immer wieder angepasst werden so das du dein Orbit ja schaffst.

somit bekommst du schonmal eine gewünschte Richtung hin.

bei mir waren es 30° Inclination am ende. Wenn du deinen Orbit dann hast mit einer gewissen Neigung kannst du im nach gang schauen ob die Inclination der Flugbahn die 56° hat oder nicht. Wenn nicht musst du ein Manuver ansteuern was die restlichen 26° absolviert. Getestet hab ich das alles leider nicht aber ist von mir mal ein Gedanken anstoß :wink:

vlt hilft er dir weiter 

Link to comment
Share on other sites

I can read German a lot better than I can write it, so I understand what you are talking about, but I will not subject you to my (or Google's) bad German. Forgive my response in English.

tl;dr: tc1=mod(atan2(sin(lon1-lon2)*cos(lat2), cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon1-lon2)), 2*pi)

 

Longer answer:

What you need to search for is navigation on a 'great circle' or Riemann circle (Großkreis): a circle created by intersecting a plane with a sphere that crosses the sphere center - which if you think about it, is just another way of saying 'an orbital path around a sphere with a set inclination with the sphere's ecliptical' (if you calculate with a virtual sphere that is planet radius+orbital altitude).

The problem is that a compass heading will not stay constant while navigating such a circle. If you follow the circle you will notice that the heading will vary: the greater the orbit inclination away from the ecliptic, the more the heading changes along the orbit. The easiest to notice this is at the most northern/southern points of the orbit, where the heading will be parallel to the ecliptic (ie. either 90 degrees, or 270 for retrograde orbits).

@TJ179 Notice that he is not talking about the pitch, which I think is what you are referring to... how much 'up' into the sky your nose is pointing. You are correct that this too changes if you follow a gravity turn, but it is not what @inoculator is asking about. Even during a gravity turn, on an inclined orbit path the compass heading will not stay the same - the 56 will slowly start to move towards 90 then up to 124 when crossing the ecliptical, then back to 90 and finally 56 when flying over the KSC again.

The trick to calculating this constantly changing heading is understanding that the compass heading on a great circle/inclined orbit is basically a wave function, of which the wave amplitude becomes greater as the inclination of the orbit increases.

The formula for calculating the heading/bearing/course (depending the page they use different words for this) would be as follows:

tc1=mod(atan2(sin(lon1-lon2)*cos(lat2), cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon1-lon2)), 2*pi)

 

Instead of trying to explain the math behind it myself (I'm not that good at math), I'll give you a few links (some in German) that give a better explanation than I could.

 

Great circle explained:

https://de.wikipedia.org/wiki/Gro%C3%9Fkreis

 

 

Some formulas to calculate great circle navigation (should be possible to make this into kOS code):

 

http://astrosail.de/de/static/tutorial/best5.php?cat=42

 

More in English:

http://williams.best.vwh.net/avform.htm

http://mathforum.org/library/drmath/view/55417.html

 

Hopefully if the above is not directly helpful, at least searching for these terms may find you more useful documentation of how to code a function that maintains the correct compass heading on an inclined orbit.

P.S.: I would be very interested to see your finished kOS script, if you are inclined to share it once you have it working as desired.

Edited by swjr-swis
PS
Link to comment
Share on other sites

  • 2 months later...

Hi swjr-swis,

it has lasted a while since I hit the forum again. sorry for the delay.

At the moment I have a lack of performance on my PC to get a propper developement running on KOS.
Nevertheless I have read the links and You really hit the point that I was missing.

Thanks for this.
As soon as I got my environment back in bussines, I will return and post some results.

Many thanks 'till now
Carsten

Link to comment
Share on other sites

  • 3 weeks later...

Hi again.

As promised a short status.

I took a more or less deep dive into navigation regarding the great circle (GC). I did some tests applying the formula and ended up in more misunderstanding, than before ;-)

I think, the formula You provided is only step 1 out of 3 or more steps.

1. The angle calculated is the angle between two point, relative to the center of the GC.
2. To get the steering course I need to calculate the "Kurswinkel" which is written on the wiki below Your quotation. It calculates the angle relative to north (0°).
3. Nevertheless I get the issue, that the navigation is bound to the ground, and as soon, as I lift off, I have to compensate two further parameters:
3.a. Coriolis effect if inclination is not 90 or 270°
3.b. The rotation of the body.

I put in here the current scripts sniplets of the calculation I have done up to now. This does not include (3a + b).
 

//main script
//Runmode contains the step of the launch phase the ship is currently in.
//0 is waiting to launch
//1 is lift off and clear launchpad
//>1 are 2: Rollmanuever 3: gravity turn 4: coast to AP 5:orbital burn 6:cleanup and ready to load next phase.

if runmode >1 {
[...]
	
//Kursrechner
	set my_prograde to get_prograde().
	set my_bearing to get_bearing(my_prograde, my_orb).
}
// Prograde rechner
//Es muss ermittelt werden,
//welchen relativen Kurs wir zwischen der letzten und der
// aktuellen position gehabt haben
// dieser muss dann mit dem soll-kurs basierend auf der my_orb vorgabe 
// verglichen werden und ggfls. ein korrekturfaktor 
// eingerechnet werden

// deklaration der variablen

set bit_func_getprograde_rm to 0. //funktions laufmodus
set int_last_lat to 0.
set int_last_lon to 0.
set int_cur_lat to 0.
set int_cur_lon to 0.
set this_Kurswinkel to 0.
set this_GKANG to 0.

declare function get_prograde {

set my_position to ship:geoposition.
set int_last_lat to int_cur_lat.
set int_last_lon to int_cur_lon.
set int_cur_lat to my_position:lat.
set int_cur_lon to my_position:lng.

if bit_func_getprograde_rm = 1 {
	//init ist gelaufen
	//Aus dem Forum:
	//tl;dr: tc1=mod(atan2(sin(lon1-lon2)*cos(lat2), cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon1-lon2)), 2*pi)
	set this_GKANG to mod(arctan2(sin(int_last_lon-int_cur_lon)*cos(int_cur_lat), cos(int_last_lat)*sin(int_cur_lat)-sin(int_last_lat)*cos(int_cur_lat)*cos(int_last_lon-int_cur_lon)), 2*constant:pi).
	set this_Kurswinkel to arccos((sin(int_cur_lon)-sin(int_last_lon)* cos(this_GKANG))/(cos(int_last_lat)*sin(this_GKANG))).
}
set bit_func_getprograde_rm to 1.
return this_Kurswinkel.

}
// Prograde rechner
// this one calculates the needed corretive course by given is-value and -shouldbe-value
declare function get_Bearing {
	parameter int_prograde. //this is the course
	parameter int_orb. //this shouldbe the course
	
	set my_heading to (int_orb - int_prograde) + int_orb.
	
	return my_heading. //this needs to be the course to compensate
}

I expect, that these sniplets might get more questions than answers, but I just wanted to show up, that I don't forget about this thread ;-)
I don't think, that the script quotes are usable for any other by c&p. There are a lot of further lines and functions.

I hope to get some steps further today

br

Carsten

Link to comment
Share on other sites

Finaly..... I think I got it.

Maybe, someone can try it, I he likes, maybe it helps somebody.

I went 3 days though all that navigation stuff and finally ended up in a totally simple solution:

"orbit:inclination".

I really don't know, why I haven't seen this command before.

The final script gets an inclination of +/- 0.5° off.

// Inclination correction
// my_orb is the given heading in the main script
// the function is to be called at the beginning of every control loop.

// deklaration der variablen

set bit_func_getprograde_rm to 0. //funktions laufmodus
set int_last_inc to 0.
set int_cur_inc to 0.
set this_inc to 0.
set this_qad to 0.
set this_Kurswinkel to 0.
if my_orb<=90 {
 set this_inc to 90 - my_orb.
 set this_qad to 1.
 }
if my_orb>90 and my_orb<=270 {
 set this_inc to my_orb - 90.
 set this_qad to 2.
 }
if my_orb>270 {
 set this_inc to 450-my_orb.
 set this_qad to 3.
 }
declare function get_prograde {

set int_last_inc to int_cur_inc.
set int_cur_inc to orbit:inclination.

if bit_func_getprograde_rm = 1 {
	//init ist gelaufen
	if mod(this_qad,2)=1 {
	set this_kurswinkel to max(-8,min(8,orbit:inclination-this_inc)) *2 +my_orb.
	} else {
	set this_kurswinkel to max(-8,min(8,this_inc-orbit:inclination)) *2 +my_orb.
	}
}
set bit_func_getprograde_rm to 1.
return this_kurswinkel.

}

I have put the complete script library on to here:

https://drive.google.com/folderview?id=0BxyO38kgW4YuWmE4Qlp3RXJhSGs&usp=sharing

It is very raw and not really cleaned up, so don't expect to much ;-)

Thanks for the help.

Carsten

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