Andi’s Autopilot
A Hard Real-Time Control Application
Broderic GonzalesCS 722
May 2, 2005v.05
Purpose
• “Cruise control” for an airplane.• During flight the autopilot must maintain a
plane’s:– Altitude: keep the plane level at its current height – Direction: keep the plane traveling in its current
heading– Attitude: keep the plane’s orientation stable
• The autopilot is a hard real-time system.
What makes a system real time?1
• Timeliness• Reactiveness• Concurrency• Device abstractions• Distributive• State-dependency • Dynamic internal structure
1 Coad[230]
Timeliness
• Timing constraints if not met cause unwanted loss of data.
• The autopilot uses separate, prioritized threads of control.
Reactiveness
• Immediately identify, respond and process changes in the system.
• The autopilot continuously polls instruments and reports deviations to the autopilot to correct the plane’s flight.
Concurrency
• Multiple activities may be taking place at the same time.
• The autopilot uses multiple threads of control. Each thread does a single task and is assigned to different subsystems to either monitor an instrument or manipulate a control.
Device Abstractions
• Abstract representations of both the physical (problem domain) and the logical (program design.)
• The autopilot abstracts the instruments and controls as objects of the airplane.
• The autopilot is built on a framework layer that abstracts the implementation details of the operating system.
Distributive
• Responsibility of controls is spread amongst objects.
• The autopilot allows the instrumentation to maintain only the information that is relevant to them.
Design Overview
Main Classes
Airplane Class Implementation Details
Airplane::Airplane():_elevators(0), _ailerons(0), _rudders(0)
{ Controls* controls = Controls::On();
_elevators = controls->GetElevators();_ailerons = controls->GetAilerons();_rudders = controls->GetRudders();
}
bool Airplane::ActivateAutopilot(){
bool elevatorsActivated = _elevators->ActivateAltitudeMaint();bool aileronsActivated = _ailerons->ActivateHeadingMaint();bool ruddersActivated = _rudders->ActivateHeadingMaint();
// Was activation of sensor monitors successful?if( elevatorsActivated && aileronsActivated && ruddersActivated )
return true;else
return false;}
Elevators Class Details
Elevators Class Details Continued
bool Elevators::ActivateAltitudeMaint( ){ Initialize(); bool status = false; // Create thread to monitor for updates. taskId = _task->Start( &CallBack, (void*)this);
if( _taskId == Sthread::GOOD_TID ) status = true; // Spawn subthreads. if( status ) status = Activate();
return status;}
Elevators Class Details Continued
float Elevators::CalcAdjustments(){ float length = 0.0; if( _altChgRate != 0.0 ) length = RATE *(_altDeviation/_altChgRate);
float angle = 0.0; if( length != 0.0 ) angle = atan( length/_altDeviation );
return (_pitch + angle);}
Altimeter Class Detail
void Altimeter::MonitorAltitudeDeviation( void* pid ){ Altimeter* a = (Altimeter*)pid;
for( ;; ){ // Lock. a->_mutex->Acquire();
float current = a->ReadAltitude(); a->_altDeviation = a->CalcDeviation( current ); if( a->IsReportable() ){ a->ReportDeviation(); }
// Unlock a->_mutex->Release(); }}
Thread function example
Vertical Speed Gyro Detail
void VerticalSpeedGyro::Register( Elevators* e ){ // May eventually want to store // this into a subscribers list. _elevators = e;}
void VerticalSpeedGyro::ReportChangeRate( float changeRate ){ _elevators->Update( VSI, changeRate );}
Register-Update example
Attitude Gyro Detail
Perhaps, the composite pattern would’ve helped solve the complexity of this class.
bool AttitudeGyro::DeactivatePitchMonitoring(){ _pitchMutex->Acquire();
_pitchTask->Cancel(); _pitchMutex->Release();
return true;}
System Interaction Classes
Test drivers. They generated data for the instruments.
SI Classes - Details
Composite Pattern
Not really a gyro
OS Abstraction Layer
Although, these classes are concrete, their design is intended to act as a framework for this autopilot to work on different OS.
OS Abstraction Layer Details
Relying on POSIX threads
References
• Coad, Peter. Object Models: Strategies, Patterns, & Applications. 2nd ed. New Jersey:Prentice Hall,1997