General Question Questions about developing a hover autopilot

sorindafabico

New member
Joined
Mar 23, 2011
Messages
1,231
Reaction score
1
Points
0
Location
Porto Alegre
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?


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);
	}
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Your "constant altitude" autopilot is inherently instable, because even small perturbations (e.g. thrust vector not perfectly aligned with weight vector) will lead to accelerations that are not corrected for.

One possibility would be to measure the vertical acceleration \ddot{x} and adjust thrust T accordingly, i.e.
[math] \Delta T = - \zeta \ddot{x} [/math]with some constant \zeta. However, this would still not result in a constant altitude, because it wouldn't to cancel vertical velocity. For that, I would recommend a damped harmonic oscillator, given by
[math] m \ddot{x} = -\alpha \dot{x} - \beta x [/math]where \ddot{x} is the vertical acceleration, \dot{x} is the vertical velocity, and x is the difference between target and current altitude. \alpha and \beta are the damping coefficient and spring constant. They should be set to the aperiodic limit, for achieving equilibrium quickly without oscillation. The autopilot then has to adjust the thrust to maintain the vertical acceleration given by the equation. If the system is moved out of the equilibrium, it corrects itself.
 
Top