0% found this document useful (0 votes)
26 views26 pages

SAGEM-AGS Programing Patterns and Good Practices

AGS

Uploaded by

joker hot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views26 pages

SAGEM-AGS Programing Patterns and Good Practices

AGS

Uploaded by

joker hot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

AGS programming patterns

and good practices


How to write better analysis algorithms

Edouard GARNIER DE LABAREYRE / System Architect


0/ Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Challenges in programming

 What do you expect from your code ?


 Compile and run without errors
 Solve your problem

 What you should also expect from your code


 Handle marginal situations (aka « robust »)
 Be readable
 Be maintenable
 Be debugable

 A bit of methodology can help


 “Programming patterns are formalized best practices that the programmer can use
to solve common problems when designing an application or system” – Wikipedia

 “Best coding practices are a set of informal rules that the software development
community has learned over time which can help improve the quality of software” –
Wikipedia

1/ Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Presentation outline

1. Clarity
1. Procedures decoupling
2. Comments and readability
3. Output parameter handling

2. Robustness
1. State machine
2. Voted conditions

3. Performance / debugging
1. Debugging probe
2. Integrated profiling tool
3. Parameter shifting

2/ Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Clarity

3/ Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Procedure decoupling

Divide and rule

 Eachprocedure shall be responsible for only one consistent set of


computations
 Could it be done in several separated independent procedures ?
 Could it be done in several steps, involving interesting intermediate values ?

 Examples:
 “Altitude correction / Determination of selected altitude”
 “Holding pattern detection”

 Benefits:
 Smaller code chunks
 Avoid code duplication
 Well identified responsibilities
 Easy maintenance

4/ Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Comments and readability

What do you have in mind ?

 Code shall be commented in a way that explains what your are trying to
achieve, and why
 Explain the main steps of your algorithm
 Provide hints when needed
 Do not comment the obvious

 Prefer code readability over concision


 Because your code will never thank you for being so short

 Benefits:
 Team collaboration
 Easy maintenance

5/ Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Output parameters handling

Do you really know the outputs of your procedure ?

 Do not affect outputs in the middle of your algorithm

 Use internal variables only for your algorithm logic

 Affect AGS parameters at the very end of the procedure

 Benefits:
 Easy maintenance
 Easy debugging

6/ Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Output parameters handling example

Complex logic

Output
assignment

7/ Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Robustness

8/ Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
State machine: when to use it ?

Do you feel your algorithm needs “memory” of what happens over time ?

 Use state machines intensively

 Benefits:
 Allow modelisation of complex behaviors
 Robust at execution
 Easy debugging

 State machines are typically used for problems where there is some stream
of input and the activity that needs to be done at a given moment depends on
previous elements of the stream

 Allow to represent a set of complex rules and conditions in an elegant, bug-


free manner

9/ Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
State machine: what is it ?

Abstract machine, which can be in one of a finite number of states.


Change from one state to another can be done only on specific transitions

IF current state = A and cond1 = true


cond1 THEN next_state = B

IF current state = A and cond3 = true


A THEN next_state = C
B
In other words, the only way to leave
cond3 state A is that cond1 or cond3 is true
cond2

C
Not to be confused
with a flow chart !

10 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
State machine: what is it ?

Transitions from one state to another can trigger some actions

Memorize T
cond1
IF current state = A AND next_state = B
THEN t_mem = T
A B IF current state = B AND next_state = A
THEN counter = 0
cond3
cond2

C Reset counter

11 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
State machine: how to implement it ?

 Start by defining the expected logic on paper

 Implement the logic with the following pattern

 Compute all transitions


 Compute next state
 Trigger actions
 Prepare next iteration

 Run it and monitor:


 current state
 all transitions

12 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
State machine: how to implement it ?

 Set initial state

 Compute all transitions

13 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
State machine: how to implement it ?

 Compute next state

14 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
State machine: how to implement it ?

 Trigger actions

 Prepare next iteration

15 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
State machine applications in Cobalt

 Flight phases
 From/to airport and runway
 Top of climb / top of descent
 Turn detection
 Flare detection
 TCAS / GPWS
 Unstable approach
 Non compliant approaches
 Holding pattern detection
 Many events and measures with simple 3-states state machines
…

16 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Flight phase state machine

17 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Voted conditions

Several conditions can contribute to one single boolean

 Useseveral conditions to compute one single boolean with voting


mechanism

 Benefits:
 Robust at execution

 Example: aircraft moving on ground


 Ground speed > 3 knots
 Heading variation > 2 deg / sec Pick two
 Amplitude of vertical acceleration > 0.05

18 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Performance / debugging

19 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Debugging probe

You should not modify the code you want to test, just to test it

 Capture each variable you want to debug at the very end of the procedure

 Benefits:
 Safe debugging

20 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Integrated profiling tool

During analysis, few procedures consume most CPU time

 Use integrated profiling tool to know which procedures consume the most

 Work on optimizing the most consuming ones

 Benefits:
 Improve analysis performance

21 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Integrated profiling tool example

C:\Program Files\SAGEM\AGS\AGSMono\CONFIG\db_profile\<dbversion>.txt

DB version 753, compiled on 2014-12-24 10:04:57.610000


File analysed: C:\Program Files (x86)\SAGEM\AGS\AGSMono\Work\RD009517.SAV
Time spent in analysis: 2865 ms
Time spent in procedures: 1434 ms ( 50.1 %)
---
Procedure 1010 ( ADD ): 350 ms ( 24.4 %)
Procedure 1004 ( ADD ): 193 ms ( 13.5 %)
Procedure 1028 ( ADD ): 168 ms ( 11.7 %)
Procedure 1032 ( ADD ): 163 ms ( 11.4 %)
Procedure 1030 ( ADD ): 143 ms ( 10.0 %)
Procedure 2000 ( ADD ): 74 ms ( 5.2 %)
Procedure 1000 ( ADD ): 42 ms ( 2.9 %)
Procedure 7002 ( ADD ): 37 ms ( 2.6 %)
Procedure 7000 ( ADD ): 31 ms ( 2.2 %)
Procedure 1014 ( ADD ): 31 ms ( 2.2 %)
Procedure 1016 ( ADD ): 28 ms ( 2.0 %)
Procedure 1012 ( ADD ): 22 ms ( 1.5 %)
Procedure 4000 ( OPE ): 11 ms ( 0.8 %)
Procedure 1530 ( ADD ): 10 ms ( 0.7 %)
Procedure 4154 ( OPE ): 7 ms ( 0.5 %)
Procedure 3024 ( ADD ): 6 ms ( 0.4 %)

22 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Parameter shifting

Using a gliding window ?

 Limit calls to value in the future and shift parameters at each iteration

 Benefits:
 Improve analysis performance
5 values, 2 in the past, 2 in the future
Naïve solution: Improved solution:
PARAM(2)
PARAM(-2)
PARAM(-1)
Step i p2 p1 c f1 f2
PARAM(2)
PARAM
PARAM(1) p2 p1 c f1 f2
Step i + 1
PARAM(2)
23 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Parameter shifting example

24 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.
Questions

Thank you for your attention !

Happy AGS programming ;-)

25 / Ce document et les informations qu’il contient sont la propriété de Sagem. Ils ne doivent pas être copiés ni
communiqués à un tiers sans l’autorisation préalable et écrite de Sagem.
Sagem est le nom commercial de la société Sagem Défense Sécurité.

You might also like