So what do I need to do to make orbiter automatically respond to buttons and automatically generate animationLUA works well for things like ascent scripts. That's the way Martins originally used it, as an ascent program computer for Space Shuttle Atlantis.
Based on the docs Lua was supposed to be able to do everything, including keypresses, complete ship parameter definition, etc.LUA works well for things like ascent scripts. That's the way Martins originally used it, as an ascent program computer for Space Shuttle Atlantis.
Yes, I want to know how to realize the function of automatic retraction and retraction of landing gear in the module of making spaceship with C + +Based on the docs Lua was supposed to be able to do everything, including keypresses, complete ship parameter definition, etc.
The problem is that the interpreter is incomplete. At least keyboard and landing point functions aren't implemented.
Regarding the OP's question besides C++ you can use VesselBuilder.
For a simple "press key - animation + change parameter" situation VesselBuilder is enough.
set_gear_state(up)
, set_gear_state(down)
& get_gear_state()
methods available.get_status()
rsp. set_status()
are enough to work with.set_gear_state(...)
or get_gear_state()
methods as not every vessel has a landing-gear!V:Gear(UP)
would work)!Last time I messed with LUA (years ago) it wasn't possible. I gave up on it because of that; implementation is incomplete.
You can do this by using the v:send_bufferedkey(keycode) method which is described in the section Orbiter Scripting→Reference→Class methods→Vessel methods in the Orbiter.chm file, which is located in the html folder of your Orbiter installation.I want to set in the script file of orbiter2016 to automatically press a button at a certain moment so that the spacecraft can make corresponding animations.
BEGIN_OrbiterSound
SENDVESSELKEY T:10 Key:OAPI_KEY_G Vessel:GL-01
END
v = vessel.get_interface('GL-01')
goals = 0
while goals < 1 do
simt = oapi.get_simtime()
proc.skip()
if simt > 10 then goals = 1 end
if goals > 0 then end
end
v:send_bufferedkey(OAPI_KEY.G)
v = vessel.get_interface('GL-01')
goals = 0
while goals < 1 do
alt = v:get_altitude(ALTMODE.GROUND)
proc.skip()
if alt > 10 then goals = 1 end
if goals > 0 then end
end
v:send_bufferedkey(OAPI_KEY.G)
Thank you very much for your detailed methods, let me learn a lotI am pretty sure that the v:send_bufferedkey(keycode) method has existed ever since lua scripts were introduced in Orbiter back in the 2010 version. This does exactly what the OP is asking. Perhaps you are confusing it with a "wait for keypress" method, which is true that it doesn't currently exist.
To answer the original question:
You can do this by using the v:send_bufferedkey(keycode) method which is described in the section Orbiter Scripting→Reference→Class methods→Vessel methods in the Orbiter.chm file, which is located in the html folder of your Orbiter installation.
Outside of lua, you can send keypresses to a vessel through a scenario command, if you have DanSteph's OrbiterSound 5.0 installed. Look for more information in the ScenarioCommandsHelp.txt file, located in the Doc\OrbiterSound Documentation\bin folder of your Orbiter installation with OrbiterSound 5.0
To my knowledge, apart from Vesselbuilder (already mentioned in this thread), these are the two methods you can use to send a keypress to a spacecraft in Orbiter, that rely on editing simple text files (.lua and .scn).
Here is an example of sending a keypress through an OrbiterSound 5.0 scenario command:
(The following goes into your scenario file, before the BEGIN_SHIPS ... END_SHIPS section).
Code:BEGIN_OrbiterSound SENDVESSELKEY T:10 Key:OAPI_KEY_G Vessel:GL-01 END
This will press the "G" key for the vessel with the name "GL-01" 10 seconds after the scenario starts.
Scenario commands are limited in the way they can be triggered, as the only input they use is time, measured in either seconds passed since the start of the scenario, or seconds passed since the last command was issued.
A lua script is much more versatile in this regard as you can use a vast number of triggers from the existing lua functions. Here is an example of a lua script that will perform the same task as the previous example (press the "G" key for the vessel with the name "GL-01" 10 seconds after the scenario starts. )
Code:v = vessel.get_interface('GL-01') goals = 0 while goals < 1 do simt = oapi.get_simtime() proc.skip() if simt > 10 then goals = 1 end if goals > 0 then end end v:send_bufferedkey(OAPI_KEY.G)
Any number of triggers can be used to achieve the same goal. This next example presses the G key for the vessel named "GL-01" when it reaches an altitude of 10 meters above ground.
Code:v = vessel.get_interface('GL-01') goals = 0 while goals < 1 do alt = v:get_altitude(ALTMODE.GROUND) proc.skip() if alt > 10 then goals = 1 end if goals > 0 then end end v:send_bufferedkey(OAPI_KEY.G)
Hope this helps,
Thank you very much for your kind answerC++ is different from LUA, it is the native language in which Orbiter is coded. But there's no specific function like 'retract landing gear'. You'll have to define one, or probably a sequence of animations. Then you can have it triggered by a key or key combo, and implement it in a physical way (the ground contact points of the vessel should change).
Look for APIGuide in the SDK/doc folder, Martins takes a landing gear animation as an example. You also have a chm 'help' file that reference all the functions and classes.
If you never used C++ before, don't be shy and go install MS Visual Studio (2017 or 2019), I'm the living proof you don't need a computer science background for that. It's a fine hobby. There are tutorials specific to Orbiter all over the Forums, even on YouTube, and I and others will be happy to help you.
Hello, I want to ask if I can get the longitude and latitude of the spaceship in Lua and display it directly through anotationI am pretty sure that the v:send_bufferedkey(keycode) method has existed ever since lua scripts were introduced in Orbiter back in the 2010 version. This does exactly what the OP is asking. Perhaps you are confusing it with a "wait for keypress" method, which is true that it doesn't currently exist.
To answer the original question:
You can do this by using the v:send_bufferedkey(keycode) method which is described in the section Orbiter Scripting→Reference→Class methods→Vessel methods in the Orbiter.chm file, which is located in the html folder of your Orbiter installation.
Outside of lua, you can send keypresses to a vessel through a scenario command, if you have DanSteph's OrbiterSound 5.0 installed. Look for more information in the ScenarioCommandsHelp.txt file, located in the Doc\OrbiterSound Documentation\bin folder of your Orbiter installation with OrbiterSound 5.0
To my knowledge, apart from Vesselbuilder (already mentioned in this thread), these are the two methods you can use to send a keypress to a spacecraft in Orbiter, that rely on editing simple text files (.lua and .scn).
Here is an example of sending a keypress through an OrbiterSound 5.0 scenario command:
(The following goes into your scenario file, before the BEGIN_SHIPS ... END_SHIPS section).
Code:BEGIN_OrbiterSound SENDVESSELKEY T:10 Key:OAPI_KEY_G Vessel:GL-01 END
This will press the "G" key for the vessel with the name "GL-01" 10 seconds after the scenario starts.
Scenario commands are limited in the way they can be triggered, as the only input they use is time, measured in either seconds passed since the start of the scenario, or seconds passed since the last command was issued.
A lua script is much more versatile in this regard as you can use a vast number of triggers from the existing lua functions. Here is an example of a lua script that will perform the same task as the previous example (press the "G" key for the vessel with the name "GL-01" 10 seconds after the scenario starts. )
Code:v = vessel.get_interface('GL-01') goals = 0 while goals < 1 do simt = oapi.get_simtime() proc.skip() if simt > 10 then goals = 1 end if goals > 0 then end end v:send_bufferedkey(OAPI_KEY.G)
Any number of triggers can be used to achieve the same goal. This next example presses the G key for the vessel named "GL-01" when it reaches an altitude of 10 meters above ground.
Code:v = vessel.get_interface('GL-01') goals = 0 while goals < 1 do alt = v:get_altitude(ALTMODE.GROUND) proc.skip() if alt > 10 then goals = 1 end if goals > 0 then end end v:send_bufferedkey(OAPI_KEY.G)
Hope this helps,
-- ---------------------------------------------------------------------------
-- Some useful general constants
-- ---------------------------------------------------------------------------
PI=3.14159265358979 -- pi
PI05=1.57079632679490 -- pi/2
RAD=PI/180.0 -- deg->rad conversion factor
DEG=180.0/PI -- rad->deg conversion factor
-- ---------------------------------------------------------------------------
-- ANNOTATION SETUP
-- ---------------------------------------------------------------------------
-- re-use 1st 'old' annotation object (if available)
note = oapi.get_annotations() or oapi.create_annotation()
note:set_pos (0.2,0.1,0.8,0.9);
note:set_size(0.5)
note:set_colour ({r=0.7,g=0.8,b=1})
-- ---------------------------------------------------------------------------
-- Monitor background task
-- (does not terminate. Run as background job and kill when done)
-- ---------------------------------------------------------------------------
function monitor_range()
while true do
v = vessel.get_focusinterface()
if v ~= nil then
hobj = v:get_surfaceref()
equ = oapi.global_to_equ (hobj, v:get_globalpos())
name = v:get_name()
lng = equ.lng *DEG
lat = equ.lat *DEG
note:set_text( string.format("lon: %.3f lat: %.3f [%s]", lng, lat, name))
else
note:set_text( "lon: n/a lat: n/a [n/a]" )
end
proc.wait_sysdt(0.1) -- 100ms refresh rate
end
end
-- ---------------------------------------------------------------------------
-- MAIN
-- ---------------------------------------------------------------------------
-- Launch monitor process
proc_id = proc.bg(monitor_range)
-- proc.kill(proc_id)
Thank youSomething like this would do the job:
SQL:-- --------------------------------------------------------------------------- -- Some useful general constants -- --------------------------------------------------------------------------- PI=3.14159265358979 -- pi PI05=1.57079632679490 -- pi/2 RAD=PI/180.0 -- deg->rad conversion factor DEG=180.0/PI -- rad->deg conversion factor -- --------------------------------------------------------------------------- -- ANNOTATION SETUP -- --------------------------------------------------------------------------- -- re-use 1st 'old' annotation object (if available) note = oapi.get_annotations() or oapi.create_annotation() note:set_pos (0.2,0.1,0.8,0.9); note:set_size(0.5) note:set_colour ({r=0.7,g=0.8,b=1}) -- --------------------------------------------------------------------------- -- Monitor background task -- (does not terminate. Run as background job and kill when done) -- --------------------------------------------------------------------------- function monitor_range() while true do v = vessel.get_focusinterface() if v ~= nil then hobj = v:get_surfaceref() equ = oapi.global_to_equ (hobj, v:get_globalpos()) name = v:get_name() lng = equ.lng *DEG lat = equ.lat *DEG note:set_text( string.format("lon: %.3f lat: %.3f [%s]", lng, lat, name)) else note:set_text( "lon: n/a lat: n/a [n/a]" ) end proc.wait_sysdt(0.1) -- 100ms refresh rate end end -- --------------------------------------------------------------------------- -- MAIN -- --------------------------------------------------------------------------- -- Launch monitor process proc_id = proc.bg(monitor_range) -- proc.kill(proc_id)
I think you know how to start Lua scripts in Orbiter, do you?
In case you like to quickly see what the script is doing, I've attached a "full package" for easy "runTheScenarioAndTakeALook"[TM]
Hi, I have downloaded the Audio of STS-129 Shuttle Atlantis launch. Which is about 10min,28sec long. Liftoff, is just after the 1min, is there perhaps a way I can start the sim or setup the sim to start liftoff of the Shuttle at that 1min mark, or to start lift off at the exact time frame. After pressing the Launch on the auto pilot? Or can I set the auto pilot to do everything?I am pretty sure that the v:send_bufferedkey(keycode) method has existed ever since lua scripts were introduced in Orbiter back in the 2010 version. This does exactly what the OP is asking. Perhaps you are confusing it with a "wait for keypress" method, which is true that it doesn't currently exist.
To answer the original question:
You can do this by using the v:send_bufferedkey(keycode) method which is described in the section Orbiter Scripting→Reference→Class methods→Vessel methods in the Orbiter.chm file, which is located in the html folder of your Orbiter installation.
Outside of lua, you can send keypresses to a vessel through a scenario command, if you have DanSteph's OrbiterSound 5.0 installed. Look for more information in the ScenarioCommandsHelp.txt file, located in the Doc\OrbiterSound Documentation\bin folder of your Orbiter installation with OrbiterSound 5.0
To my knowledge, apart from Vesselbuilder (already mentioned in this thread), these are the two methods you can use to send a keypress to a spacecraft in Orbiter, that rely on editing simple text files (.lua and .scn).
Here is an example of sending a keypress through an OrbiterSound 5.0 scenario command:
(The following goes into your scenario file, before the BEGIN_SHIPS ... END_SHIPS section).
Code:BEGIN_OrbiterSound SENDVESSELKEY T:10 Key:OAPI_KEY_G Vessel:GL-01 END
This will press the "G" key for the vessel with the name "GL-01" 10 seconds after the scenario starts.
Scenario commands are limited in the way they can be triggered, as the only input they use is time, measured in either seconds passed since the start of the scenario, or seconds passed since the last command was issued.
A lua script is much more versatile in this regard as you can use a vast number of triggers from the existing lua functions. Here is an example of a lua script that will perform the same task as the previous example (press the "G" key for the vessel with the name "GL-01" 10 seconds after the scenario starts. )
Code:v = vessel.get_interface('GL-01') goals = 0 while goals < 1 do simt = oapi.get_simtime() proc.skip() if simt > 10 then goals = 1 end if goals > 0 then end end v:send_bufferedkey(OAPI_KEY.G)
Any number of triggers can be used to achieve the same goal. This next example presses the G key for the vessel named "GL-01" when it reaches an altitude of 10 meters above ground.
Code:v = vessel.get_interface('GL-01') goals = 0 while goals < 1 do alt = v:get_altitude(ALTMODE.GROUND) proc.skip() if alt > 10 then goals = 1 end if goals > 0 then end end v:send_bufferedkey(OAPI_KEY.G)
Hope this helps,