Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Prototype]Touchdown points penetration distance #470

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Orbitersdk/include/VesselAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
};

// ======================================================================
Expand Down
13 changes: 13 additions & 0 deletions Orbitersdk/samples/Lua/DeltaGlider/Src/Deltaglider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
2 changes: 1 addition & 1 deletion Src/Module/LuaScript/LuaInterpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions Src/Module/LuaScript/LuaInterpreter/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions Src/Module/LuaScript/LuaInterpreter/lua_vessel_mtd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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.

Expand Down
45 changes: 29 additions & 16 deletions Src/Orbiter/Vessel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -1214,6 +1217,7 @@ void Vessel::ClearTouchdownPoints ()
if (ntouchdown_vtx) {
delete []touchdown_vtx;
ntouchdown_vtx = 0;
touchdown_contact_info.resize(0);
}
}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -9044,3 +9052,8 @@ int VESSEL4::clbkNavProcess (int mode)
{
return mode;
}

bool VESSEL4::GetGroundContactInfo(CONTACTINFO *info, DWORD idx)
{
return vessel->GetGroundContactInfo(info, idx);
}
11 changes: 10 additions & 1 deletion Src/Orbiter/Vessel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<CONTACTINFO> touchdown_contact_info;
DWORD ntouchdown_vtx; // number of touchdown vertices
DWORD next_hullvtx; // used by hull vertex iterator

Expand Down
Loading