sorindafabico
New member
I'm playing with a little built-in vessel AP (to learn how to write custom vessel autopilots). It consists in lift-off from an airless surface at constant VACC until an arbitrary altitude, when the hover engine shutdowns and waits the vertical speed approaches zero. Then, the hover engine would counterbalance the gravitational force and altitude would remain constant. It works ok (not perferct, I suppose) in ascent, but in constant altitude phase the vessel experiments some vertical acceleration (or deceleration).
My hypothesis: the gravity from other bodies is affecting the autopilot (take a look at the code), giving the vessel some extra acceleration. The extra acceleration vector changes with the position of the Sun in the sky. Any thoughts on solving this?
My hypothesis: the gravity from other bodies is affecting the autopilot (take a look at the code), giving the vessel some extra acceleration. The extra acceleration vector changes with the position of the Sun in the sky. Any thoughts on solving this?
Code:
// Variables
VECTOR3 spd, gforce;
GetHorizonAirspeedVector(spd);
GetWeightVector(gforce);
double gravidade, massa, tp_th, tp_th_hv, altitude;
gravidade = sqrt(pow(gforce.x,2)+pow(gforce.y,2)+pow(gforce.z,2));
massa = GetMass();
tp_th = (((2*massa)+gravidade)/TL_MAXHOVERTH);
tp_th_hv = ((gravidade)/TL_MAXHOVERTH);
altitude = GetAltitude();
// Test autopilot
if (test_pilot == TP_ON && altitude < 640)
{
SetThrusterLevel (th_hover,tp_th);
}
if (test_pilot == TP_ON && altitude >=640)
{
SetThrusterLevel (th_hover,0);
}
if (test_pilot == TP_ON && spd.y < 0.02 && altitude > 4)
{
SetThrusterLevel (th_hover,tp_th_hv);
}