Orbiter BETA Lua development

Ripley

Tutorial translator
Donator
Joined
Sep 12, 2010
Messages
2,960
Reaction score
191
Points
78
Location
Rome
Website
www.tuttovola.org
Looking forward to your comeback BEEP.
Hope everything will work out for the best, Godspeed.
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
1,665
Reaction score
192
Points
63
No problem.
Handle your real life first; Orbiter comes 2nd.
 

Face

Addon Developer
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,228
Reaction score
182
Points
103
Location
Vienna
The pack of Post 45 should be self-contained.

Sorry for the long delay, somehow I've totally forgot that over the holidays and the stressy first weeks this year.

I've tried the pack referenced and it works as it should on beta r73 with MOGE. I.e. I see the building's chimney smoking.
 

BEEP

Addon Developer
Addon Developer
Joined
Apr 5, 2008
Messages
150
Reaction score
9
Points
18
Thanks everybody for the kind words. Things are developing exceptionally well and I expect to be home again next week. Orbiter comes in 2nd but is a close 2nd to me and I hope I'll have some time left to employ in this magnific mind adventure. Rate will be slower but it will go on.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,834
Reaction score
90
Points
123
Location
Cape
Go take care of priorities in your life. We'll be here when you back.:thumbup:
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
1,665
Reaction score
192
Points
63
LuaScriptPlus DLLs (for Orbiter 2016)

I've uploaded versions for Orbiter 2016 (see attachments in first post of this thread).
One ZIP containing the sources and the other the DLLs.

You may now try those Lua extensions for Orbiter 2016.
Note, that the contents of the ZIP will overwrite your files, so you might like to backup those before they get overwritten.
I've tried to link those statically with the runtime, so hopefully they work just by unzipping it.

The test scenario (\Scenarios\Tests\undock_test.scn) is a starting point to run the test script.
As Orbiter 2016 does not have the "automatic Lua script start from scenario" feature, you have to run/start that manually.
At the LuaConsole type:
Code:
run('test/undock_test')

Have fun (if it works for you, else please report back)
 
Last edited:

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
1,665
Reaction score
192
Points
63
LuaScript 2019-07-11.zip

I've uploaded a new ZIP[1], that is functionality-wise basically the same as the previous ZIP[2] but the directory layout has been adopted to the latest Orbiter BETA (r85++) layout and some LDoc documentation fixes were added.

As no functional change is done, the DLL package [3] is still valid.

The ZIP contains only files that differ from the HEAD revision (r87) of Orbiter BETA repository, to make it easer to spot the changes.

This is mainly a way to provide Martin a small help while he's doing more important stuff :thumbup:


[1] LuaScript 2019-07-11.zip ...available at the first post.
[2] LuaScript 2017-12-08.zip
[3] LuaScript 2017-12-07(dlls).zip


Here's a detailed list of changes (against Orbiter BETA r87):

-------------------------------------------------------------------------------
term.clear() additions.
- LuaConsole\ConsoleInterpreter.cpp
- LuaConsole\ConsoleInterpreter.h
- LuaConsole\LuaConsole.cpp
- LuaConsole\LuaConsole.h
- LuaMFD\MfdInterpreter.cpp

unreachable code from ConsoleConfig::Description removed.
- LuaConsole\ConsoleCfg.cpp

[Del], [End] and [Pos1] key handling.
- LuaConsole\LuaConsole.cpp

Doc fix (missing full stop for LDoc).
- LuaInterpreter\Interpreter.cpp
- LuaInterpreter\lua_vessel_mtd.cpp

Doc fix (parameter names were missing).
- LuaInterpreter\lua_vessel_mtd.cpp
-------------------------------------------------------------------------------


or the other way around (what files have what changes):

-------------------------------------------------------------------------------
LuaConsole\ConsoleCfg.cpp
- unreachable code from ConsoleConfig::Description removed

LuaConsole\ConsoleInterpreter.cpp
- term.clear() additions.

LuaConsole\ConsoleInterpreter.h
- term.clear() additions.

LuaConsole\LuaConsole.cpp
- term.clear() additions.
- [Del], [End] and [Pos1] key handling.

LuaConsole\LuaConsole.h
- term.clear() additions.

LuaMFD\MfdInterpreter.cpp
- term.clear() additions.

LuaInterpreter\Interpreter.cpp
- doc fix for Interpreter::eek:api_set_tacc (missing full stop for LDoc)
- leaner loop iterator at Interpreter::eek:apiGetAnnotations (no functional change)

LuaInterpreter\lua_vessel_mtd.cpp
- doc fix for Interpreter::v_add_force (parameter names were missing)
- doc fix for Interpreter::v_register_animation (missing full stop for LDoc)
-------------------------------------------------------------------------------
 

xjflcf520

Member
Joined
Feb 26, 2021
Messages
61
Reaction score
5
Points
23
Location
Chana
Finally here's the Lua (sub-)Forum!

My current progress and questions regarding the Orbiter Lua API will be posted here.

I will update this 1st post with the current state, as soon as it changed.
New items (since last edit of this post) will be marked green

The attached file represents the current "work in progress" and might still contain some "todo"s.
The attached ZIP contains only files with changes to keep the ZIP-size small.

Almost all the added functions in the current ZIP (2017-12-08) have documentation.
Some of the documentation might not fit the 'LDoc-rules', 'cause I haven't installed LDoc.

The latest update (LuaScript 2019-07-11.zip) only contained documentation changes and a re-layout of the source file locations, therefore no new DLL package was uploaded.

2019-07-11: New source ZIP added, DLL package added
2019-07-08: As per request I've added builds (and sources) for Orbiter 2016, too
2019-07-11: New source ZIP added

For the time being, here are some documentation snippets/hints/details here.

Current status:

Terminal:
- term.clear()

OAPI:
  • oapi_get_orbiter_version()
  • oapi_get_viewport_size()
  • oapi_rand()
  • oapi_getcolor()
  • oapi.get_annotations()

Vessel-API:
  • get_COG_elev()
  • get_touchdownpointcount()
  • get_touchdownpoints()
  • set_touchdownpoints()
  • get_clipradius()
  • set_albedoRGB()
  • set_clipradius()
  • set_surfacefrictioncoeff()
  • get_status()
  • defset_status()
  • get_angularacc()
  • get_linearmoment()
  • get_angularmoment()
  • get_globalorientation()
  • set_globalorientation()
  • is_orbitstabilised()
  • is_nonsphericalgravityenabled()
  • get_surfaceelevation()
  • get_surfacenormal()
  • get_smi()
  • get_argper()
  • get_pedist()
  • get_apdist()
  • toggle_navmode()
  • toggle_rcsmode()
  • get_hoverholdaltitude()
  • set_hoverholdaltitude()
  • version()
  • get_dragvector()
  • get_forcevector()
  • get_torquevector()
  • add_force()
  • edit_airfoil()
  • dockingstatus()
  • get_animation()
  • del_animationcomponent()
  • register_animation()
  • unregister_animation()
  • set_cameradefaultdirection()
  • get_cameradefaultdirection()
  • set_cameracatchangle()
  • set_camerarotationrange()
  • set_camerashiftrange()
  • set_cameramovement()
[/COLOR]
// coordinate transformations
  • shift_centreofmass()
  • shiftCG()
  • get_superstructureCG()
  • get_rotationmatrix()
  • set_rotationmatrix()
  • globalrot()
  • horizonrot()
  • horizoninvrot()
  • local2global()
  • global2local()
  • local2rel()
  • set_thrusterlevel_singlestep()
// Nosewheel-steering and wheel brakes
  • set_nosewheelsteering()
  • get_nosewheelsteering()
  • set_maxwheelbrakeforce()
  • set_wheelbrakelevel()
  • get_wheelbrakelevel()
// Instrument panel and virtual cockpit methods
  • trigger_panelredrawarea()
  • trigger_redrawarea()


Documentation details:

term.clear() :
This method clears the terminal window.

get_touchdownpoints :
This method uses a polymorphic approach.
If the function is called without any parameter, it will return three vectors representing the three touchdownpoints as per the "old" API.
If hte function is called with an index as parameter, it will return the "new" TOUCHDOWNVTX table.
The TOUCHDOWNVTX table contains the following key value pairs:
  • "pos" (vector)
  • "stiffness" (number)
  • "damping" (number)
  • "mu" (number)
  • "mu_lng" (number)

set_touchdownpoints :
This method uses a polymorphic approach.
If the function is called with three vectors, it will perform the "old" API action.
If the function is called with one list (table) containing at least 3 TOUCHDOWNVTX tables, it will perform the "new" API action.

Example:
Code:
v = vessel.get_focusinterface()

// ----------------------------------------------------------------
p1,p2,p3 = v:get_touchdownpoints()  // OLD, 'cause no index provided
v:set_touchdownpoints(p1, p2, p3)   // OLD, 'cause three vectors provided

// ----------------------------------------------------------------
arr = {}
arr[1] = v:get_touchdownpoints(0) // NEW, 'cause index provided
arr[2] = v:get_touchdownpoints(1) // NEW,   "     "     "
arr[3] = v:get_touchdownpoints(2) // NEW,   "     "     "
v:set_touchdownpoints(arr)        // NEW, 'cause table with at least 3 TOUCHDOWNVTX tables given
get_status :
This method can be used to get either the "version 1" VESSELSTATUS or the "version 2" VESSELSTATUS2 table.
The first parameter can be used to distinguish between these two:
  • 1: Return "version 1" table
  • 2: Return "version 2" table (default if no parameter is given)

The VESSELSTATUS2 table contains the following key value pairs:
  • "version" (number) // always 2
  • "flag" (number)
  • "rbody" (OBJHANDLE)
  • "base" (OBJHANDLE)
  • "port" (number)
  • "status" (number)
  • "rpos" (vector)
  • "rvel" (vector)
  • "vrot" (vector)
  • "arot" (vector)
  • "surf_lng" (number)
  • "surf_lat" (number)
  • "surf_hdg" (number)
  • "fuel" (list of tables) each containing a "idx" (number) and a "level" (number) member
  • "thruster" (list of tables) each containing a "idx" (number) and a "level"(number) member
  • "dockinfo" (list of tables) each containing a "idx" (number), "ridx" (number) and a "rvessel" (OBJHANDLE) member
  • "xpdr" (number)

The VESSELSTATUS table contains the following key value pairs:
  • "rpos" (vector)
  • "rvel" (vector)
  • "vrot" (vector)
  • "arot" (vector)
  • "fuel" (number)
  • "eng_main" (number)
  • "eng_hovr" (number)
  • "rbody" (OBJHANDLE)
  • "base" (OBJHANDLE)
  • "port" (number)
  • "status" (number)
  • "vdata" (vector) // ignored [1]...[9]
  • "fdata" number) // "
  • "flag" (number) // "

Example:
Code:
v = vessel.get_focusinterface()
v:get_status()  // returns VESSELSTATUS2 table
v:get_status(1) // returns VESSELSTATUS table
v:get_status(2) // returns VESSELSTATUS2 table
defset_status :
This method can be used to set either a "version 1" VESSELSTATUS or a "version 2" VESSELSTATUS2 table.
The method distinguishes the type just by checking if the value of the ["version"] field in the given table equals 1 or 2.
This method only changes the values that are given in the table, any not mentioned values will not be changed!
Any "unknown" fields will be ignored.

Example:
Code:
v = vessel.get_focusinterface()
vect = { x=1, y=2, z=3 }

v:defset_status("dummy") // <= results in error
v:defset_status({}) // <= results in error (no ["version"] specified)
v:defset_status({ version=2 }) // <= OK, but does not change anything
v:defset_status({ version=1 }) // <= same as above (with "old" VESSELSTATUS)
v:defset_status({ version=2, port=666 }) // <= will only change the port
v:defset_status({ version=2, port=666, foo="bar" }) // <= same as above, all unknown fields will be ignored
v:defset_status({ port=666, arot=vect, version=2 }) // <= OK as long as vect is a VECTOR; the order of the fields is irrelevant

oapi.deflate :
This function deflates (or packs) a string.
This function is called with one string (a bytes array, as Lua strings can contain binary zero as well)

oapi.inflate :
This methods inflates (or unpacks) a packed string that was packed by oapi.deflate() or by the according Orbiter core function.
The new tree-data files for example are packed this way.
This function is called with one string (a bytes array, as Lua strings can contain binary zero as well)

Example:
Code:
local inp = "Hello World!\nHello World!\nHello World!\nHello World!" -- input buffer
local pak = oapi.deflate(inp)
local out = oapi.inflate(pak)

term.out(#inp .. ' => ' .. #pak .. ' => ' .. #out)
term.out("Result: " .. tostring(inp == out))

oapi.get_annotations :
This method returns a list of all currently created annotation handle objects.
This was added mainly as an option while debugging, as newly created annotation handle objects are not automatically deleted when running a script via the "run()" command. So each time a script was run ("run 'script'" rsp. "run('script')") the previous annotatos were not cleared.
Here's an example how this method can be used:
Code:
-- re-use 1st 'old' annotation object (if available)
local noteTop = oapi.get_annotations() or oapi.create_annotation()
This is functionally equal to the following code:
Code:
local noteTop = oapi.get_annotations()
if noteTop == nil then
  noteTop = oapi.create_annotation()
end
...just written a bit more 'cool' :p

Another way of usage (to clear all 'old' annotation objects) would be:
Code:
-- delete any 'old' annotation objects
for key,value in pairs({oapi.get_annotations()}) do
  oapi.del_annotation(value)
end


Note: Current implementation in Orbiter BETA cannot print (via term.out) some of the "more complex" structures, so you might have to explicitly access sub-members like "term.out(vesselstat2.fuel[1])" or "term.out( #vesselstat2.thruster )"
I want to know about set_ For example, I already know the coordinates of the three points where the landing gear of the spaceship contacts the ground, and how to set them in detail in the Lua file
 

Attachments

  • 屏幕截图(34).png
    屏幕截图(34).png
    14.9 KB · Views: 13

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
1,665
Reaction score
192
Points
63
Basically all lua functions behave just like their C++ counterparts (except for the different syntax of course).
So to get a grasp on those, I recommend to look at the Orbiter API documentation for those.

Another option to get the "general concept" is to look at the samples (for example Orbitersdk\samples\DeltaGlider\ rsp. Orbitersdk\samples\Vessel\DeltaGlider\).
The C++ source code might give a hint on how to use the functions.
Look for SetTouchdownPoints and/or TOUCHDOWNVTX

Regarding you code sample, I can only see one "empty" list element in the call to set_touchdownpoints(p1, p2, p3, ,p4, p5, p6, p7, p8, p9)
[Note the "double comma" between p3 & p4]. I think it should be set_touchdownpoints(p1, p2, p3, p4, p5, p6, p7, p8, p9)
 
Last edited:

xjflcf520

Member
Joined
Feb 26, 2021
Messages
61
Reaction score
5
Points
23
Location
Chana
Basically all lua functions behave just like their C++ counterparts (except for the different syntax of course).
So to get a grasp on those, I recommend to look at the Orbiter API documentation for those.

Another option to get the "general concept" is to look at the samples (for example Orbitersdk\samples\DeltaGlider\ rsp. Orbitersdk\samples\Vessel\DeltaGlider\).
The C++ source code might give a hint on how to use the functions.
Look for SetTouchdownPoints and/or TOUCHDOWNVTX

Regarding you code sample, I can only see one "empty" list element in the call to set_touchdownpoints(p1, p2, p3, ,p4, p5, p6, p7, p8, p9)
[Note the "double comma" between p3 & p4]. I think it should be set_touchdownpoints(p1, p2, p3, p4, p5, p6, p7, p8, p9)
Except for the double comma error, can I set the collision point coordinates like this
 

xjflcf520

Member
Joined
Feb 26, 2021
Messages
61
Reaction score
5
Points
23
Location
Chana
Basically all lua functions behave just like their C++ counterparts (except for the different syntax of course).
So to get a grasp on those, I recommend to look at the Orbiter API documentation for those.

Another option to get the "general concept" is to look at the samples (for example Orbitersdk\samples\DeltaGlider\ rsp. Orbitersdk\samples\Vessel\DeltaGlider\).
The C++ source code might give a hint on how to use the functions.
Look for SetTouchdownPoints and/or TOUCHDOWNVTX

Regarding you code sample, I can only see one "empty" list element in the call to set_touchdownpoints(p1, p2, p3, ,p4, p5, p6, p7, p8, p9)
[Note the "double comma" between p3 & p4]. I think it should be set_touchdownpoints(p1, p2, p3, p4, p5, p6, p7, p8, p9)
Should touchdownpoint be set to this form:
p1 = v(0, 0, 0)
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
1,665
Reaction score
192
Points
63
I am not absolutely sure, as I have never done that ;)
But generally each point is a (3-dimensional) vector, so that should be O.K.

Could you post a simple lua script, where you think it should work? So maybe I can step through the specific line and double-check that those values are actually given to the right Orbiter API calls.

As the lua interface functions were made back in 2017 and I don't think anybody has really tried them until now, it is possible that they actually do not work as expected 😊 .
Please make the script as simple as possible, as I am not really a lua expert - If I were, I would have written unit tests for each function -

So, long story short: There is a chance that set_touchdownpoints is buggy (I estimate a chance of 10% though).
 

xjflcf520

Member
Joined
Feb 26, 2021
Messages
61
Reaction score
5
Points
23
Location
Chana
Here is my Lua file,This way of setting touchdownpoint doesn't work. I hope you can point out the reason for my mistake
 

Attachments

  • lua.zip
    404 bytes · Views: 3

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
1,665
Reaction score
192
Points
63
Hi again,
I have not yet found the time to look at your script, sorry.
But I've noticed that the TOUCHDOWNVTX struct seems to be a bit more than just a vector, uuups.

It has several more members (to be provided/filled):
  • "pos"
  • "stiffness"
  • "damping"
  • "mu"
  • "mu_lng"

So I guess constructing one TOUCHDOWNVTX "point" would look something like this:

Code:
p1 = { pos={ x=1, y=2, z=3 }, stiffness=4, damping=5, mu=6, mu_lng=7 }
// or is it ? I'm not good at Lua ;)
p1 = {}
p1.pos.x=1
p1.pos.y=2
p1.pos.z=3
p1.stiffness=4
p1.damping=5
p1.mu=6
p1.mu_lng=7

Note: The numbers are only examples. And that code is not tested, so it might not even be syntactically correct ;)
But I hope you get the idea what I am trying to tell.
 
Last edited:

xjflcf520

Member
Joined
Feb 26, 2021
Messages
61
Reaction score
5
Points
23
Location
Chana
Hi again,
I have not yet found the time to look at your script, sorry.
But I've noticed that the TOUCHDOWNVTX struct seems to be a bit more than just a vector, uuups.

It has several more members (to be provided/filled):
  • "pos"
  • "stiffness"
  • "damping"
  • "mu"
  • "mu_lng"

So I guess constructing one TOUCHDOWNVTX "point" would look something like this:

Code:
p1 = { pos={ x=1, y=2, z=3 }, stiffness=4, damping=5, mu=6, mu_lng=7 }
// or is it ? I'm not good at Lua ;)
p1 = {}
p1.pos.x=1
p1.pos.y=2
p1.pos.z=3
p1.stiffness=4
p1.damping=5
p1.mu=6
p1.mu_lng=7

Note: The numbers are only examples. And that code is not tested, so it might not even be syntactically correct ;)
But I hope you get the idea what I am trying to tell.
Hello, I've tried the two methods you mentioned to set up touchdownpoints, but they don't seem to work
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
1,665
Reaction score
192
Points
63
Hello again,

I've managed to port the old project/solution to Visual Studio 2017 and was able to dig into the touchdownpoints issue.
There was actually a bug in the interface implementation 😊
So, in the 1st post you'll find a new ZIP (LuaScript 2021-03-30(dlls).zip) for Orbiter BETA which you can try!
I will provide the Builds (ZIPs) for Orbiter 2016 when I find the time to do it.

Attached, my test Lua (overwrite Orbiters Script\Tests\unit_test.lua file and run it via Scenarios\Tests\unit_test.scn).
I had to rename it to unit_test.lua.txt as .lua is a not accepted attachment extenssion, but I guess you know how to rename it ;)

The "relevant" parts here:
Code:
add_line("Test: vessel:get_touchdownpoints()")
v = vessel.get_interface("GL-01")
td1,td2,td3 = v:get_touchdownpoints()
assert(td1.x == 0 and td1.y == -1.5 and td1.z == 9 and td2.x == -6 and td2.y == -0.8 and td2.z == -5 and td3.x == 3 and td3.y == -1.2 and td3.z == -5)
v:Gear(1)
proc.wait_simdt(7)
td1,td2,td3 = v:get_touchdownpoints()
assert(td1.x == 0 and td1.y == -2.57 and td1.z == 10 and td2.x == -3.5 and td2.y == -2.57 and td2.z == -1 and td3.x == 3.5 and td3.y == -2.57 and td3.z == -1)
v:Gear(0)
proc.wait_simdt(7)
td1,td2,td3 = v:get_touchdownpoints()
assert(td1.x == 0 and td1.y == -1.5 and td1.z == 9 and td2.x == -6 and td2.y == -0.8 and td2.z == -5 and td3.x == 3 and td3.y == -1.2 and td3.z == -5)
pass()

add_line("Test: vessel:get_touchdownpointcount()")
v = vessel.get_interface("GL-01")
tdc = v:get_touchdownpointcount()
assert(tdc == 13)
pass()

exp = {} -- expected "gear up" results
exp[ 0] = {pos={x=0, y=-1.5, z=9}, stiffness=1e7, damping=1e5, mu=3.5445e-08, mu_lng=3}
exp[ 1] = {pos={x=-6, y=-0.8, z=-5}, stiffness=1e7, damping=1e5, mu=2.21197e-08, mu_lng=3}
exp[ 2] = {pos={x=3, y=-1.2, z=-5}, stiffness=1e7, damping=1e5, mu=4.24352e-08, mu_lng=3}
exp[ 3] = {pos={x=-8.5, y=-0.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=-9.12894e+306, mu_lng=3}
exp[ 4] = {pos={x=8.5, y=-0.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=-1.63524e-206, mu_lng=3}
exp[ 5] = {pos={x=-8.5, y=-0.4, z=-3}, stiffness=1e7, damping=1e5, mu=2.00016, mu_lng=3}
exp[ 6] = {pos={x=8.5, y=-0.4, z=-3}, stiffness=1e7, damping=1e5, mu=1.03171e+26, mu_lng=3}
exp[ 7] = {pos={x=-8.85, y=2.3, z=-5.05}, stiffness=1e7, damping=1e5, mu=1.42505e+103, mu_lng=3}
exp[ 8] = {pos={x=8.85, y=2.3, z=-5.05}, stiffness=1e7, damping=1e5, mu=9.53414e-130, mu_lng=3}
exp[ 9] = {pos={x=-8.85, y=2.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=5.50352e-53, mu_lng=3}
exp[10] = {pos={x=8.85, y=2.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=5.88118e-308, mu_lng=3}
exp[11] = {pos={x=0,y=2, z=6.2}, stiffness=1e7, damping=1e5, mu=2.93186e-308, mu_lng=3}
exp[12] = {pos={x=0,y=-0.6, z=10.65}, stiffness=1e7, damping=1e5, mu=1.42005e-306, mu_lng=3}

exp2 = {} -- expected "gear down" results
exp2[0] = {pos={x=0, y=-2.57, z=10}, stiffness=1e6, damping=1e5, mu=9.09091e-08, mu_lng=1.6}
exp2[1] = {pos={x=-3.5, y=-2.57, z=-1}, stiffness=1e6, damping=1e5, mu=4.54545e-07, mu_lng=3}
exp2[2] = {pos={x=3.5, y=-2.57, z=-1}, stiffness=1e6, damping=1e5, mu=4.54545e-07, mu_lng=3}
exp2[3] = {pos={x=-8.5, y=-0.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=-5.10637e-310, mu_lng=3}
exp2[4] = {pos={x=8.5, y=-0.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=3.11088e-302, mu_lng=3}
exp2[5] = {pos={x=-8.5, y=-0.4, z=-3}, stiffness=1e7, damping=1e5, mu=0, mu_lng=3}
exp2[6] = {pos={x=8.5, y=-0.4, z=-3}, stiffness=1e7, damping=1e5, mu=0, mu_lng=3}
exp2[7] = {pos={x=-8.85, y=2.3, z=-5.05}, stiffness=1e7, damping=1e5, mu=0, mu_lng=3}
exp2[8] = {pos={x=8.85, y=2.3, z=-5.05}, stiffness=1e7, damping=1e5, mu=0, mu_lng=3}
exp2[9] = {pos={x=-8.85, y=2.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=nil, mu_lng=3}
exp2[10] = {pos={x=8.85, y=2.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=-3.53744e-310, mu_lng=3}
exp2[11] = {pos={x=0, y=2, z=6.2}, stiffness=1e7, damping=1e5, mu=2.76101e-309, mu_lng=3}
exp2[12] = {pos={x=0, y=-0.6, z=10.65}, stiffness=1e7, damping=1e5, mu=0, mu_lng=3}

add_line("Test: vessel:get_touchdownpoints(GEARUP \"NewAPI\")")
v = vessel.get_interface("GL-01")
tdc = v:get_touchdownpointcount()
for i=0,tdc-1 do
  tdp = v:get_touchdownpoints(i)
  assert(tdp.pos.x == exp[i].pos.x and tdp.pos.y == exp[i].pos.y and tdp.pos.z == exp[i].pos.z
     and tdp.stiffness == exp[i].stiffness
     and tdp.damping == exp[i].damping
   --and  tdp.mu == exp[i].mu
     and tdp.mu_lng == exp[i].mu_lng
  )
end
pass()
v:Gear(1)
proc.wait_simdt(7)
add_line("Test: vessel:get_touchdownpoints(GEARDOWN \"NewAPI\")")
for i=0,tdc-1 do
  tdp = v:get_touchdownpoints(i)
  assert(tdp.pos.x == exp2[i].pos.x and tdp.pos.y == exp2[i].pos.y and tdp.pos.z == exp2[i].pos.z
     and tdp.stiffness == exp2[i].stiffness
     and tdp.damping == exp2[i].damping
   --and  tdp.mu == exp2[i].mu
     and tdp.mu_lng == exp2[i].mu_lng
  )
end
pass()
v:Gear(0)
proc.wait_simdt(7)
add_line("Test: vessel:get_touchdownpoints(GEARUP2 \"NewAPI\")")
for i=0,tdc-1 do
  tdp = v:get_touchdownpoints(i)
  assert(tdp.pos.x == exp[i].pos.x and tdp.pos.y == exp[i].pos.y and tdp.pos.z == exp[i].pos.z
     and tdp.stiffness == exp[i].stiffness
     and tdp.damping == exp[i].damping
   --and  tdp.mu == exp[i].mu
     and tdp.mu_lng == exp[i].mu_lng
  )
end
pass()

add_line("Test: vessel:set_touchdownpoints(\"NewAPI\")")
v = vessel.get_interface("GL-01")
arr = {}
arr[1] = v:get_touchdownpoints(0) -- NEW, 'cause index provided
arr[2] = v:get_touchdownpoints(1) -- NEW,   "     "     "
arr[3] = v:get_touchdownpoints(2) -- NEW,   "     "     "
arr[4] = v:get_touchdownpoints(3) -- NEW,   "     "     "
arr[5] = v:get_touchdownpoints(4) -- NEW,   "     "     "
arr[6] = v:get_touchdownpoints(5) -- NEW,   "     "     "
v:set_touchdownpoints(arr)
pass()

--note:set_colour ({r=0,g=0.9,b=0})
add_line("=== All tests passed ===", "green")
 

Attachments

  • unit_test.lua.txt
    14.1 KB · Views: 1

xjflcf520

Member
Joined
Feb 26, 2021
Messages
61
Reaction score
5
Points
23
Location
Chana
Hello again,

I've managed to port the old project/solution to Visual Studio 2017 and was able to dig into the touchdownpoints issue.
There was actually a bug in the interface implementation 😊
So, in the 1st post you'll find a new ZIP (LuaScript 2021-03-30(dlls).zip) for Orbiter BETA which you can try!
I will provide the Builds (ZIPs) for Orbiter 2016 when I find the time to do it.

Attached, my test Lua (overwrite Orbiters Script\Tests\unit_test.lua file and run it via Scenarios\Tests\unit_test.scn).
I had to rename it to unit_test.lua.txt as .lua is a not accepted attachment extenssion, but I guess you know how to rename it ;)

The "relevant" parts here:
Code:
add_line("Test: vessel:get_touchdownpoints()")
v = vessel.get_interface("GL-01")
td1,td2,td3 = v:get_touchdownpoints()
assert(td1.x == 0 and td1.y == -1.5 and td1.z == 9 and td2.x == -6 and td2.y == -0.8 and td2.z == -5 and td3.x == 3 and td3.y == -1.2 and td3.z == -5)
v:Gear(1)
proc.wait_simdt(7)
td1,td2,td3 = v:get_touchdownpoints()
assert(td1.x == 0 and td1.y == -2.57 and td1.z == 10 and td2.x == -3.5 and td2.y == -2.57 and td2.z == -1 and td3.x == 3.5 and td3.y == -2.57 and td3.z == -1)
v:Gear(0)
proc.wait_simdt(7)
td1,td2,td3 = v:get_touchdownpoints()
assert(td1.x == 0 and td1.y == -1.5 and td1.z == 9 and td2.x == -6 and td2.y == -0.8 and td2.z == -5 and td3.x == 3 and td3.y == -1.2 and td3.z == -5)
pass()

add_line("Test: vessel:get_touchdownpointcount()")
v = vessel.get_interface("GL-01")
tdc = v:get_touchdownpointcount()
assert(tdc == 13)
pass()

exp = {} -- expected "gear up" results
exp[ 0] = {pos={x=0, y=-1.5, z=9}, stiffness=1e7, damping=1e5, mu=3.5445e-08, mu_lng=3}
exp[ 1] = {pos={x=-6, y=-0.8, z=-5}, stiffness=1e7, damping=1e5, mu=2.21197e-08, mu_lng=3}
exp[ 2] = {pos={x=3, y=-1.2, z=-5}, stiffness=1e7, damping=1e5, mu=4.24352e-08, mu_lng=3}
exp[ 3] = {pos={x=-8.5, y=-0.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=-9.12894e+306, mu_lng=3}
exp[ 4] = {pos={x=8.5, y=-0.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=-1.63524e-206, mu_lng=3}
exp[ 5] = {pos={x=-8.5, y=-0.4, z=-3}, stiffness=1e7, damping=1e5, mu=2.00016, mu_lng=3}
exp[ 6] = {pos={x=8.5, y=-0.4, z=-3}, stiffness=1e7, damping=1e5, mu=1.03171e+26, mu_lng=3}
exp[ 7] = {pos={x=-8.85, y=2.3, z=-5.05}, stiffness=1e7, damping=1e5, mu=1.42505e+103, mu_lng=3}
exp[ 8] = {pos={x=8.85, y=2.3, z=-5.05}, stiffness=1e7, damping=1e5, mu=9.53414e-130, mu_lng=3}
exp[ 9] = {pos={x=-8.85, y=2.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=5.50352e-53, mu_lng=3}
exp[10] = {pos={x=8.85, y=2.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=5.88118e-308, mu_lng=3}
exp[11] = {pos={x=0,y=2, z=6.2}, stiffness=1e7, damping=1e5, mu=2.93186e-308, mu_lng=3}
exp[12] = {pos={x=0,y=-0.6, z=10.65}, stiffness=1e7, damping=1e5, mu=1.42005e-306, mu_lng=3}

exp2 = {} -- expected "gear down" results
exp2[0] = {pos={x=0, y=-2.57, z=10}, stiffness=1e6, damping=1e5, mu=9.09091e-08, mu_lng=1.6}
exp2[1] = {pos={x=-3.5, y=-2.57, z=-1}, stiffness=1e6, damping=1e5, mu=4.54545e-07, mu_lng=3}
exp2[2] = {pos={x=3.5, y=-2.57, z=-1}, stiffness=1e6, damping=1e5, mu=4.54545e-07, mu_lng=3}
exp2[3] = {pos={x=-8.5, y=-0.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=-5.10637e-310, mu_lng=3}
exp2[4] = {pos={x=8.5, y=-0.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=3.11088e-302, mu_lng=3}
exp2[5] = {pos={x=-8.5, y=-0.4, z=-3}, stiffness=1e7, damping=1e5, mu=0, mu_lng=3}
exp2[6] = {pos={x=8.5, y=-0.4, z=-3}, stiffness=1e7, damping=1e5, mu=0, mu_lng=3}
exp2[7] = {pos={x=-8.85, y=2.3, z=-5.05}, stiffness=1e7, damping=1e5, mu=0, mu_lng=3}
exp2[8] = {pos={x=8.85, y=2.3, z=-5.05}, stiffness=1e7, damping=1e5, mu=0, mu_lng=3}
exp2[9] = {pos={x=-8.85, y=2.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=nil, mu_lng=3}
exp2[10] = {pos={x=8.85, y=2.3, z=-7.05}, stiffness=1e7, damping=1e5, mu=-3.53744e-310, mu_lng=3}
exp2[11] = {pos={x=0, y=2, z=6.2}, stiffness=1e7, damping=1e5, mu=2.76101e-309, mu_lng=3}
exp2[12] = {pos={x=0, y=-0.6, z=10.65}, stiffness=1e7, damping=1e5, mu=0, mu_lng=3}

add_line("Test: vessel:get_touchdownpoints(GEARUP \"NewAPI\")")
v = vessel.get_interface("GL-01")
tdc = v:get_touchdownpointcount()
for i=0,tdc-1 do
  tdp = v:get_touchdownpoints(i)
  assert(tdp.pos.x == exp[i].pos.x and tdp.pos.y == exp[i].pos.y and tdp.pos.z == exp[i].pos.z
     and tdp.stiffness == exp[i].stiffness
     and tdp.damping == exp[i].damping
   --and  tdp.mu == exp[i].mu
     and tdp.mu_lng == exp[i].mu_lng
  )
end
pass()
v:Gear(1)
proc.wait_simdt(7)
add_line("Test: vessel:get_touchdownpoints(GEARDOWN \"NewAPI\")")
for i=0,tdc-1 do
  tdp = v:get_touchdownpoints(i)
  assert(tdp.pos.x == exp2[i].pos.x and tdp.pos.y == exp2[i].pos.y and tdp.pos.z == exp2[i].pos.z
     and tdp.stiffness == exp2[i].stiffness
     and tdp.damping == exp2[i].damping
   --and  tdp.mu == exp2[i].mu
     and tdp.mu_lng == exp2[i].mu_lng
  )
end
pass()
v:Gear(0)
proc.wait_simdt(7)
add_line("Test: vessel:get_touchdownpoints(GEARUP2 \"NewAPI\")")
for i=0,tdc-1 do
  tdp = v:get_touchdownpoints(i)
  assert(tdp.pos.x == exp[i].pos.x and tdp.pos.y == exp[i].pos.y and tdp.pos.z == exp[i].pos.z
     and tdp.stiffness == exp[i].stiffness
     and tdp.damping == exp[i].damping
   --and  tdp.mu == exp[i].mu
     and tdp.mu_lng == exp[i].mu_lng
  )
end
pass()

add_line("Test: vessel:set_touchdownpoints(\"NewAPI\")")
v = vessel.get_interface("GL-01")
arr = {}
arr[1] = v:get_touchdownpoints(0) -- NEW, 'cause index provided
arr[2] = v:get_touchdownpoints(1) -- NEW,   "     "     "
arr[3] = v:get_touchdownpoints(2) -- NEW,   "     "     "
arr[4] = v:get_touchdownpoints(3) -- NEW,   "     "     "
arr[5] = v:get_touchdownpoints(4) -- NEW,   "     "     "
arr[6] = v:get_touchdownpoints(5) -- NEW,   "     "     "
v:set_touchdownpoints(arr)
pass()

--note:set_colour ({r=0,g=0.9,b=0})
add_line("=== All tests passed ===", "green")
Thank you very much for your solution. I will try to see if I can solve my needs as soon as possible. Thank you again for your warm-hearted answers.
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
1,665
Reaction score
192
Points
63
Found some time ;) ...
Added the ZIPs for Orbiter 2016 (see 1st post).
 
Top