From d6a3af92567c31f3b49664a8d494e85d74d2500a Mon Sep 17 00:00:00 2001 From: Gondos Date: Thu, 4 Jul 2024 00:33:23 +0200 Subject: [PATCH 1/2] [Prototype]Touchdown points contact information --- Orbitersdk/include/VesselAPI.h | 8 ++++ .../Lua/DeltaGlider/Src/Deltaglider.lua | 13 ++++++ .../LuaScript/LuaInterpreter/Interpreter.cpp | 2 +- .../LuaScript/LuaInterpreter/Interpreter.h | 1 + .../LuaInterpreter/lua_vessel_mtd.cpp | 26 +++++++++++ Src/Orbiter/Vessel.cpp | 45 ++++++++++++------- Src/Orbiter/Vessel.h | 11 ++++- 7 files changed, 88 insertions(+), 18 deletions(-) diff --git a/Orbitersdk/include/VesselAPI.h b/Orbitersdk/include/VesselAPI.h index 521209e82..523babe46 100644 --- a/Orbitersdk/include/VesselAPI.h +++ b/Orbitersdk/include/VesselAPI.h @@ -40,6 +40,12 @@ typedef struct { double mu_lng; ///< longitudinal friction coefficient (only used for first 3 points) } TOUCHDOWNVTX; +struct CONTACTINFO { + double depth; + VECTOR3 normal; +}; + + // ====================================================================== /** * \brief Base class for objects of vessel type (spacecraft and similar) @@ -6464,6 +6470,8 @@ class OAPIFUNC VESSEL4: public VESSEL3 { * VESSEL::ActivateNavmode, VESSEL::DeactivateNavmode, VESSEL::ToggleNavmode */ virtual int clbkNavProcess (int mode); + + bool GetGroundContactInfo(CONTACTINFO *, DWORD idx); }; // ====================================================================== diff --git a/Orbitersdk/samples/Lua/DeltaGlider/Src/Deltaglider.lua b/Orbitersdk/samples/Lua/DeltaGlider/Src/Deltaglider.lua index 45eef823d..eb1537152 100644 --- a/Orbitersdk/samples/Lua/DeltaGlider/Src/Deltaglider.lua +++ b/Orbitersdk/samples/Lua/DeltaGlider/Src/Deltaglider.lua @@ -1412,6 +1412,19 @@ function DeltaGlider:clbkPostStep (simt, simdt, mjd) end ComponentVessel.clbkPostStep (self, simt, simdt, mjd) + + if self.bGearIsDown and self:get_groundcontact() then + local str = "" + for i = 0,12 do + local tdinfo = self:get_groundcontactinfo(i) + if tdinfo and tdinfo.depth <= 0 then + str = str..string.format("td%d %.02f V(%.02f,%.02f,%.02f) ", i, tdinfo.depth, tdinfo.normal.x, tdinfo.normal.y, tdinfo.normal.z) + end + end + oapi.dbg_out(str) + else + oapi.dbg_out("") + end end function DeltaGlider:clbkLoadGenericCockpit () diff --git a/Src/Module/LuaScript/LuaInterpreter/Interpreter.cpp b/Src/Module/LuaScript/LuaInterpreter/Interpreter.cpp index 8ce085d0e..ac511fd50 100644 --- a/Src/Module/LuaScript/LuaInterpreter/Interpreter.cpp +++ b/Src/Module/LuaScript/LuaInterpreter/Interpreter.cpp @@ -3661,7 +3661,7 @@ module or by multiple modules) the last state before rendering will be displayed int Interpreter::oapiDbgOut (lua_State *L) { const char *str = lua_tostringex (L, 1); - strcpy (oapiDebugString(), str); + strncpy (oapiDebugString(), str, 256); return 0; } diff --git a/Src/Module/LuaScript/LuaInterpreter/Interpreter.h b/Src/Module/LuaScript/LuaInterpreter/Interpreter.h index 93b5e795b..8260fa354 100644 --- a/Src/Module/LuaScript/LuaInterpreter/Interpreter.h +++ b/Src/Module/LuaScript/LuaInterpreter/Interpreter.h @@ -647,6 +647,7 @@ class INTERPRETERLIB Interpreter { static int v_send_bufferedkey (lua_State *L); static int v_is_landed (lua_State *L); static int v_get_groundcontact (lua_State *L); + static int v_get_groundcontactinfo (lua_State *L); // general vessel properties static int v_get_name (lua_State *L); diff --git a/Src/Module/LuaScript/LuaInterpreter/lua_vessel_mtd.cpp b/Src/Module/LuaScript/LuaInterpreter/lua_vessel_mtd.cpp index a6222dc3c..eb84e882f 100644 --- a/Src/Module/LuaScript/LuaInterpreter/lua_vessel_mtd.cpp +++ b/Src/Module/LuaScript/LuaInterpreter/lua_vessel_mtd.cpp @@ -333,6 +333,7 @@ void Interpreter::LoadVesselAPI () // vessel status {"is_landed", v_is_landed}, {"get_groundcontact", v_get_groundcontact}, + {"get_groundcontactinfo", v_get_groundcontactinfo}, // fuel management {"create_propellantresource", v_create_propellantresource }, @@ -2387,6 +2388,31 @@ int Interpreter::v_get_groundcontact (lua_State *L) return 1; } +int Interpreter::v_get_groundcontactinfo (lua_State *L) +{ + static const char *funcname = "v_get_groundcontactpenetration"; + VESSEL* v = lua_tovessel_safe(L, 1, funcname); + if (v->Version() < 3) { + lua_pushnil(L); + lua_pushstring(L, "Invalid vessel version in register_panelarea"); + return 2; + } + VESSEL4* v4 = (VESSEL4*)v; + int idx = luaL_checkinteger(L, 2); + + CONTACTINFO info; + bool ret = v4->GetGroundContactInfo(&info, idx); + if(!ret) return luaL_error(L, "Index out of range (%d/%d)", idx, v4->GetTouchdownPointCount()); + + lua_newtable (L); + lua_pushnumber (L, info.depth); + lua_setfield (L, -2, "depth"); + lua_pushvector(L, info.normal); + lua_setfield (L, -2, "normal"); + + return 1; +} + /*** Angular acceleration. diff --git a/Src/Orbiter/Vessel.cpp b/Src/Orbiter/Vessel.cpp index f1555c64d..207dca007 100644 --- a/Src/Orbiter/Vessel.cpp +++ b/Src/Orbiter/Vessel.cpp @@ -1144,8 +1144,11 @@ bool Vessel::SetTouchdownPoints (const TOUCHDOWNVTX *tdvtx, DWORD ntp) double a, b, c, d, e, f; if (ntp != ntouchdown_vtx) { - if (ntouchdown_vtx) delete []touchdown_vtx; + if (ntouchdown_vtx) { + delete []touchdown_vtx; + } touchdown_vtx = new TOUCHDOWN_VTX[ntouchdown_vtx = ntp]; + touchdown_contact_info.resize(ntouchdown_vtx, {0,{0,1,0}}); } for (i = 0; i < ntp; i++) { touchdown_vtx[i].pos.Set (MakeVector(tdvtx[i].pos)); @@ -1214,6 +1217,7 @@ void Vessel::ClearTouchdownPoints () if (ntouchdown_vtx) { delete []touchdown_vtx; ntouchdown_vtx = 0; + touchdown_contact_info.resize(0); } } @@ -4293,7 +4297,6 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub int i, j; double alt = 0, tdymin = 0; static int *tidx = new int[3]; - static double *tdy = new double[3]; static double *fn = new double[3]; static double *flng = new double[3]; static double *flat = new double[3]; @@ -4334,8 +4337,6 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub ntdy = ntouchdown_vtx; delete []tidx; tidx = new int[ntdy]; - delete []tdy; - tdy = new double[ntdy]; delete []fn; fn = new double[ntdy]; delete []flng; @@ -4352,12 +4353,19 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub for (i = 0; i < ntouchdown_vtx; i++) { Vector p (mul (T, touchdown_vtx[i].pos) + shift); double lng, lat, rad, elev = 0.0; + VECTOR3 normal = _V(0,1,0); proxybody->LocalToEquatorial (p, lng, lat, rad); - if (emgr) - elev = emgr->Elevation (lat, lng, reslvl, &etile); - tdy[i] = rad - elev - proxybody->Size(); - if (!i || tdy[i] < tdymin) { - tdymin = tdy[i]; + if (emgr) { + Vector n; + elev = emgr->Elevation (lat, lng, reslvl, &etile, &n); + normal.x = n.x; + normal.y = n.y; + normal.z = n.z; + } + touchdown_contact_info[i].depth = rad - elev - proxybody->Size(); + touchdown_contact_info[i].normal = normal; + if (!i || touchdown_contact_info[i].depth < tdymin) { + tdymin = touchdown_contact_info[i].depth; } } @@ -4466,16 +4474,16 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub DWORD ntouch = 0; for (i = 0; i < ntouchdown_vtx; i++) { - if (tdy[i] < 0.0) { // ground contact on point i! - tdy[i] = max(tdy[i], -1.0); // DEBUG + if (touchdown_contact_info[i].depth < 0.0) { // ground contact on point i! + touchdown_contact_info[i].depth = max(touchdown_contact_info[i].depth, -1.0); // DEBUG tidx[ntouch++] = i; Vector gv (surfp.groundvel_ship + crossp(touchdown_vtx[i].pos,s->omega)); // ground velocity of touchdown point in vessel frame gv_n = dotp (gv, hn); // gv projected on horizon normal in vessel frame gv_lon = dotp (gv, d1h); // longitudinal speed component for touchdown point i gv_lat = dotp (gv, d2h); // lateral speed component - fn[i] = -tdy[i]*touchdown_vtx[i].stiffness; // horizon-normal force component: gear compression forces - double maxpress = min (-tdy[i], 0.1)*touchdown_vtx[i].stiffness; + fn[i] = -touchdown_contact_info[i].depth*touchdown_vtx[i].stiffness; // horizon-normal force component: gear compression forces + double maxpress = min (-touchdown_contact_info[i].depth, 0.1)*touchdown_vtx[i].stiffness; if (i < 3) { mu = touchdown_vtx[i].mu_lng; @@ -4497,7 +4505,7 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub if (gv_lat > 0.0) flat[i] = -flat[i]; flat_tot += flat[i]; - E_comp -= fn[i]*tdy[i]*0.5; // compression energy + E_comp -= fn[i]*touchdown_contact_info[i].depth*0.5; // compression energy fn_tot_undamped += fn[i]; fn[i] -= gv_n*touchdown_vtx[i].damping; fn_tot += fn[i]; @@ -4619,7 +4627,7 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub } else { double v1, v2; for (i = 0; i < 3; i++) { - if (tdy[i] < 0.0) { + if (touchdown_contact_info[i].depth < 0.0) { Vector gv (surfp.groundvel_ship + crossp(touchdown_vtx[i].pos,s->omega)); // ground velocity of touchdown point in vessel frame v1 = dotp (gv, d1h); // longitudinal speed component for touchdown point i v2 = dotp (gv, d2h); // lateral speed component @@ -4665,7 +4673,7 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub // apply angular forces for (i = 0; i < 3; i++) { - if (tdy[i] < 0.0) { + if (touchdown_contact_info[i].depth < 0.0) { Vector f_attack(touchdown_vtx[i].pos); //f_attack.y = 0.0; // hack to avoid nicking Vector F(d1h*flng[i] + d2h*flat[i]); @@ -9044,3 +9052,8 @@ int VESSEL4::clbkNavProcess (int mode) { return mode; } + +bool VESSEL4::GetGroundContactInfo(CONTACTINFO *info, DWORD idx) +{ + return vessel->GetGroundContactInfo(info, idx); +} diff --git a/Src/Orbiter/Vessel.h b/Src/Orbiter/Vessel.h index 01b61fef1..314c36ffd 100644 --- a/Src/Orbiter/Vessel.h +++ b/Src/Orbiter/Vessel.h @@ -1283,6 +1283,15 @@ class Vessel: public VesselBase { void Write (std::ostream &ofs) const; // read/write vessel status from/to stream + bool GetGroundContactInfo(CONTACTINFO *tdi, DWORD idx) { + if(idx < touchdown_contact_info.size()) { + *tdi = touchdown_contact_info[idx]; + return true; + } else { + return false; + } + } + protected: bool OpenConfigFile (std::ifstream &cfgfile) const; // returns configuration file for the vessel @@ -1442,7 +1451,6 @@ class Vessel: public VesselBase { TOUCHDOWN_VTX *HullvtxFirst (); TOUCHDOWN_VTX *HullvtxNext (); - private: void UpdateMass (); // update vessel mass (empty + sum of all fuel resources) @@ -1650,6 +1658,7 @@ class Vessel: public VesselBase { Vector touchdown_nm; // upward normal of touchdown plane (vessel frame) Vector touchdown_cg; // projection of CG onto touchdown plane TOUCHDOWN_VTX *touchdown_vtx; + mutable std::vector touchdown_contact_info; DWORD ntouchdown_vtx; // number of touchdown vertices DWORD next_hullvtx; // used by hull vertex iterator From 2c268a32f147fd1bc82c759ac4f201b8787fdc99 Mon Sep 17 00:00:00 2001 From: Gondos Date: Mon, 22 Jul 2024 18:55:06 +0200 Subject: [PATCH 2/2] Try to fix github CI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index df2d48b3f..7209d77b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -74,7 +74,7 @@ jobs: run: cmake --build --preset windows-${{ matrix.architecture }}-release --jobs 2 - name: Test - run: ctest --preset windows-${{ matrix.architecture }}-release --jobs 2 + run: ctest --preset windows-${{ matrix.architecture }}-release --parallel 2 - name: Install working-directory: ${{ github.workspace }}/out/build/windows-${{ matrix.architecture }}-release