Jump to content

Launch Window Time to seconds Python Script


Recommended Posts

Without a stock launch window tool in KSP2 for now, I'm back to using AlexMoon Launch Window Tool: https://alexmoon.github.io/ksp/
This gives me the launch window time, though you need to add +1 to the year for earliest departure, as KSP2 is 1 year offset (KSP1 year 1 = KSP2 year 0).

I run the Python script below (run locally or at https://www.online-python.com/), input the launch time, and current time, and get the difference in number of seconds, and copy that.

Once I have that, I create a maneuver node, and using Maneuver Node Controller (https://spacedock.info/mod/3270/Maneuver Node Controller), put in the seconds to skip ahead, along with the usual delta-V amount.

 

#calculates time in seconds to add for transfer window
#input is transfer window time and current time
#1 year = 426.08 days = 2556.50 hours = 9203400 seconds 
#take first number of 92303400
#add 1 year to KSP2 time, as KSP1 year 1 = KSP2 year 0
#Launch window calculator using KSP1 date convention: https://alexmoon.github.io/ksp/

def convert_to_seconds(year,day,hour, minute, second):
	sec_year = year * 9203400
	sec_day = day * 60 * 60 * 6
	sec_hour = hour * 60 * 60
	sec_minute = minute * 60
	return sec_year + sec_day + sec_hour + sec_minute + second

def get_time():
	year = int(input('Year: '))
	day = int(input('Day: '))
	hour = int(input('Hour: '))
	minute = int(input('Minute: '))
	second = int(input('Second: '))
	return convert_to_seconds(year,day,hour,minute,second)

#main program
print('Input Launch Window time')
launch_time = get_time()
print('Input Current time with KSP1 time convention (+1 year if KSP2)')
current_time = get_time()
print('Seconds until launch')
print(launch_time - current_time)

 

Edited by Soda Popinski
Link to comment
Share on other sites

  • 9 months later...

(Just cause I got super confused when googling this earlier :confused:)

FYI  for anyone seeing this now: the KSP2 year is now exactly the same as KSP 1 so no need to convert.

On 3/7/2023 at 7:49 AM, Soda Popinski said:

...
This gives me the launch window time, though you need to add +1 to the year for earliest departure, as KSP2 is 1 year offset (KSP1 year 1 = KSP2 year 0).

...

 

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