with Assert ;
with Gada.Text_IO ;
with Avion_Sol, INSA_Air ;
with Train, Tour ;
procedure Mission2B is
package Txt renames GAda.Text_IO ;
package IA renames INSA_Air ;
package AS renames Avion_Sol ;
Angle_Tour : constant Float := 360.0 ;
Demi_Tour : constant Float := Angle_Tour / 2.0 ;
function Delta_Cap (Cap_Actuel : Float ; Cap_Voulu : Float) return Float is
Resultat : Float ;
begin
Resultat := Cap_Voulu - Cap_Actuel ;
if Resultat > Demi_Tour then Resultat := Resultat - Angle_Tour ;
elsif Resultat < - Demi_Tour then Resultat := Resultat + Angle_Tour ;
end if ;
return Resultat ;
end Delta_Cap ;
procedure Tester_Delta_Cap (CapA : Float ; CapV : Float) is
begin
Txt.Put_Line (Aff => "Delta_Cap " & Float'Image( CapA ) & ", " &
Float'Image( CapV ) & " = " &
Float'Image( Delta_Cap(Cap_Actuel => CapA, Cap_Voulu => CapV)) ) ;
end Tester_Delta_Cap ;
function Caps_Egaux (Cap1 : Float ; Cap2 : Float) return Boolean is
Tolerance : constant Float := 5.0 ;
begin
return abs (Delta_Cap ( Cap_Actuel => Cap1, Cap_Voulu => Cap2)) < Tolerance ;
end Caps_Egaux ;
procedure Tester_Caps_Egaux (Cap1, Cap2 : Float) is
begin
Txt.Put (Aff => "Les caps " & Float'Image(Cap1) & " et " &
Float'Image(Cap2) & " ") ;
if Caps_Egaux(Cap1, Cap2) then
Txt.Put_Line (Aff => " sont égaux (à 5 degrés près).") ;
else
Txt.Put_Line (Aff => " ne sont pas égaux (à 5 degrés près).") ;
end if ;
end Tester_Caps_Egaux ;
procedure Tests_Unitaires is
begin
Tester_Delta_Cap (CapA => 0.0, CapV => 45.0) ;
Tester_Delta_Cap (CapA => 45.0, CapV => 0.0) ;
Tester_Delta_Cap (CapA => 350.0, CapV => 10.0) ;
Tester_Delta_Cap (CapA => 10.0, CapV => 350.0) ;
Tester_Delta_Cap (CapA => 30.0, CapV => 285.0) ;
Tester_Caps_Egaux (Cap1 => 0.0, Cap2 => 10.0) ;
Tester_Caps_Egaux (Cap1 => 10.0, Cap2 => 0.0) ;
Tester_Caps_Egaux (Cap1 => 170.0, Cap2 => 172.0) ;
Tester_Caps_Egaux (Cap1 => 172.0, Cap2 => 170.0) ;
Tester_Caps_Egaux (Cap1 => 25.0, Cap2 => 359.0) ;
Tester_Caps_Egaux (Cap1 => 359.0, Cap2 => 25.0) ;
Tester_Caps_Egaux (Cap1 => 358.0, Cap2 => 2.0) ;
Tester_Caps_Egaux (Cap1 => 2.0, Cap2 => 358.0) ;
end Tests_Unitaires ;
procedure Orienter_Au_Sol (Cible : Float) is
begin
Assert.Failif (Cond => Cible < 0.0 or Cible > Angle_Tour,
Message => "Orienter_Au_Sol : cap incorrect = " & Float'Image(Cible)) ;
IA.Regler_Reacteur (Force => 1) ;
while not (Caps_Egaux (Cap1 => Cible, Cap2 => IA.Cap_Courant)) loop
if Delta_Cap (Cap_Actuel => IA.Cap_Courant, Cap_Voulu => Cible) < 0.0 then
Train.Positionner_A_Gauche ;
else
Train.Positionner_A_Droite ;
end if ;
end loop ;
Train.Positionner_A_Zero ;
AS.Freiner ;
end Orienter_Au_Sol ;
procedure Tester_Cap is
Nord : constant Float := 0.0 ;
Sud : constant Float := 180.0 ;
Est : constant Float := 90.0 ;
Ouest : constant Float := 270.0 ;
begin
Tour.Attendre_Autorisation_Roulage ;
AS.Rouler_Vers (Dest => 'L') ;
AS.Rouler_Vers (Dest => 'M') ;
AS.Freiner ;
Orienter_Au_Sol(Cible => Nord) ;
AS.Attendre_Entree ;
Orienter_Au_Sol(Cible => Est) ;
AS.Attendre_Entree ;
Orienter_Au_Sol(Cible => Ouest) ;
AS.Attendre_Entree ;
Orienter_Au_Sol(Cible => Sud) ;
AS.Attendre_Entree ;
AS.Rouler_Vers (Dest => 'M') ;
AS.Rouler_Vers (Dest => 'L') ;
AS.Rouler_Vers (Dest => 'K') ;
end Tester_Cap ;
begin
Tester_Cap ;
end Mission2B ;