View Full Version : Semi-automatic Celestial Navigation
dottore
09-06-12, 05:09 AM
Original don1reed: http://www.subsim.com/radioroom/showthread.php?t=163113&highlight=stellarium&page=2
Yesterday, based on the original idea of don1reed(Thank you sir!) I began to work on the semi-automatic CelNav to implement this nice function in Silent Hunter 5:
1. phase (Under development):
Using Python script to get the needed data from the only actual CampaignMission.mis file. Push this to the startup.ssc(The new Stellarium script extension) they made a whole new API so I needed to mine deep into.
2. phase (In the very near future):
After I made my celestial body inspects, Stars, Moon, Sun etc. I'd like to calculate my current pos with an application written in C# or B#.
Pros:
. You don't need to know your Current Pos, before you begin to calculate your Current Pos :D. That was funny :).
. If you're not a navigator or a hobby astronomer yet you can enjoy the success with your CelOb inspects.
. You can navigate in bad weather too or even under water, but that's not realistic so not recommended.
Cons:
. You need some software: Stellarium above 0.11.3, The Python interpreter ( Future: automated install with everything, and batch file to execute) and my exe file from 2. phase (Required: Dotnetfx 2.0 or above).
. You need time, patience, and time :D Interest, if you want to navigate like a real navigator.
I use Python for data mine, because of it's talent in. Visual family from Microsoft is best for object-oriented programming (2. phase).
Software reqs:
.Python
.Stellarium 0.11.3 or above (if they change the programming language in the future, then I need some modification) Important: you need to configure config.ini, change timezone to UTC time and change display settings to best your system is capable.
have a look at this thread : http://www.subsim.com/radioroom/showthread.php?t=194033
dottore
09-06-12, 05:52 AM
Thank you Flostt!
I read this thread before, I'm not a modder, but I think I can help Silent Marshal.
I'm eager to do this first written below and I am curious about your opinion. Are you interested? I just want to bring closer this thing to the ordinary people.
dottore
09-06-12, 05:30 PM
Progress:
import fileinput,string,sys,csv
def MakeFile(file_name):
"""
MakeFile(file_name): makes a file.
"""
temp_path = 'C:\\Python27\\' + file_name
file = open(temp_path, 'w')
file.write('')
file.close()
print 'Execution completed.'
MakeFile('my.active.uboat.data.txt')
#YourUsername #Your.ingame.name, Your Campaign date -> You need to modify this onetime per new patrol(working on an automated latest file copy paste)
f=open("C:\\Users\\*.*.*\\Documents\\SH5\\data\\Users\\*.* .*\\Campaign-2012-09-02_1721\\CampaignMission.mis",'r')
lookup = 'Name=U-' #changes here too
with open("C:\\Users\\*.*.*\\Documents\\SH5\\data\\Users\\*.* .*\\Campaign-2012-09-02_1721\\CampaignMission.mis",'r') as f:
for num, line in enumerate(f, 1):
if lookup in line:
print 'found at line:', num
nu=num
f.close() #changes here too
with open("C:\\Users\\*.*.*\\Documents\\SH5\\data\\Users\\*.* .*\\Campaign-2012-09-02_1721\\CampaignMission.mis",'r') as f:
g=open("c:\\Python27\\my.active.uboat.data.txt",'w')
lines=f.readlines()
for i in range(nu-1,nu+45):
line = lines[i]
line2 = g.writelines(line)
f.close()
g.close()
# longitude grab
lookup2 = 'Long='
with open("c:\\Python27\\my.active.uboat.data.txt",'r') as h:
for long, line in enumerate(h, 1):
if lookup2 in line:
long2=line
h.close()
long2.split('=')
longitude = long2.split('=')[1]
print longitude
# latitude grab
lookup3 = 'Lat='
with open("c:\\Python27\\my.active.uboat.data.txt",'r') as h:
for long, line in enumerate(h, 1):
if lookup3 in line:
lat2=line
h.close()
lat2.split('=')
latitude = lat2.split('=')[1]
print latitude
#stella=open("C:\\Program Files\\Stellarium\\scripts\\startup.ssc" ,'w')
#stella.write("date utc "+date+"T"+time+":00\n")
#stella.write("moveto lon "+str(longi2)+"\n")
#stella.write("moveto lat "+str(lati2)+"\n")
#stella.write("script action end\n")
#stella.close()
With this initiation we can reduce our big CampaignMission.mis to show only the U-** data. This is essential, because we get rid of needless navigational data.
Everybody can use this script, because it finds the Uboat data ergo the Unit 1.
Results:
my.active.uboat.data.txt content:
Name=U-33
Class=SSTypeVIIA
Type=200
Origin=German
LayerOperation=0
Side=2
Commander=1
CargoExt=-1
CargoInt=-1
Doctrine=0
CfgDate=19400313
MainEquipment=1
SecondaryEquipment=1
DeleteOnLastWaypoint=false
DockedShip=false
IsEscort=false
GameEntryDate=19380101
GameEntryTime=0
GameExitDate=19451231
GameExitTime=0
EvolveFromEntryDate=false
Long=1322261.310968
Lat=6550443.292625
Height=-3.870683
IsFromSingleMis=true
Heading=69.006813
Speed=0.000000
CrewRating=3
DelayMin=0
ReportPosMin=-1
ReportPosProbability=100
SecondsUntilReport=-40100.000000
HighPrioContact=false
RandStartRadius=0.000000
In3D=true
TacticalUnit=false
AvailStartDate=19380101
AvailEndDate=19451231
TempHeading=0.000000
TempNextWP=0
CombatSubmarine2D=false
CombatRadius2D=30.000000
CommandedSpeed2D=0.000000
Num2DCombatKills=0
Intercept2DCooldown=6.000000
NextWP=1000000Yes, I know we can grab the important data without this step, but this is double proof safety. You don't want to get an another unit's position only your boat.
Changes:
.Added code snippet so we have our latitude and longitude in decimal using the my.active.uboat.data.txt file.
TheDarkWraith
09-06-12, 10:53 PM
The ScriptManager exposes a function that one can call to get the player's position at anytime :yep: There's no need to do what you are doing...
dottore
09-07-12, 10:03 AM
Thank you for your guide. That makes everything simpler.
2. phase (In the very near future):
After I made my celestial body inspects, Stars, Moon, Sun etc.
How do you "inspects" the celestial body in stellarium without getting pinpoint accuracy of the star's position? That is the most important question.
dottore
09-08-12, 04:32 PM
Maybe I used the "inspect", because of my limited English. I meant to click on the stars and write down the needed data.
If I correctly understand your question, I don't think about hardening the way to get star position. In this first step, I want it to work.
Your job is reduced to choose your navigation object's, note the needed data, give this to the app. I think about triangulation and square operation in this start. If you make more triangulation you get more precise position.
I think, but don't know, in IRL they used actual navigation star data books based on the latitudes, almanacs, sun moon charts. They calculated position's with boards. Today we use math based apps to get this job done.
-
We can limit our options in Stellarium if somebody understand the Stellarium programming language. But if you limit, you need a tool to extract this data.
Today we use math based apps to get this job done.
-
We can limit our options in Stellarium if somebody understand the Stellarium programming language. But if you limit, you need a tool to extract this data.
Tool for free the celestial navigator for android-handys (http://slideme.org/application/celestial-navigator).
Almanacs 39-45 and sight reduction tables are also availeable for free.
An option in stellarium could be:
if act wind_sh5 = 1 then FOView_Stellarium = max 80
if act wind_sh5 = 3 then FOView_Stellarium = max 75
if act wind_Sh5 = 6 then FOView_Stellarium = max 65
etc.
FOV-values in stellar. make the star-positioning more difficult/inaccurater
dottore
09-09-12, 02:15 AM
Thank you CaliEs!
This will be very useful to refine the Stellarium options. Please note CaliEs' modifications one below to make the navigation more difficult.
-
Stellarium will show your ingame sky always as you execute, correct dates(read below).
Script is working, but read the information below. The script carries the navdata(your location, time) from mission files into the Stellarium's startup file automatically without user input.
You need to run the batch file, when you would like to see your sky in Stellarium.
If you feel lost, don't hesitate to contact me.
Download:
http://www.mediafire.com/?9swhqak15l9a502
Alt.download:
http://www.sendspace.com/file/i22sa1 (Click on below "Click here to start download from...")
Warning:
This is not the final scipt, because it needs user friendly modifications and using needless methods to get the navdata.
-
I don't know the game programming architecture so I need to study Ironpython to make navigational data pick the correct way from the game itself instead of using mission files and avoid text manipulation. So there will be an other script and this will be trashed.
The script is using brute string manipulations to make the job so I apologize.
It prints values, but don't need them. Their purpose is testing the success of data mine. It doesn't change any file in your install or in your user folder only grabbing data to the 2 txt files it creates.(date.txt, my.active.uboat.data.txt) If you want Backup your mission file, but the script only reads it.
Requirements:
Important install information:
You need to write your file paths, directory paths into the script before running it(don't use "find and replace" because script using \\ to describe paths). I marked the needed modifications. You need to do this only once except your mission file. If you go to a new patrol, you need to change it to point the new file.(This will be fixed later, to auto find your paths). If you make a new profile in the game, you have new folder, new mission file, so you must show the script the new file.
Needed applications:
Python 2.7 default paths in script: C:\Python27
Stellarium 0.11.4 or above (older Stellarium uses other language, so "no go!") default paths in script: C:\Program Files\Stellarium
Default path for .mis file:
C:\Users\This.is.your.name\Documents\SH5\data\User s\This.is.your.in.game.name\Campaign-This.is.your.date\CampaignMission.mis
Important changes in Stellarium config.ini:
Default path: C:\Users\This.is.your.name\AppData\Roaming\Stellar ium
Backup your config.ini.
Use your resolution from ingame in Stellarium, change the values:
[localization]
...
...
time_zone = GMT
.
Note: this is a req, without this your Stellarium will apply your GMT shift and mess up date.
[video]
...
...
screen_h = (Example: 1080)
screen_w = (Example: 1920)
.
You need the script and the python.exe in one folder, you run the whole with a batch file.
This is not difficult but not user-friendly. If you aligned everything you need only change your .mis file location occasionally.
I really much appreciate if you try this script and beta test for me. If this works to you I can step forward.
TheDarkWraith
09-09-12, 08:07 AM
If not user-friendly then many people will not try/use it. That's just the way it is :shifty:
I have no need for your idea as I have a working real navigation in my UIs mod (thus no need to test it). I do feel you are overcomplicating things. I would suggest you learn the game's architecture (what functions the scriptmanager exposes and how to use them) first. It will make things so much easier for you/everyone else :yep:
You'll also probably get a much better response/feedback if this was originally posted in the SH5 Mods forum.
dottore
09-09-12, 08:14 AM
Yes, I know but invested too much time in it to trash out the whole thing. That's why I posted. I need time to learn game architecture.
Next time, I will post in the SH5 mods topic.
TheDarkWraith
09-09-12, 08:26 AM
Yes, I know but invested too much time in it to trash out the whole thing. That's why I posted. I need time to learn game architecture.
Next time, I will post in the SH5 mods topic.
You can always ask a moderator to move your thread to another forum. Contact CCIP or Webster :up:
dottore
09-09-12, 08:30 AM
Thank you! I felt we misunderstood each other. I really like your Real Navigation, just hard to calculate position in game, the way it meant.
Mod: I started IronPython to make the new script :).
First experience: Moon is a problem in game so I can see 1 hour shift of the Moon from GMT.
Download:
http://www.mediafire.com/?9swhqak15l9a502
Error:
Traceback(most recent call last):
File "sacn.0.09.beta.py", line 13, in (module) MakeFile("my.active.uboat.data.txt')
File "sacn.0.09.beta.py", line 9, in (module) file = open(temp_path, 'w')
IOError: [Errno 2] No such file or directory 'C:\\Python27\\my.active.uboat.data.txt'
dottore
09-09-12, 07:48 PM
It works for me, PM sent.
Almost done with the newer script, that using the ingame scripts, so you don't need this.
Mod:
http://www.subsim.com/radioroom/showpost.php?p=1932267&postcount=260
It works for me, PM sent.
def MakeFile(file_name):
"""
MakeFile(file_name): makes a file.
""" temp_path = 'C:\\Python27\\' + file_name
file = open(temp_path, 'w')
file.write('')
file.close()
print 'Execution completed.'
MakeFile('my.active.uboat.data.txt')
I dont understnd python but it seems that the command "MakeFile (file_name)" wasnot
doing anything.
That "makes a file" thingy looks weird for me. Is this a comment or something?
Installed python v2.7.2.
dottore
09-10-12, 07:38 AM
Yes it is a comment.
I think I found the problem. But in my file there is everything okay.
You need to hit the Enter at temp_path.
So:
"""
temp_path.............
Like there is in my progress code below.
Maybe when you edited the file you hit the backspace or something.
Mod: I didn't make troubleshooting, but maybe if you use other viewer than notepad that can confuse the indents. Python is a heavy indent dependent language. If you save it in an another format, maybe there could be a problem.
Important: I am ready with the new simpler script, but I'm waiting a help guide to run it correctly from game.
You need to hit the Enter at temp_path.
The program was terminated with an error message. There is no Wait-for-input for me.
What is the purpose of """ ?
dottore
09-10-12, 11:06 AM
You don't need to input anything after you run the *.bat file. If you made the changes that I marked in the script, the script will run without problem. If you don't make the changes, the script won't find the files.
""" is a comment sign for more lines than one for information to other users or remind for the programmer. The interpreter will leave alone these lines. They don't need to running the script. Example:
"""
Sea sells seashells on
the seashore.
"""
I marked the change requirements in the archived script, that you need to make before run.
This is your Campaignmission file's path, you need to use \\ instead of \ to separate folders. And your Stellarium's path also.
If you'd like I give you my msn and we solve this in 2 mins. If somebody had a problem too don't hesitate contact me and I fix for you in no time.
Mod: I sent PM with my MSN.
Ok, got it to work. It was my error.
Some suggestions about the startup.ssc:
1)The startup screen in stellarium is a snapshot of your sunshot/moonshot/starshot/... with the help of your sextant. So the time in stellarium has to be stopped in the beginning. Dont know the script command here but it it could be core.timehold(0) or similar.
2)You get no seconds from the campaignfile? You have to create one. Celestial navigation with always hh:mm:00 feels not right and very unnatural. "Seconds management" is a very important part during your sextant-shot. see here at 3:03ff (http://www.youtube.com/watch?v=wCTToLtLHtc)
3) Also a bit complicated are the time-zones. Do you know which time you get from the campaignfile: UTC or local?
Have to install stellarium v11.4 and must test the script a little bit more...
dottore
09-11-12, 05:54 AM
1) :yep: This is easy. No problem.
2) :hmmm: No seconds in the mission file, so that's why made this. But in my new script with the Game.CurrentGameDateTime ingame variable this is working. :03: Just I am waiting for a kind modder how to make this script working ingame when you load the saved game. You can get seconds and this variant only from ingame.
3) :yep: You get the GMT time always.
That's why I wrote below to make the Stellarium config.ini time_zone = GMT. If it isn't GMT your time will be :doh: in Stellarium.
Another important thing is, you have observed that fact, that in game you can see graphic surprises which is not true, so we cannot compare accordingly the ingame view with Stellarium. As a wise member said in my topic, about the Nautical Map:http://www.subsim.com/radioroom/showpost.php?p=1929111&postcount=2
A fact that I think my script is worked properly: I tried the 1939-45 Sunalmanac. At sunrise I noted the time and search for the guessed latitude on that day. I saw the sunrise at: GMT 4h:28min. I know that I am east from GMT. On the 50th latitude GMT sunrise time 5h:18 min so you are 50 min East from GMT time. 50 min is 12.5 degree so I am roughly 12.5 degree to the EAST. My ingame navdata is 54,3243126261 North, 12.1823970313 East. This error is generated because of the inaccurate inspect of the sunrise time. That's why seconds are very important. The correct sunrise time is 48,73 min East from GMT time. Does matter we speak about geometric sunrise or trailing(leading) sunrise. Generally we meet leading sunrise times. In Stellarium I advise to accept the sunrise time, when the sun passed the horizon by 0 degree 15' and 30''. This is the apparent height. If you do this will be the most close to the in game sunrise time and you can calculate the accurate East shift.
Mod:
The ingame new much simpler script, yet it needs your 1) suggestion.
Don't use yet, because it only works now from Scriptmanager and just ingame. But works! :yeah: Don't need to run any file nor use the python interpreter. This code snippet is copy pasted so isn't properly indented to copypaste again and use. I don't know yet, how to make it work like the other scripts in game.
#Stellarium
def MakeFile(file_name):
# python path below use \\
temp_path = 'C:\\Program files\\Stellarium\\scripts\\' + file_name
file = open(temp_path, 'w')
file.write('')
file.close()
MakeFile('startup.ssc')
latitudealpha = PageDefaultHud_MapGroup_Mapcontrol.SubmarineContac t.Location.X
longitudealpha = PageDefaultHud_MapGroup_Mapcontrol.SubmarineContac t.Location.Y
latitudealpha2 = float(latitudealpha) / 120000
longitudealpha2 = float(longitudealpha) / 120000
stella=open("c:\\Program files\\Stellarium\\scripts\\startup.ssc", 'w')
a = 'core.setDate("'+str(Game.CurrentGameDateTime)+'");\n'+'core.setObserverLocation('+str(longitudealp ha2)+','+' '+str(latitudealpha2)+', 10, 0, "1");'
b = str(a)
c = list(b)
c[18] = ':'
c[21] = ':'
c[24] = 'T'
c[25] = ''
d = "".join(c)
stella.write(d)
stella.close()
#end of stellarium
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.