Skip to content

Commit

Permalink
[Prototype]Touchdown points penetration distance
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGondos committed Jul 3, 2024
1 parent 4a00732 commit 92c8977
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Orbitersdk/include/VesselAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -6464,6 +6464,8 @@ class OAPIFUNC VESSEL4: public VESSEL3 {
* VESSEL::ActivateNavmode, VESSEL::DeactivateNavmode, VESSEL::ToggleNavmode
*/
virtual int clbkNavProcess (int mode);

const double *GetTouchdownVtxPenetration();
};

// ======================================================================
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_groundcontactpenetration (lua_State *L);

// general vessel properties
static int v_get_name (lua_State *L);
Expand Down
18 changes: 18 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_groundcontactpenetration", v_get_groundcontactpenetration},

// fuel management
{"create_propellantresource", v_create_propellantresource },
Expand Down Expand Up @@ -2387,6 +2388,23 @@ int Interpreter::v_get_groundcontact (lua_State *L)
return 1;
}

int Interpreter::v_get_groundcontactpenetration (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);

const double *dist = v4->GetTouchdownVtxPenetration();
lua_pushnumber(L, dist[idx]);
return 1;
}

/***
Angular acceleration.
Expand Down
34 changes: 20 additions & 14 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_vtx_penetration.resize(ntouchdown_vtx);
}
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_vtx_penetration.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 @@ -4355,9 +4356,9 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub
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];
touchdown_vtx_penetration[i] = rad - elev - proxybody->Size();
if (!i || touchdown_vtx_penetration[i] < tdymin) {
tdymin = touchdown_vtx_penetration[i];
}
}

Expand Down Expand Up @@ -4466,16 +4467,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_vtx_penetration[i] < 0.0) { // ground contact on point i!
touchdown_vtx_penetration[i] = max(touchdown_vtx_penetration[i], -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_vtx_penetration[i]*touchdown_vtx[i].stiffness; // horizon-normal force component: gear compression forces
double maxpress = min (-touchdown_vtx_penetration[i], 0.1)*touchdown_vtx[i].stiffness;

if (i < 3) {
mu = touchdown_vtx[i].mu_lng;
Expand All @@ -4497,7 +4498,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_vtx_penetration[i]*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 +4620,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_vtx_penetration[i] < 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 +4666,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_vtx_penetration[i] < 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 +9045,8 @@ int VESSEL4::clbkNavProcess (int mode)
{
return mode;
}

const double *VESSEL4::GetTouchdownVtxPenetration()
{
return vessel->GetTouchdownVtxPenetration();
}
6 changes: 5 additions & 1 deletion Src/Orbiter/Vessel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,10 @@ class Vessel: public VesselBase {
void Write (std::ostream &ofs) const;
// read/write vessel status from/to stream

inline const double *GetTouchdownVtxPenetration() {
return touchdown_vtx_penetration.data();
}

protected:
bool OpenConfigFile (std::ifstream &cfgfile) const;
// returns configuration file for the vessel
Expand Down Expand Up @@ -1442,7 +1446,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 +1653,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<double> touchdown_vtx_penetration;
DWORD ntouchdown_vtx; // number of touchdown vertices
DWORD next_hullvtx; // used by hull vertex iterator

Expand Down

0 comments on commit 92c8977

Please sign in to comment.