Editing Lua Script for Orbit Stabilization

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
Lua script for chapter 2 of [[Go Play In Space]] by Bruce Irving, Andy McSorley, and Mark Paton for [[Orbiter|Orbiter Space Flight Simulator]].
 
  
 +
-- Lua script for chapter 2 of "Go Play in Space" - Orbit Stabilization
  
<pre>
 
-- Lua script for chapter 2 of "Go Play in Space" - Orbit Stabilization
 
 
--
 
--
 +
 
-- Author: David Murley
 
-- Author: David Murley
 +
 
-- Date: 7/01/2019
 
-- Date: 7/01/2019
 +
 
-- Version: 1.1  
 
-- Version: 1.1  
 +
 
--
 
--
 +
 
--  
 
--  
 +
  
 
term.out('Script invoked')
 
term.out('Script invoked')
 +
  
 
-- Get access to the Delta Gliders GL-01 and GL-02. With the interface handles
 
-- Get access to the Delta Gliders GL-01 and GL-02. With the interface handles
 +
 
-- obtained, access to various controls and flight data are acquired.
 
-- obtained, access to various controls and flight data are acquired.
 +
  
  
 
hGL1=vessel.get_interface('GL-01')
 
hGL1=vessel.get_interface('GL-01')
 +
 
hGL2=vessel.get_interface('GL-02')
 
hGL2=vessel.get_interface('GL-02')
 +
  
 
-- Wait until vessels are docked before continuing with script
 
-- Wait until vessels are docked before continuing with script
 +
  
  
 
term.out ('Waiting until vessels are docked before')
 
term.out ('Waiting until vessels are docked before')
 +
 
term.out ('  executing remainder of script')
 
term.out ('  executing remainder of script')
 +
 
continue = true
 
continue = true
 +
 
hDckPort = hGL1:get_dockhandle(0)
 
hDckPort = hGL1:get_dockhandle(0)
 +
 +
continue=true
 +
 
while continue do
 
while continue do
hDckStatus=hGL1:get_dockstatus(hDckPort)
+
 
 +
  hDckStatus=hGL1:get_dockstatus(hDckPort)
 +
 
 
   if hDckStatus ~= nil then
 
   if hDckStatus ~= nil then
 +
 
     continue = false
 
     continue = false
 +
 
   else
 
   else
 +
 
     proc.wait_simdt(5)
 
     proc.wait_simdt(5)
 +
 
   end
 
   end
 +
 
end
 
end
 +
 
    
 
    
 
-- Kill Rotation
 
-- Kill Rotation
 +
  
 
term.out('Kill Rotation')
 
term.out('Kill Rotation')
 +
 
hGL1:set_navmode(NAVMODE.KILLROT)
 
hGL1:set_navmode(NAVMODE.KILLROT)
 +
 
proc.wait_simdt(10)
 
proc.wait_simdt(10)
 +
  
 
-- Undock
 
-- Undock
 +
  
 
term.out('Undock')
 
term.out('Undock')
 +
 
hGL1:undock(ALLDOCKS)
 
hGL1:undock(ALLDOCKS)
 +
  
 
-- Set RCS mode on GL-01 to Translation
 
-- Set RCS mode on GL-01 to Translation
 +
  
 
term.out('Set RCS mode to translate.')
 
term.out('Set RCS mode to translate.')
 +
 
hGL1:set_rcsmode(RCSMODE.LIN)
 
hGL1:set_rcsmode(RCSMODE.LIN)
 +
  
 
-- Thrust away from GL-02. The resulting distance from GL-02 is about 35 meters.
 
-- Thrust away from GL-02. The resulting distance from GL-02 is about 35 meters.
 +
  
 
term.out('Separation of GL-01 and GL-02 to +/-35 meters')
 
term.out('Separation of GL-01 and GL-02 to +/-35 meters')
 +
 
-- oapi.set_tacc(10)
 
-- oapi.set_tacc(10)
 +
 
thrstGrpHdl1=hGL1:get_thrustergrouphandle(THGROUP.ATT_BACK)
 
thrstGrpHdl1=hGL1:get_thrustergrouphandle(THGROUP.ATT_BACK)
 +
 
hGL1:set_thrustergrouplevel(THGROUP.ATT_BACK,.1)
 
hGL1:set_thrustergrouplevel(THGROUP.ATT_BACK,.1)
 +
 
proc.wait_simdt(11.237)
 
proc.wait_simdt(11.237)
 +
 
hGL1:set_thrustergrouplevel(THGROUP.ATT_BACK,0)
 
hGL1:set_thrustergrouplevel(THGROUP.ATT_BACK,0)
 +
 
proc.wait_simdt(52.777)
 
proc.wait_simdt(52.777)
 +
 
thrstGrpHdl2=hGL1:get_thrustergrouphandle(THGROUP.ATT_FORWARD)
 
thrstGrpHdl2=hGL1:get_thrustergrouphandle(THGROUP.ATT_FORWARD)
 +
 
hGL1:set_thrustergrouplevel(THGROUP.ATT_FORWARD,.1)
 
hGL1:set_thrustergrouplevel(THGROUP.ATT_FORWARD,.1)
 +
 
proc.wait_simdt(18.733)
 
proc.wait_simdt(18.733)
 +
 
hGL1:set_thrustergrouplevel(THGROUP.ATT_FORWARD,0)
 
hGL1:set_thrustergrouplevel(THGROUP.ATT_FORWARD,0)
 +
 
-- oapi.set_tacc(1)
 
-- oapi.set_tacc(1)
 +
 
term.out('Separation completed.')
 
term.out('Separation completed.')
 +
  
 
-- Set the prograde autopilot for both vessels to on.
 
-- Set the prograde autopilot for both vessels to on.
 +
  
 
term.out('Set prograde autopilot for both vessels.')
 
term.out('Set prograde autopilot for both vessels.')
 +
 
hGL1:set_navmode(NAVMODE.PROGRADE)
 
hGL1:set_navmode(NAVMODE.PROGRADE)
 +
 
hGL2:set_navmode(NAVMODE.PROGRADE)
 
hGL2:set_navmode(NAVMODE.PROGRADE)
proc.wait_simdt(30)
+
 
 +
proc.wait_simdt(25)
 +
 
  
 
-- The following 14 lines set up the annotations that are used to display
 
-- The following 14 lines set up the annotations that are used to display
 +
 
-- time to apoapsis for both vessels
 
-- time to apoapsis for both vessels
 +
  
 
hApT1Label = oapi.create_annotation()
 
hApT1Label = oapi.create_annotation()
 +
 
hApT1Label:set_pos(0.7,0.7,1,1)
 
hApT1Label:set_pos(0.7,0.7,1,1)
 +
 
hApT1Label:set_colour({r=1, g=0.7, b=0.3})
 
hApT1Label:set_colour({r=1, g=0.7, b=0.3})
 +
 
hApT1Label:set_text ('ApT (GL-01): ')
 
hApT1Label:set_text ('ApT (GL-01): ')
 +
  
 
hApT1 = oapi.create_annotation()
 
hApT1 = oapi.create_annotation()
 +
 
hApT1:set_pos(0.8,0.7,1,1)
 
hApT1:set_pos(0.8,0.7,1,1)
 +
 
hApT1:set_colour({r=1, g=0.7, b=0.3})
 
hApT1:set_colour({r=1, g=0.7, b=0.3})
 +
  
 
hApT2Label = oapi.create_annotation()
 
hApT2Label = oapi.create_annotation()
 +
 
hApT2Label:set_pos(0.7,0.75,1,1)
 
hApT2Label:set_pos(0.7,0.75,1,1)
 +
 
hApT2Label:set_colour({r=1, g=0.7, b=0.3})
 
hApT2Label:set_colour({r=1, g=0.7, b=0.3})
 +
 
hApT2Label:set_text ('ApT (GL-02): ')
 
hApT2Label:set_text ('ApT (GL-02): ')
 +
 +
  
 
hApT2 = oapi.create_annotation()
 
hApT2 = oapi.create_annotation()
 +
 
hApT2:set_pos(0.8,0.75,1,1)
 
hApT2:set_pos(0.8,0.75,1,1)
 +
 
hApT2:set_colour({r=1, g=0.7, b=0.3})
 
hApT2:set_colour({r=1, g=0.7, b=0.3})
 +
  
 
-- Wait until +/- 20 seconds before apoapsis, then slow time acceleration to 1x.
 
-- Wait until +/- 20 seconds before apoapsis, then slow time acceleration to 1x.
 +
 
-- Ignition of main engines on both vessels occurs around +/- 10 seconds before  
 
-- Ignition of main engines on both vessels occurs around +/- 10 seconds before  
 +
 
-- apoapsis. Time acceleration during the waiting period is set to 100x to
 
-- apoapsis. Time acceleration during the waiting period is set to 100x to
 +
 
-- reduce waiting time for those who are easily bored.
 
-- reduce waiting time for those who are easily bored.
 +
  
 
term.out ('Wait until +/- 10 seconds from aoapis. Then fire')
 
term.out ('Wait until +/- 10 seconds from aoapis. Then fire')
 +
 
term.out ('  main engines to stabilize orbit')
 
term.out ('  main engines to stabilize orbit')
 +
 
oapi.set_tacc(100)
 
oapi.set_tacc(100)
 +
 
continue = true
 
continue = true
 +
 
while continue do
 
while continue do
 +
 
   el,op = hGL1:get_elementsex()
 
   el,op = hGL1:get_elementsex()
 +
 
   TimeToApoapsis= op.ApT
 
   TimeToApoapsis= op.ApT
 +
 
   hApT1:set_text(TimeToApoapsis)
 
   hApT1:set_text(TimeToApoapsis)
 +
 
   el,op=hGL2:get_elementsex()
 
   el,op=hGL2:get_elementsex()
 +
 
   TimeToAposis=op.ApT
 
   TimeToAposis=op.ApT
 +
 
   hApT2:set_text(TimeToApoapsis)
 
   hApT2:set_text(TimeToApoapsis)
 +
 
   if TimeToApoapsis < 20 then
 
   if TimeToApoapsis < 20 then
 +
 
     continue=false
 
     continue=false
 +
 
   end
 
   end
 +
 
   proc.wait_simdt(1)
 
   proc.wait_simdt(1)
 +
 
end
 
end
 +
 
oapi.set_tacc(1)
 
oapi.set_tacc(1)
 +
  
  
 
-- Track time to apoapsis from time=+/-20 sec in 1x time.
 
-- Track time to apoapsis from time=+/-20 sec in 1x time.
 +
  
 
continue=true
 
continue=true
 +
 
while continue do
 
while continue do
 +
 
   el,op = hGL1:get_elementsex()
 
   el,op = hGL1:get_elementsex()
 +
 
   TimeToApoapsis1 =op.ApT
 
   TimeToApoapsis1 =op.ApT
 +
 
   hApT1:set_text(TimeToApoapsis1)
 
   hApT1:set_text(TimeToApoapsis1)
 +
 
   el,op = hGL2:get_elementsex()
 
   el,op = hGL2:get_elementsex()
 +
 
   TimeToApoapsis2=op.ApT
 
   TimeToApoapsis2=op.ApT
 +
 
   hApT2:set_text(TimeToApoapsis2)
 
   hApT2:set_text(TimeToApoapsis2)
 +
 
   if TimeToApoapsis1 <= 10 then
 
   if TimeToApoapsis1 <= 10 then
 +
 
     continue=false
 
     continue=false
 +
 
     oapi.del_annotation(hApT1)
 
     oapi.del_annotation(hApT1)
 +
 
     oapi.del_annotation(hApT1Label)
 
     oapi.del_annotation(hApT1Label)
 +
 
     oapi.del_annotation(hApT2)
 
     oapi.del_annotation(hApT2)
 +
 
     oapi.del_annotation(hApT2Label)
 
     oapi.del_annotation(hApT2Label)
 +
 
   else
 
   else
 +
 
     proc.wait_simdt(1)
 
     proc.wait_simdt(1)
 +
 
   end
 
   end
 +
 
end
 
end
 +
  
 
-- Set up annotations to show orbit eccentricities
 
-- Set up annotations to show orbit eccentricities
 +
  
 
hEcc1Label = oapi.create_annotation()
 
hEcc1Label = oapi.create_annotation()
 +
 
hEcc1Label:set_pos(0.7,0.7,1,1)
 
hEcc1Label:set_pos(0.7,0.7,1,1)
 +
 
hEcc1Label:set_colour({r=1, g=0.7, b=0.3})
 
hEcc1Label:set_colour({r=1, g=0.7, b=0.3})
 +
 
hEcc1Label:set_text ('Ecc (GL-01): ')
 
hEcc1Label:set_text ('Ecc (GL-01): ')
 +
  
 
hEcc1 = oapi.create_annotation()
 
hEcc1 = oapi.create_annotation()
 +
 
hEcc1:set_pos(0.8,0.7,1,1)
 
hEcc1:set_pos(0.8,0.7,1,1)
 +
 
hEcc1:set_colour({r=1, g=0.7, b=0.3})
 
hEcc1:set_colour({r=1, g=0.7, b=0.3})
 +
 +
  
 
hEcc2Label = oapi.create_annotation()
 
hEcc2Label = oapi.create_annotation()
 +
 
hEcc2Label:set_pos(0.7,0.75,1,1)
 
hEcc2Label:set_pos(0.7,0.75,1,1)
 +
 
hEcc2Label:set_colour({r=1, g=0.7, b=0.3})
 
hEcc2Label:set_colour({r=1, g=0.7, b=0.3})
 +
 
hEcc2Label:set_text ('Ecc (GL-02): ')
 
hEcc2Label:set_text ('Ecc (GL-02): ')
 +
  
 
hEcc2 = oapi.create_annotation()
 
hEcc2 = oapi.create_annotation()
 +
 
hEcc2:set_pos(0.8,0.75,1,1)
 
hEcc2:set_pos(0.8,0.75,1,1)
 +
 
hEcc2:set_colour({r=1, g=0.7, b=0.3})
 
hEcc2:set_colour({r=1, g=0.7, b=0.3})
 +
  
 
-- Stabilize orbits
 
-- Stabilize orbits
 +
  
 
term.out('Start Stabilization of Orbits')
 
term.out('Start Stabilization of Orbits')
 +
 
hGL1:set_thrustergrouplevel(THGROUP.MAIN, 1)
 
hGL1:set_thrustergrouplevel(THGROUP.MAIN, 1)
 +
 
hGL2:set_thrustergrouplevel(THGROUP.MAIN, 1)
 
hGL2:set_thrustergrouplevel(THGROUP.MAIN, 1)
 +
 +
 
continue1=true
 
continue1=true
 +
 
continue2 = true
 
continue2 = true
 +
 
while continue1 or continue2 do
 
while continue1 or continue2 do
 +
 
   el=hGL1:get_elements()
 
   el=hGL1:get_elements()
 +
 
   e1 = el.e
 
   e1 = el.e
 +
 
   hEcc1:set_text(e1)
 
   hEcc1:set_text(e1)
 +
 
   if e1 <= .005 then
 
   if e1 <= .005 then
 
     hGL1:set_thrustergrouplevel (THGROUP.MAIN, 0)
 
     hGL1:set_thrustergrouplevel (THGROUP.MAIN, 0)
 +
 
     continue1 = false
 
     continue1 = false
 +
 
   end  
 
   end  
 +
 
   el = hGL2:get_elements()
 
   el = hGL2:get_elements()
 +
 
   e2 = el.e
 
   e2 = el.e
 +
 
   hEcc2:set_text(e2)
 
   hEcc2:set_text(e2)
 +
 
   if e2 <= .005 then
 
   if e2 <= .005 then
 +
 
     hGL2:set_thrustergrouplevel (THGROUP.MAIN, 0)
 
     hGL2:set_thrustergrouplevel (THGROUP.MAIN, 0)
 +
 
     continue2 = false
 
     continue2 = false
 +
 
   end
 
   end
 +
 
   proc.wait_simdt(1)
 
   proc.wait_simdt(1)
 +
 
end
 
end
 +
 
term.out ('Orbits stabilized.')
 
term.out ('Orbits stabilized.')
 +
 
term.out ('')
 
term.out ('')
 +
 
term.out ('')
 
term.out ('')
 +
  
 
-- Wait a few seconds and then delete eccentricity annotations
 
-- Wait a few seconds and then delete eccentricity annotations
 +
  
 
proc.wait_simdt(10)
 
proc.wait_simdt(10)
 +
 
oapi.del_annotation(hEcc1)
 
oapi.del_annotation(hEcc1)
 +
 
oapi.del_annotation(hEcc1Label)
 
oapi.del_annotation(hEcc1Label)
 +
 
oapi.del_annotation(hEcc2)
 
oapi.del_annotation(hEcc2)
 +
 
oapi.del_annotation(hEcc2Label)
 
oapi.del_annotation(hEcc2Label)
 +
 
    
 
    
  
  
 
term.out ('End Script')
 
term.out ('End Script')
</pre>
 
 
[[Category: Articles]]
 
[[Category: Lua]]
 

Please note that all contributions to OrbiterWiki are considered to be released under the GNU Free Documentation License 1.2 (see OrbiterWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)