TheBigDog Posted October 22, 2007 Report Posted October 22, 2007 Per CraigD's suggestion I have created this thread for our conversation on a simulator for launch to soft landing portions of the mission profile. Here is a link to NASA's Moon Fact Sheet, which should have all the data you need for representing the earth and the moon in the simulator. Moon Fact Sheet What it does not have is a lunar calendar. It notes that the distance of the moon ranges quite a bit.Mean values at opposition from Earth Distance from Earth (equator, km) 378,000 Apparent diameter (seconds of arc) 1896 Apparent visual magnitude -12.74 * These represent mean apogee and perigee for the lunar orbit. The orbit changes over the course of the year so the distance from the Moon to Earth roughly ranges from 357,000 km to 407,000 km.50,000 kilometers between close and far. We need to plot that distance on the calendar to match our math with our launch window. I would aim for the dead center of the visible face of the moon, with the landing taking place at the beginning of the lunar day for that point. That gives us about two weeks of solar power to complete the primary mission. However, I gladly defer to more knowledgeable folks on this important part of the mission. Of interest... <base target="_self"> <title>Eagle Lander 3D Lunar Lander Simulator - Palm OS Lunar Explorer: A Space Flight Simulator - MobyGames Bill Quote
TheBigDog Posted October 27, 2007 Author Report Posted October 27, 2007 Not exactly a mission sim, but it is a fun toy... Gravity Simulator I downloaded it and it is pretty cool. You can see the orbits of everything in the solar system at any point in time. I am looking forward to what Craig is building. :hal_jackolantern: Bill Quote
TheBigDog Posted October 27, 2007 Author Report Posted October 27, 2007 OK, I have some free time this weekend (got my homework done!) so I am going to take a crack at a VB.net based simulator that I can post here. I will post the program and the code. ready... set... Code!!! Quote
Janus Posted October 28, 2007 Report Posted October 28, 2007 There is a spaceflight simulator called "orbiter" which I have on my computer and which might be made to work for our purposes. It comes with some ready-made spacecraft, but it is possible to modify/create ships of your own. I'm looking into how easy this to do and what the limitations are. Quote
TheBigDog Posted October 30, 2007 Author Report Posted October 30, 2007 I have written a gravity simulator. It works in 3D (x,y,z coordinates) and runs on a 1 second time interval. I can create any number of bodies in free space with mass, vector, and velocity. Of course this does not mean that there are any graphics. So far I have the Earth and the Moon, with them acting upon each other as the moon orbits the earth. Next step is to put something in orbit of the earth and then fly it to the moon. I am not bothering with launching from the earth. Of course all of this is moot since Janus has a program that can do it already, but it has been a very interesting exercise and I have learned a great deal from spending time on it over the weekend. I will post it when I have added controls instead of setting all the value in code. Bill Quote
CraigD Posted October 30, 2007 Report Posted October 30, 2007 I have written a gravity simulator. It works in 3D (x,y,z coordinates) and runs on a 1 second time interval.:( Excelent! I look forward to seeing it. I finished my latest, GRAVSIM4, last weekend. It's main features/changes:Like my previous GRAVSIM*s, it’s a command line interpreter.I redid its syntax completely (the old ones’ were kinda clunky).Everything in the syntax is an object that can be viewed or set (eg: Earth.M=5.9736e24 #sets the mass of the Earth to its usual value)The $ object is the simulator itselfIt’s major enhancement of the old ones is that the bodies (Earth, Moon, the ship, etc.) have an property (.X) that allow you to give each a program consisting of MUMPS code, allowing them to do stuff like change their mass and acceleration per a rocket motor & fuel programIt’s not as practical, yet, as GRAVSIM2. I don’t plan to make it much more, rather I plan to write .X code for stuff like graphics output. The command line itself, I plan to leave with only primitive output features. Here’s a run of the simulator showing a 100 kg rocket with 900 kg of fuel and specific impulse 450 s – basically a really big model rocket – go up then down in a little less than 104 sXGRAVSIM4>Earth.M=5.9736e24 Moon.M=7.347673e22 .L=363104000,0,0 .V=0,1082,0 #The usual Earth and Moon XGRAVSIM4>Ship.M=1000 .L=6378137,0,0 .V=0,463.8,0 #1000 kg Ship on the surface of the equator XGRAVSIM4>Ship.X="n (B,I) s Mf=B(I,""X"",""Mf""),SI=B(I,""X"",""SI""),M=-Mf*B(""TI"")+B(I,0) s:M<B(I,""X"",""M0"") Mf=0 s A=Mf*SI/(M+B(I,0))*2,B(I,21)=B(I,""X"",21)*A,B(I,22)=B(I,""X"",22)*A,B(I,23)=B(I,""X"",23)*A,B(I,0)=-Mf*B(""TI"")+B(I,0)" #Rocket motor XGRAVSIM4>.X("SI")=250 .X("Mf")=50 .X("M0")=100 #Rocket motor specific impulse, burn rate, and 100 kg minimum vehicle mass XGRAVSIM4>.X(21)=1 .X(22)=0 .X(23)=0 #thrust vector XGRAVSIM4>$.T=1 Ship.M .L .V .A # #SHIP.M=950 .L=6378138.510032063895,463.7998218340913345,0 .V=3.02006412778904451,463.7996436681826685,0 .A=12.82051282051282051,0,0 XGRAVSIM4>$.T=10 Ship.M .L .V .A #SHIP.M=500 .L=6378414.894590005906,4637.880633501694489,0 .V=75.20675035288839365,463.7643692911025346,0 .A=23.80952380952380952,0,0 XGRAVSIM4>$.T=20 Ship.M .L .V .A #SHIP.M=100 .L=6380677.051336701228,9275.04882631241004,0 .V=377.1969438729633817,463.6575375527910744,0 .A=0,0,0 #Note: engine shutoff XGRAVSIM4>$.T=30 Ship.M .L .V .A #SHIP.M=100 .L=6383959.572000057278,13910.79377670996689,0 .V=279.3238639845522164,463.4797680659022456,0 .A=0,0,0 XGRAVSIM4>$.T=40 Ship.M .L .V .A #SHIP.M=100 .L=6386263.816969892319,18544.40719033907758,0 .V=181.5368644980712998,463.2312502756681295,0 .A=0,0,0 XGRAVSIM4>$.T=50 Ship.M .L .V .A #SHIP.M=100 .L=6387590.497549352828,23175.1820474100567,0 .V=83.80606490867480755,462.9120625488694604,0 .A=0,0,0 XGRAVSIM4>$.T=60 Ship.M .L .V .A #SHIP.M=100 .L=6387940.02674845683,27802.41167964278307,0 .V=-13.89832117965128978,462.5221968732724911,0 .A=0,0,0 #Note: rocket coming down XGRAVSIM4>$.T=100 Ship.M .L .V .A #SHIP.M=100 .L=6379564.474404304418,46261.7085752850397,0 .V=-405.0469612267389591,460.2527731771944981,0 .A=0,0,0 XGRAVSIM4>$.T=101 Ship.M .L .V .A #SHIP.M=100 .L=6379154.529490345703,46721.92565277778461,0 .V=-414.8428666906910533,460.1813818082953234,0 .A=0,0,0 XGRAVSIM4>$.T=102 Ship.M .L .V .A #SHIP.M=100 .L=6378734.788041651078,47182.07097860561975,0 .V=-424.6400306985589834,460.1092698473749626,0 .A=0,0,0 XGRAVSIM4>$.T=103 Ship.M .L .V .A #SHIP.M=100 .L=6378305.248784582742,47642.14383192611936,0 .V=-434.4384834381129305,460.0364367936242636,0 .A=0,0,0 XGRAVSIM4>$.T=104 Ship.M .L .V .A #SHIP.M=100 .L=6377865.910415304252,48102.14349139155726,0 .V=-444.2382551188663537,459.9628821372515378,0 .A=0,0,0 #note: splat! at 104 seconds XGRAVSIM4>$.ti=0 #how to exit the simulatorHere’s the current MUMPS code of GRAVSIM4:N (XCU,XQMP,XGRAVSIM3D1,XGRAVSIM4) x XGRAVSIM3D1(-1) s LO="$",WF=0 f q:'B("TI") w:WF ! s WF=0,WLO="" r "XGRAVSIM4>",R,! x XCU,XGRAVSIM4((R="?":0,1:1)) ;XGRAVSIM4: YA Gravity simulator s N="" f s N=(XGRAVSIM4(0,N)) q:N="" w (XGRAVSIM4(0,N),";"),! ;XGRAVSIM4(0) Enter - Object.property to display a property ;XGRAVSIM4(0,1) - Object.property=value to set a property to a value ;XGRAVSIM4(0,2) - #followed by any text to be ignored (a comment) ;XGRAVSIM4(0,2.5) - Any of the above, separated by one or more spaces ;XGRAVSIM4(0,2.7) Note - If object is omitted, the previously referenced object is assumed ;XGRAVSIM4(0,3) - Occurances of the text "XGRAVSIM4>" at the beginning are ignored. ;XGRAVSIM4(0,3.5) - The special object $ has the following properties: ;XGRAVSIM4(0,4) -- T - elapsed time of simulation. Set to a greater value to advance ;XGRAVSIM4(0,5) simulation ;XGRAVSIM4(0,6) -- TI - simulation interval. Default 1. The interval of simulation ;XGRAVSIM4(0,7) time between calculations. Set to 0 to end simulation. ;XGRAVSIM4(0,8) -- ALL - Display only. Displays all properties of all objects. ;XGRAVSIM4(0,8.5) - Other object have the following properties: ;XGRAVSIM4(0,9) -- M - mass of object ;XGRAVSIM4(0,10) -- L (=n,n,n) location of object ;XGRAVSIM4(0,11) -- V (=n,n,n) velocity of object ;XGRAVSIM4(0,12) -- A (=n,n,n) acceleration of object ;XGRAVSIM4(0,13) -- X (may be followed by (subscripts...), ="xecute code") code to be ;XGRAVSIM4(0,14) xecuted each simulation interval. Meaningful symbols: ;XGRAVSIM4(0,15) --- B(I,0) - mass of object -OK to set ;XGRAVSIM4(0,16) --- B(I,21) ,22) ,23) - acceleration of object -OK to set ;XGRAVSIM4(0,17) --- B(OI(object),1) ,2) ,3) - location of any object -read only, please ;XGRAVSIM4(0,18) --- B(OI(object),11) ,12) ,13) - velocity of any object -read only ;XGRAVSIM4(0,19) x XGRAVSIM4(1,-1) s (R(1),CC)=R,R(2)=" ",R(3)=0 x XQMP f CP=1:1:R s R(1)=CC,R(2)=" ",R(3)=CP x XQMP i R]"" s C=R q:C?1"#".e s R(1)=R,R(2)="=",R(3)=1 x XQMP s O=(R,"."),O=(O="":LO,1:O),P=(R,".",2),V=C,(V,1,(R)+1)="" x XGRAVSIM4(1,V]"",O'="$") s LO=O ;XGRAVSIM4(1) f q:R'?1.an1">".e s (R,">")="",(R)="" ;XGRAVSIM4(1,-1) s N="" f s N=(XGRAVSIM4(1,0,0,1,N)) q:N="" x XGRAVSIM4(1,0,0,1,N) q:N="" ;XGRAVSIM4(1,0,0): show system property i P="T" s V=B("T") x XGRAVSIM4(2) s N="" ;XGRAVSIM4(1,0,0,1,1) i P="TI" s V=B("TI") x XGRAVSIM4(2) s N="" ;XGRAVSIM4(1,0,0,1,2) i P="ALL" x XGRAVSIM4(1,0,0,1,3,0) s O="" f s O=(OI(O)) q:O="" x XGRAVSIM4(1,0,0,1,3,1),XGRAVSIM4(1,0,0,1,3,1.1) ;XGRAVSIM4(1,0,0,1,3) s O="$" f P="T","TI" x XGRAVSIM4(1,0,0) ;XGRAVSIM4(1,0,0,1,3,0) f P="M","L","V","A" x XGRAVSIM4(1,0,1) ;XGRAVSIM4(1,0,0,1,3,1) s (Q,Q0)=(B(OI(O),"X")),P="X" x:(@Q)#10 XGRAVSIM4(1,0,1) f s (P,Q)=(@Q) q:(@Q,2)'=Q0 s (P,1,(Q0))="X(" x XGRAVSIM4(1,0,1) ;XGRAVSIM4(1,0,0,1,3,1.1) s V="undefined",WLO="" x XGRAVSIM4(2) ;XGRAVSIM4(1,0,0,1,999) s N="" f s N=(XGRAVSIM4(1,0,1,1,N)) q:N="" x XGRAVSIM4(1,0,1,1,N) i N="" x XGRAVSIM4(2) q ;XGRAVSIM4(1,0,1): show object property s I=(OI(O)) i 'I s P="",V="undefined",WLO="" s N="" ;XGRAVSIM4(1,0,1,1,-1) i P="M" s V=B(I,0) s N="" ;XGRAVSIM4(1,0,1,1,1) i P="L" s V=B(I,1)_","_B(I,2)_","_B(I,3) s N="" ;XGRAVSIM4(1,0,1,1,2) i P="V" s V=B(I,11)_","_B(I,12)_","_B(I,13) s N="" ;XGRAVSIM4(1,0,1,1,3) i P="A" s V=B(I,21)_","_B(I,22)_","_B(I,23) s N="" ;XGRAVSIM4(1,0,1,1,4) i P?1"X".1"(".e k N s V=P,(V,1,2)="B(I,""X"""_(P="X":")",1:","),N((@V,"undefined"))="",N=(N),V=(N,3,(N)-1) k N s N="" ;XGRAVSIM4(1,0,1,1,5) n N s V=Q,(V,1,(Q0))="X",N((@Q,"undefined"))="",N=(N),V=V_"="_(N,3,(N)-1) ;XGRAVSIM4(1,0,1,1,5,1) s V="undefined",WLO="" x XGRAVSIM4(2) ;XGRAVSIM4(1,0,1,1,999) s N="" f s N=(XGRAVSIM4(1,1,0,1,N)) q:N="" x XGRAVSIM4(1,1,0,1,N) q:N="" ;XGRAVSIM4(1,1,0): set system property i P="T" s N="" f q:B("T")'<V x XGRAVSIM4(1,1,0,1,1,1),XGRAVSIM3D1(0) ;XGRAVSIM4(1,1,0,1,1) f I=1:1:B("I9") x (B(I,"X")) ;XGRAVSIM4(1,1,0,1,1,1) i P="TI" s B("TI")=V s N="" ;XGRAVSIM4(1,1,0,1,2) s V="undefined",WLO="" x XGRAVSIM4(2) ;XGRAVSIM4(1,1,0,1,999) s N="" f s N=(XGRAVSIM4(1,1,1,1,N)) q:N="" x XGRAVSIM4(1,1,1,1,N) q:N="" ;XGRAVSIM4(1,1,1): set object property s I=(OI(O)) i P="M" s:'I I=B("I9")+1,OI(O)=I s B(I,0)=V x XGRAVSIM3D1(-1) s N="" ;XGRAVSIM4(1,1,1,1,1) i I,P="L" s B(I,1)=+V,B(I,2)=+(V,",",2),B(I,3)=+(V,",",3) x XGRAVSIM3D1(-1) s N="" ;XGRAVSIM4(1,1,1,1,2) i I,P="V" s B(I,11)=+V,B(I,12)=+(V,",",2),B(I,13)=+(V,",",3) x XGRAVSIM3D1(-1) s N="" ;XGRAVSIM4(1,1,1,1,3) i I,P="A" s B(I,21)=+V,B(I,22)=+(V,",",2),B(I,23)=+(V,",",3) x XGRAVSIM3D1(-1) s N="" ;XGRAVSIM4(1,1,1,1,4) i I,P?1"X".1"(".e s (P,1,2)="B(I,""X"""_(P="X":")",1:","),@(P_"="_V) s N="" ;XGRAVSIM4(1,1,1,1,5) s:'I P="" s V="undefined",WLO="" x XGRAVSIM4(2) ;XGRAVSIM4(1,1,1,1,999) w (WF:" ",1:"#"),(O=WLO:"",1:O),(P]"":".",1:""),P,"=",V s WF=1,WLO=O ;XGRAVSIM4(2): output O.P=V i P="T" s N="" f q:B("T")'<V x XGRAVSIM4(1,1,0,1,1,1),XGRAVSIM3D1(0) ;XGRAVSIM4(1,1,0,1,1) f I=1:1:B("I9") x (B(I,"X")) ;XGRAVSIM4(1,1,0,1,1,1) i P="TI" s B("TI")=V s N="" ;XGRAVSIM4(1,1,0,1,2) s N="" f s N=(XGRAVSIM4(1,1,1,1,N)) q:N="" x XGRAVSIM4(1,1,1,1,N) q:N="" ;XGRAVSIM4(1,1,1): set object property s I=(OI(O)) i P="M" s:'I I=B("I9")+1,OI(O)=I s B(I,0)=V x XGRAVSIM3D1(-1) s N="" ;XGRAVSIM4(1,1,1,1,1) i I,P="L" s B(I,1)=+V,B(I,2)=+(V,",",2),B(I,3)=+(V,",",3) x XGRAVSIM3D1(-1) s N="" ;XGRAVSIM4(1,1,1,1,2) i I,P="V" s B(I,11)=+V,B(I,12)=+(V,",",2),B(I,13)=+(V,",",3) x XGRAVSIM3D1(-1) s N="" ;XGRAVSIM4(1,1,1,1,3) i I,P="A" s B(I,21)=+V,B(I,22)=+(V,",",2),B(I,23)=+(V,",",3) x XGRAVSIM3D1(-1) s N="" ;XGRAVSIM4(1,1,1,1,4) i I,P?1"X".1"(".e s (P,1,2)="B(I,""X"""_(P="X":")",1:","),@(P_"="_V) s N="" ;XGRAVSIM4(1,1,1,1,5) s:'I P="" s V="undefined",WLO="" x XGRAVSIM4(2) ;XGRAVSIM4(1,1,1,1,999) w (WF:" ",1:"#"),(O=WLO:"",1:O),(P]"":".",1:""),P,"=",V s WF=1,WLO=O ;XGRAVSIM4(2): output O.P=V n (R) s R=(R,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ") ;XCU: fold to uppercase n (XQMP,R) s Q="""",D=R(2),(M,R)=D_R(1) x XQMP(1) s R=((R(3)):(R,((M,D,1,R(3)))+2,((M,D,1,R(3)+1))),1:(M,D)-1) ;XQMP: quote sensitive R=(R(1),R(2),R(3)) or R=(R(1),R(2)) if 'R(3) s D1=((D)+1) f I=2:2:(R(1),Q) s (M,Q,I)=(("",((M,Q,I)))," ",D1) ;XQMP(1) ;XGRAVSIM3D1: 3-d gravity simulator core N (XGRAVSIM3D1,B) s B("G")=(B("G"),6.6742e-11),B("TI")=(B("TI"),1),B("T")=(B("T"),0),B("S")=(B("S"),1),B("I9")=0 x XGRAVSIM3D1(-1,1) m B=B2 ;XGRAVSIM3D1(-1): Assure B valid for call to XGRAVSIM3D1(0) f J=1:1 s I=(B("")) q:'I s B("I9")=J m B2(J)=B(I) k B(I) f K=0:1:3,11:1:13,21:1:23 s B2(J,K)=(B2(J,K),0) ;XGRAVSIM3D1(-1,1) N (XGRAVSIM3D1,B) s I9=B("I9"),G=B("G"),TI=B("TI"),S=B("S") X XGRAVSIM3D1(2),XGRAVSIM3D1(3) M B=B1 s B("T")=TI*S+B("T") ;XGRAVSIM3D1(0): Increment B,T by 1*TI F I2=1:1:I1-1,I1+1:1:I9 S DY=B(I2,1)-Y,DX=B(I2,2)-X,DZ=B(I2,3)-Z,D2=DY*DY+(DX*DX)+(DZ*DZ),D=D2**.5,A=G*B(I2,0)/D2*TI*S,VY=DY/D*A+VY,VX=DX/D*A+VX,VZ=DZ/D*A+VZ ;XGRAVSIM3D1(1): change body I1 velocity F I1=1:1:I9 S VY=B(I1,11),VX=B(I1,12),VZ=B(I1,13),Y=VY*TI/2+B(I1,1),X=VX*TI/2+B(I1,2),Z=VZ*TI/2+B(I1,3) X XGRAVSIM3D1(1) S VY=B(I1,21)*TI*S+VY,VX=B(I1,22)*TI*S+VX,VZ=B(I1,23)*TI*S+VZ,B1(I1,11)=VY,B1(I1,12)=VX,B1(I1,13)=VZ ;XGRAVSIM3D1(2): change all velocities F I=1:1:I9 S B(I,1)=B(I,11)+B1(I,11)/2*TI*S+B(I,1),B(I,2)=B(I,12)+B1(I,12)/2*TI*S+B(I,2),B(I,3)=B(I,13)+B1(I,13)/2*TI*S+B(I,3) ;XGRAVSIM3D1(3): change all positionsI’m curious to see how TBD’s VB.net-based simulator and my MUMPS-based simulator compare. :QuestionM TBD, can you run yours for the following “standard”, a single geostationary orbit? Here are the parameters (all units kg, m, & s, calculated from this wikipedia article):Gravitational constant = 6.6742e-11Orbital radius (from center of Earth) = 42164140.10012396182Orbital speed = 3074.661175977908351Sample position and velocity at 43082 and 86164 s (half and full orbit)Here’re the results from GRAVSIM4GRAVSIM4>Earth.M=5.9736e24 #usual Earth GRAVSIM4>Ship.M=10 .L=42164140.10012396182,0,0 .V=0,3074.661175977908351,0 #Ship in geostationary orbit GRAVSIM4>$.t=43082 ship.l .v #SHIP.L=-42145157.25275492353,-59527.65293408068424,0 .V=4.343756684837521444,-3076.039916833619272,0 #note: 42145199.29245684292 3076.042983798489842 $.t=86164 ship.l .v #SHIP.L=42163972.13018178319,119001.7055088261738,0 .V=-8.679701336015950322,3074.648927402258311,0 #note: 42164140.06238785073 3074.661178730290591Note that the orbit seems stable – its speed changed by only .00000275238224 m/s – but isn’t perfectly circular, dipping from about 42164140 to 42145199, and goes more than 1 full orbit in 86164 s. Quote
TheBigDog Posted October 30, 2007 Author Report Posted October 30, 2007 Note that the orbit seems stable – its speed changed by only .00000275238224 m/s – but isn’t perfectly circular, dipping from about 42164140 to 42145199, and goes more than 1 full orbit in 86164 s. How far beyond a full orbit does it go? It should be short by 278.349 meters in 86164 seconds considering the sidereal rotation time of the earth. The Earth rotates once in a few minutes under a day (23 hours 56 minutes 04. 09053 seconds). 23 x 3600 = 8280056 x 60 = 33604 x 1 = 4 82800 + 3360 + 4 = 86164. What is the final margin of error you are showing? I will need some time to run my own sim, give me a day or two. Bill Quote
CraigD Posted October 31, 2007 Report Posted October 31, 2007 How far beyond a full orbit does it go? It should be short by 278.349 meters in 86164 seconds considering the sidereal rotation time of the earth.A lot beyond – about 119001 m, or 39 s. I suspect my high-precision calculations of GEOSTAT orbit are off vs. the constant of gravity and Earth mass in the simulation – I used slightly different sources calculating them. I can tweak the orbital radius up ~ 6315 m to get nearly exactly a 86164 s orbital period, like this:XGRAVSIM4>Earth.M=5.9736e24 XGRAVSIM4>Ship.M=10 .L=42170455,0,0 .V=0,3074.661175977908351,0 XGRAVSIM4>$.t=43082 ship.l .v #SHIP.L=-42164136.41712641552,-11.14168741885003,0 .V=.0008125255939590325,-3075.121934885605702,0 #note: 42164136.41712788759 3075.121934885713047 XGRAVSIM4>$.t=86164 ship.l .v #SHIP.L=42170454.9999941175,22.279930461983273,0 .V=-.0016245603985481512,3074.661175977479037,0 #note: 42170455.00000000309 3074.661175977908222though the resulting orbit is still slightly (~ 6319 m) non-circular. All in all, though, I pretty happy with the accuracy of my GRAVSIM* simulators – I’ve used them to practice various maneuvers, mostly in Earth orbit, and they always agree pretty closely with published data. I much prefer the new, object-y syntax, though still need to add some essential useful $ (simulator/system) object properties, such as a “dump all” function – small, easy enhancements. As I mentioned in my previous post, the neatest thing about GRAVSIM4 is that you can add “programs” to each object, the ship being the most interesting object. Since that’s all done with MUMPS xecute code, it’s easy to make these programs “modular” – a rocket motor program can run with throttle and thrust vector data from a guidance program, etc. – and “big bump” events like stage separations can be separate programs that wait for a defined condition to adjust the ship’s net mass and current engine characteristics. Weird stuff like atmospheric drag (for launch or aerobraking), magnetic or solar sail propulsion (not in scope for an orbit-to-moon mission, but handy in general) can be written and dropped in. I hope to build a small library of useful .X programs ASAP, with parameters for real-world commercial motors, making it possible to quickly try different configurations of ship hardware. Guidance programming remains the hard part. It’s real rocket science, and not something I’ve ever done professionally, so rather over my head (unless I can smooze in with some local NASA folk ;) ). I’ve a tendency to come up with rough calculations, then “fly by the seat of my pants” to compensate for their roughness – not, I’m pretty sure, how the pros do it. Graphics are another problem area – I don’t have anything handy that will give me a real-time graphic diagram, and find myself spending a lot of time struggling to visualize the numeric data. Though a browser interface would be slickest, I’ll probably write a small VB app to run separate from my terminal window – but either approach will take worktime, which I’ve not got a lot of extra free right now. :( I’d also like to learn more latex, so that I could put graphics in posts using [math] tags, though this isn’t very helpful for realtime visualizing. For the next day or so, I fear I’ll be consumed by the much-less interesting (but better paying :) ) world of SOX. Gah! :( Quote
Janus Posted October 31, 2007 Report Posted October 31, 2007 Graphics are another problem area – I don’t have anything handy that will give me a real-time graphic diagram, and find myself spending a lot of time struggling to visualize the numeric data. Though a browser interface would be slickest, I’ll probably write a small VB app to run separate from my terminal window – but either approach will take worktime, which I’ve not got a lot of extra free right now. :( I’d also like to learn more latex, so that I could put graphics in posts using [math] tags, though this isn’t very helpful for realtime visualizing. ( Here's some of the info you can bring up graphically with "orbiter". It also allows for a real time view of and from your craft. Quote
Jay-qu Posted October 31, 2007 Report Posted October 31, 2007 It looks like the celestia interface there in the background. Quote
Janus Posted November 2, 2007 Report Posted November 2, 2007 I have downloaded the software developers kit for orbiter, and will go over the documentation this weekend. I also downloaded an add on which allows for multistage support, and I'll take a look at it also. In the meantime, I started working on a simple mesh that can be used for the visual representation of the lander in the sim. It can be refined as we get a better idea of what the final lander will be like. Quote
TheBigDog Posted November 3, 2007 Author Report Posted November 3, 2007 I’m curious to see how TBD’s VB.net-based simulator and my MUMPS-based simulator compare. TBD, can you run yours for the following “standard”, a single geostationary orbit? Here are the parameters (all units kg, m, & s, calculated from this wikipedia article): * Gravitational constant = 6.6742e-11 * Orbital radius (from center of Earth) = 42164140.10012396182 * Orbital speed = 3074.661175977908351 * Sample position and velocity at 43082 and 86164 s (half and full orbit)As far as I can tell we had very similar results. But because of how my simulator keeps all of the coordinates relative to a zero point in space it was difficult for me to tell exactly. When I added the sat to the sim it was orbiting the earth, but the earth was moving as it is influenced by the moon, so after a revolution I no longer had a solid frame of reference. I am creating a logging function so that the sim will be like our real life experiment, and the logging will be like the telemetry to do analysis after the fact. I am also creating a function for adding objects to the simulator in a nicer fashion than I am doing now. I am starting the sim with the earth. As you add objects you indicate what they are orbiting around, their current distance from their parent, and their current speed/direction (along with their mass and diameter). Then when you start the sim it begins with everything in that position. Because every object is acting upon every other object in the sim (however minutely) I want to indicate somehow what all the paired gravitational forces are. But that might be left read from the output file, rather than from the real time on screen feedback. The output file from the telemetry is going to be a delimited text file, so you can use any type of program to turn it into useful data for yourself. Last I will add a graphical part for observing the tests in a fun fashion. All the while I am looking forward to seeing what Janus is cooking up. Bill Quote
TheBigDog Posted November 3, 2007 Author Report Posted November 3, 2007 This is more complicated than I had initially estimated. Who would have thunk that about orbital mechanics and rocket science? :wave2: Bill Quote
Buffy Posted November 4, 2007 Report Posted November 4, 2007 This is more complicated than I had initially estimated. Who would have thunk that about orbital mechanics and rocket science? :hihi:Good thing that for the X prize you don't need to do lunar orbit *rendezvous*! That's wickedly more difficult than just getting on the ground in one piece! Did you know that Buzz Aldrin got his doctorate with a ground-breaking dissertation on orbital rendezvous? They don't call it rocket science for nothing, :doh:Buffy Quote
TheBigDog Posted November 5, 2007 Author Report Posted November 5, 2007 Well, here it is. Ugly and bloated, but functional. I need to step away from it for a while. Then I will add rockets, stages, and thrust vectors to the thing. For now you can do fun things like make a universe of two bowling balls 1 km apart and see how long it takes them to come together from their gravitational attraction. :hyper: Bill Quote
TheBigDog Posted November 5, 2007 Author Report Posted November 5, 2007 And the code... Imports System Imports System.IO Public Class Form1 'First I have to create the environment. 'The Earth and the Moon 'The environment is populated with objects 'Each object has properties of ... 'Mass, location, radius, direction, velocity 'Certain objects will have additional attributes of... 'Stage, fuel, thrust, thrust direction 'The object is to launch a rocket from earth and soft land it on the moon 'This will be done by adjusting the attributes as time passes 'to adjust the objects relitive to one another Dim Bodies() As Body Dim AnyBodies As Boolean = False Dim Time As Long Sub Begin() 'Create the "Heavenly bodies" Dim sw As StreamWriter 'Check if the default file exists... 'Create it if needed... If File.Exists(LogDirectory.Text & "DefaultBodies.lms") = False Then sw = File.AppendText(LogDirectory.Text & "DefaultBodies.lms") For a As Integer = 1 To 3 sw.WriteLine( _ Choose(a, "Earth", "Moon", "Alice") & "," & _ Choose(a, 0, 0, 0) & "," & _ Choose(a, 0, 378000000, 42164140.100123964) & "," & _ Choose(a, 0, 0, 0) & "," & _ Choose(a, 6378100, 1738100, 1) & "," & _ Choose(a, 5.9736 * (10 ^ 24), 0.07349 * (10 ^ 24), 1000) & "," & _ Choose(a, 0, 1023, 3074.6611759779084) & "," & _ Choose(a, 0, 0, 0) & "," & _ Choose(a, 0, 0, 0) & ",") Next sw.Close() End If AnyBodies = False LoadFile(LogDirectory.Text & "DefaultBodies.lms") Timer1.Tag = "Second,Body,Mass,Radius,x,y,z,xv,yv,zv" & vbCrLf LogPosition(0) End Sub Function Parse(ByVal Line As String, ByVal Place As Integer, ByVal Delimiter As String) As String Dim a As Integer = 0 Do Until a = Place Line = Mid$(Line, Line.IndexOf(Delimiter) + 2, Line.Length - Line.IndexOf(Delimiter)) a += 1 Loop Return Mid$(Line, 1, Line.IndexOf(Delimiter)) End Function Sub LoadFile(ByVal FullPath As String) Dim sr As StreamReader sr = File.OpenText(FullPath) AnyBodies = False Dim Line As String Do Until sr.EndOfStream = True Line = sr.ReadLine CreateBody(Parse(Line, 0, ",")) With Bodies(Bodies.Length - 1) .x = Parse(Line, 1, ",") .y = Parse(Line, 2, ",") .z = Parse(Line, 3, ",") .r = Parse(Line, 4, ",") .m = Parse(Line, 5, ",") .xv = Parse(Line, 6, ",") .yv = Parse(Line, 7, ",") .zv = Parse(Line, 8, ",") End With For b As Integer = 0 To 8 Bodies(Bodies.Length - 1).Value(:hyper:.Text = SetValue(Bodies(Bodies.Length - 1), b + 1) Bodies(Bodies.Length - 1).Alternate(B).Text = SetValue(Bodies(Bodies.Length - 1), b + 1) Next Loop sr.Close() End Sub Function SetValue(ByVal Body As Body, ByVal Part As Integer) As String Return Choose(Part, Body.x, Body.y, Body.z, Body.r, Body.m, Body.xv, Body.yv, Body.zv, Body.v) End Function Function SetField(ByVal Body As Body, ByVal Part As Integer) As String Return Choose(Part, "X:", "Y:", "Z:", "Radius:", "Mass:", "xVelocity:", "yVelocity:", "zVelocity", "aVelocity") End Function Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load LogDirectory.Text = System.Environment.CurrentDirectory Begin() End Sub Function gForce(ByVal body1 As Body, ByVal body2 As Body) As Double Return (body1.m * body2.m) / (((body1.x - body2.x) ^ 2) + ((body1.y - body2.y) ^ 2) + ((body1.z - body2.z) ^ 2)) * (6.67428 * (10 ^ (-11))) End Function Function aForce(ByVal body1 As Body, ByVal body2 As Body, ByVal axis As String) As Double Dim f, x, y, z As Double x = (body1.x - body2.x) y = (body1.y - body2.y) z = (body1.z - body2.z) f = Math.Sqrt((x ^ 2) + (y ^ 2) + (z ^ 2)) Select Case axis Case "x" aForce = (gForce(body1, body2) * x / f) Case "y" aForce = (gForce(body1, body2) * y / f) Case "z" aForce = (gForce(body1, body2) * z / f) Case Else aForce = 0 End Select Return aForce End Function Sub DeltaV() On Error GoTo Err For Each target As Body In Bodies For Each influence As Body In Bodies If target.Name <> influence.Name _ And target.Tag = 0 _ And influence.Tag = 0 Then target.xv -= aForce(target, influence, "x") / target.m target.yv -= aForce(target, influence, "y") / target.m target.zv -= aForce(target, influence, "z") / target.m End If Next For a As Integer = 0 To 8 target.Value(a).Text = SetValue(target, a + 1) Next Next Exit Sub Err: MsgBox(Err.Description, MsgBoxStyle.OkOnly) End Sub Sub MoveObjects() For Each target As Body In Bodies If target.Tag = 0 Then target.x += target.xv target.y += target.yv target.z += target.zv End If Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Select Case Timer1.Enabled Case True Timer1.Enabled = False WriteLog() Case False If Time = 0 Then If File.Exists(LogDirectory.Text & "" & LogFilename.Text & ".txt") = True Then If MsgBox("Log file already exists. Do you wish to overwrite it?", MsgBoxStyle.YesNo) = vbYes Then File.Delete(LogDirectory.Text & "" & LogFilename.Text & ".txt") Timer1.Tag = "Second,Body,Mass,Radius,x,y,z,xv,yv,zv" & vbCrLf LogPosition(0) Else Exit Sub End If End If End If Timer1.Enabled = True End Select End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick DeltaV() MoveObjects() Time += 1 If Time / Interval.Value = Int(Time / Interval.Value) Then LogPosition(Time) Me.Text = Format(Int(Time / 86400), "0") & " days " & Format(CType(Date.FromOADate(Time / 86400), Date), "HH:mm:ss") & " " & Time End Sub Sub Writelog() Dim sw As StreamWriter sw = File.AppendText(LogDirectory.Text & "" & LogFilename.Text & ".txt") sw.WriteLine(Timer1.Tag) Timer1.Tag = "" sw.Close() End Sub Sub LogPosition(ByVal Time As Long) For Each target As Body In Bodies Timer1.Tag = Timer1.Tag & ( _ Time & "," & _ target.Name & "," & _ target.m & "," & _ target.r & "," & _ target.x & "," & _ target.y & "," & _ target.z & "," & _ target.xv & "," _ & target.yv & _ "," & target.zv & vbCrLf) Next End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Button3_Click(sender, e) Time = 0 Me.Text = Format(Int(Time / 86400), "0") & " days " & Format(CType(Date.FromOADate(Time / 86400), Date), "HH:mm:ss") & " " & Time End Sub Sub CreateBody(ByVal Name As String) Dim a As Integer If AnyBodies = False Then ReDim Bodies(0) a = 0 AnyBodies = True Else a = Bodies.Length ReDim Preserve Bodies(a) End If Dim NewBody As New Body Bodies(a) = NewBody Me.Controls.Add(Bodies(a)) With Bodies(a) .Parent = Panel1 .Name = Name .Text = .Name .Left = 0 If a = 0 Then .Top = 0 Else .Top = Bodies(a - 1).Top + Bodies(a - 1).Height + 0 End If .Visible = True .AutoSize = True End With For b As Integer = 0 To 8 Dim NewField As New Parts Bodies(a).Field(B) = NewField Me.Controls.Add(Bodies(a).Field(B)) With Bodies(a).Field(B) .Parent = Bodies(a) .Left = 4 .Top = 14 + (b * 20) .Text = SetField(Bodies(a), b + 1) .Visible = True .Height = 18 .Width = 80 End With Dim NewValue As New Parts Bodies(a).Value(B) = NewValue Me.Controls.Add(Bodies(a).Value(B)) With Bodies(a).Value(B) .Parent = Bodies(a) .Left = Bodies(a).Field(B).Left + Bodies(a).Field(B).Width .Top = Bodies(a).Field(B).Top '.Text = SetValue(Bodies(a), b + 1) .Visible = True .Height = Bodies(a).Field(B).Height .Width = 100 End With Dim NewAlternate As New Alternates Bodies(a).Alternate(B) = NewAlternate Me.Controls.Add(Bodies(a).Alternate(B)) With Bodies(a).Alternate(B) .Parent = Bodies(a) .Left = Bodies(a).Value(B).Left + Bodies(a).Value(B).Width .Top = Bodies(a).Value(B).Top - 3 '.Text = SetValue(Bodies(a), b + 1) .Visible = True .Height = Bodies(a).Value(B).Height .Width = 100 End With Next End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim NewName As String = InputBox("Name of new Heavenly Body:") If NewName = "" Then Exit Sub ElseIf NewName.IndexOf(",") <> -1 Then MsgBox("Cannot have a comma in a name.") Exit Sub End If CreateBody(NewName) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim Scan(Bodies.Length, 11) As String Dim Scans As Integer = -1 For Each target As Body In Bodies Scans += 1 target.Tag = 0 For a As Integer = 0 To 8 If Trim(target.Alternate(a).Text) = "" Then Scan(Scans, a) = "" target.Tag += 1 Else Scan(Scans, a) = target.Alternate(a).Text End If Next Scan(Scans, 9) = target.Name Scan(Scans, 10) = target.Tag Next For Each target As Body In Bodies target.Dispose() Next AnyBodies = False For Create As Integer = 0 To Scans If Scan(Create, 10) < 9 Then CreateBody(Scan(Create, 9)) With Bodies(Bodies.Length - 1) .x = Num(Scan(Create, 0)) .y = Num(Scan(Create, 1)) .z = Num(Scan(Create, 2)) .r = Num(Scan(Create, 3)) .m = Num(Scan(Create, 4)) .xv = Num(Scan(Create, 5)) .yv = Num(Scan(Create, 6)) .zv = Num(Scan(Create, 7)) .Tag = Num(Scan(Create, 10)) For a As Integer = 0 To 8 .Value(a).Text = SetValue(Bodies(Bodies.Length - 1), a + 1) .Alternate(a).Text = Scan(Create, a) Next If .Tag > 0 Then .BackColor = Color.LightSalmon End If End With End If Next End Sub Function Num(ByVal Input As String) As Double If Trim(Input) = "" Then Return 0 Else Return Input End If End Function Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If Save1.ShowDialog() <> DialogResult.OK Then Exit Sub ' if you don't want to save it bail out now Else If File.Exists(Save1.FileName) Then File.Delete(Save1.FileName) ' If an existing file delete it Dim sw As StreamWriter ' open a writer sw = File.AppendText(Save1.FileName) ' prepare to write For Each target As Body In Bodies sw.WriteLine( _ target.Name & "," & _ target.x & "," & _ target.y & "," & _ target.z & "," & _ target.r & "," & _ target.m & "," & _ target.xv & "," & _ target.yv & "," & _ target.zv & ",") Next sw.Close() ' close the writer End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click If Open1.ShowDialog <> DialogResult.OK Then Exit Sub ' If not OKK to he dialog bail For Each target As Body In Bodies target.Dispose() Next AnyBodies = False LoadFile(Open1.FileName) End Sub End Class Public Class Body Inherits GroupBox Public x As Double Public y As Double Public z As Double Public m As Double Public r As Double Public xv As Double Public yv As Double Public zv As Double Public Field(8) As Parts Public Value(8) As Parts Public Alternate(8) As Alternates Function v() As Double Return Math.Sqrt((xv ^ 2) + (yv ^ 2) + (zv ^ 2)) End Function End Class Public Class Parts Inherits Label End Class Public Class Alternates Inherits TextBox End Class Quote
Jay-qu Posted November 5, 2007 Report Posted November 5, 2007 Well, here it is. Ugly and bloated, but functional. I need to step away from it for a while. Then I will add rockets, stages, and thrust vectors to the thing. For now you can do fun things like make a universe of two bowling balls 1 km apart and see how long it takes them to come together from their gravitational attraction. :hyper: BillMine wont run B) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.