Anais La M et Bruno La M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mission2b.adb 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. with GAda.Text_IO ;
  2. with INSA_Air;
  3. with Train;
  4. with Avion_Sol;
  5. with Assert;
  6. procedure Mission2b is
  7. --
  8. -- Mission 2, partie 1 : fonction Delta_Cap
  9. --
  10. -- Cette fonction Delta_Cap est incorrecte.
  11. -- À vous de corriger son algorithme.
  12. --
  13. function Delta_Cap(Cap_Actuel : Float ; Cap_Voulu : Float) return Float is
  14. Ecart_Angle : Float ;
  15. begin
  16. Ecart_Angle := Cap_Voulu - Cap_Actuel ;
  17. if Ecart_Angle < -180.0 then
  18. Ecart_Angle := Ecart_Angle + 360.0 ;
  19. end if ;
  20. if Ecart_Angle > 180.0 then
  21. Ecart_Angle := Ecart_Angle -360.0;
  22. end if;
  23. return Ecart_Angle ;
  24. end Delta_Cap ;
  25. --
  26. -- Mission 2, partie 1 : procédure de test de Delta_Cap
  27. --
  28. -- Cette procédure est incomplète, à vous de la rendre utile.
  29. --
  30. procedure Tester_Delta_Cap(CapA : Float ; CapV : Float) is
  31. Ecart_Angle: Float;
  32. begin
  33. Ecart_Angle := Delta_Cap(Cap_Actuel => CapA, Cap_Voulu => CapV);
  34. GAda.Text_IO.Put_Line (Aff => "Le cap actuel vaut" & Float'Image(CapA) & " Le cap Voulut vaut:" & Float'Image(CapV) & " Delta Cap vaut:" & Float'Image(Ecart_Angle)) ;
  35. end Tester_Delta_Cap ;
  36. --
  37. -- Mission 2, partie 2 : fonction Caps_Egaux
  38. function Caps_Egaux(Cap1:Float; Cap2:Float) return Boolean is
  39. Dif_Cap: Float;
  40. begin
  41. Dif_Cap:= abs((Delta_Cap(Cap1 , Cap2)));
  42. return Dif_Cap <= 5.0;
  43. end Caps_Egaux;
  44. --
  45. -- Mission 2, partie 2 : procédure de test de Caps_Egaux
  46. procedure Tester_Caps_Egaux(Cap1: Float; Cap2: Float) is
  47. Rep: Boolean;
  48. begin
  49. Rep := Caps_Egaux(Cap1 , Cap2);
  50. GAda.Text_IO.Put_Line(Aff => "Ecart:" & Boolean'Image(Rep));
  51. end Tester_Caps_Egaux;
  52. --
  53. -- Mission 2, parties 1 et 2 : réalisation de plusieurs tests
  54. --
  55. procedure Tests_Unitaires is
  56. begin
  57. Tester_Delta_Cap (CapA => 0.0, CapV => 45.0) ;
  58. Tester_Delta_Cap (CapA => 45.0, CapV => 0.0) ;
  59. Tester_Delta_Cap (CapA => 350.0, CapV => 10.0) ;
  60. Tester_Delta_Cap (CapA => 10.0, CapV => 350.0) ;
  61. Tester_Delta_Cap (CapA => 30.0, CapV => 285.0) ;
  62. Tester_Delta_Cap (CapA => 178.0, CapV => 182.0) ;
  63. Tester_Caps_Egaux(Cap1 => 0.0, Cap2 => 5.0) ;
  64. Tester_Caps_Egaux(Cap1 => 2.0, Cap2 => 359.0) ;
  65. Tester_Caps_Egaux(Cap1 => 350.0, Cap2 => 10.0) ;
  66. Tester_Caps_Egaux(Cap1 => 10.0, Cap2 => 350.0) ;
  67. Tester_Caps_Egaux(Cap1 => 178.0, Cap2 => 182.0) ;
  68. -- Ajouter vos propres tests unitaires
  69. end Tests_Unitaires ;
  70. --
  71. -- Mission 2, partie 3 : procédure Orienter_au_sol
  72. procedure Orienter_Au_Sol(Cap: Float) is
  73. Cap_Bon: Boolean;
  74. Delt_Cap: Float;
  75. begin
  76. Cap_Bon:= (Cap < 0.0) or (Cap > 360.0);
  77. Assert.Failif(Cap_Bon , "Le cap demandé ne correspond pas aux attentes");
  78. INSA_Air.Regler_Reacteur(1);
  79. while not Caps_Egaux(Cap , INSA_Air.Cap_Courant) loop
  80. Delt_Cap:= Delta_Cap(INSA_Air.Cap_Courant , Cap);
  81. if Delt_Cap <0.0 then
  82. Train.Positionner_A_Gauche;
  83. elsif Delt_Cap = 0.0 then
  84. Train.Positionner_A_Zero;
  85. else
  86. Train.Positionner_A_Droite;
  87. end if;
  88. INSA_Air.Attendre(0.05);
  89. end loop;
  90. Avion_Sol.Freiner;
  91. end Orienter_Au_Sol;
  92. --
  93. --
  94. -- Mission 2, partie 3 : procédure Tester_Cap
  95. --
  96. procedure Tester_Cap is
  97. begin
  98. Avion_Sol.Rouler_Vers('L');
  99. Avion_Sol.Rouler_Vers('M');
  100. Avion_Sol.Freiner;
  101. Avion_Sol.Attendre_Entree;
  102. Mission2b.Orienter_Au_Sol(0.0);
  103. Avion_Sol.Attendre_Entree;
  104. Mission2b.Orienter_Au_Sol(90.0);
  105. Avion_Sol.Attendre_Entree;
  106. Mission2b.Orienter_Au_Sol(270.0);
  107. Avion_Sol.Attendre_Entree;
  108. Mission2b.Orienter_Au_Sol(180.0);
  109. Avion_Sol.Attendre_Entree;
  110. Avion_Sol.Rouler_Vers('L');
  111. Avion_Sol.Rouler_Vers('K');
  112. end Tester_Cap;
  113. --
  114. -- Mission 2, partie 4 : procédure Orienter_en_vol
  115. --
  116. --
  117. -- Mission 2, partie 4 : procédure Realiser_Vol_Demo
  118. --
  119. begin
  120. -- Effectuer tous les tests unitaires de Delta_Cap et Caps_Egaux
  121. Tests_Unitaires ;
  122. Tester_Cap;
  123. end Mission2b ;