Andi’s Autopilot

22
Andi’s Autopilot A Hard Real-Time Control Application Broderic Gonzales CS 722 May 2, 2005 v.05

description

Andi’s Autopilot. A Hard Real-Time Control Application. Broderic Gonzales CS 722 May 2, 2005 v.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 - PowerPoint PPT Presentation

Transcript of Andi’s Autopilot

Page 1: Andi’s Autopilot

Andi’s Autopilot

A Hard Real-Time Control Application

Broderic GonzalesCS 722

May 2, 2005v.05

Page 2: Andi’s Autopilot

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.

Page 3: Andi’s Autopilot

What makes a system real time?1

• Timeliness• Reactiveness• Concurrency• Device abstractions• Distributive• State-dependency • Dynamic internal structure

1 Coad[230]

Page 4: Andi’s Autopilot

Timeliness

• Timing constraints if not met cause unwanted loss of data.

• The autopilot uses separate, prioritized threads of control.

Page 5: Andi’s Autopilot

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.

Page 6: Andi’s Autopilot

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.

Page 7: Andi’s Autopilot

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.

Page 8: Andi’s Autopilot

Distributive

• Responsibility of controls is spread amongst objects.

• The autopilot allows the instrumentation to maintain only the information that is relevant to them.

Page 9: Andi’s Autopilot

Design Overview

Page 10: Andi’s Autopilot

Main Classes

Page 11: Andi’s Autopilot

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

Page 12: Andi’s Autopilot

Elevators Class Details

Page 13: Andi’s Autopilot

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

Page 14: Andi’s Autopilot

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

Page 15: Andi’s Autopilot

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

Page 16: Andi’s Autopilot

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

Page 17: Andi’s Autopilot

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

Page 18: Andi’s Autopilot

System Interaction Classes

Test drivers. They generated data for the instruments.

Page 19: Andi’s Autopilot

SI Classes - Details

Composite Pattern

Not really a gyro

Page 20: Andi’s Autopilot

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.

Page 21: Andi’s Autopilot

OS Abstraction Layer Details

Relying on POSIX threads

Page 22: Andi’s Autopilot

References

• Coad, Peter. Object Models: Strategies, Patterns, & Applications. 2nd ed. New Jersey:Prentice Hall,1997