1. -- 
  2. -- Uwe R. Zimmer, Australia, 2013 
  3. -- 
  4.  
  5. with Ada.Task_Identification;    use Ada.Task_Identification; 
  6.  
  7. with Swarm_Configuration;        use Swarm_Configuration; 
  8. with Swarm_Control;              use Swarm_Control; 
  9. with Swarm_Data;                 use Swarm_Data; 
  10. with Swarm_Structures;           use Swarm_Structures; 
  11.  
  12. package body Vehicle_Interface is 
  13.  
  14.    use Swarm_Vectors; 
  15.  
  16.    ----------- 
  17.    -- State -- 
  18.    ----------- 
  19.  
  20.    function Position return Positions is 
  21.      (Swarm_Monitor.Position (Current_Task).all.Read); 
  22.  
  23.    function Velocity return Velocities is 
  24.      (Swarm_Monitor.Velocity (Current_Task).all.Read); 
  25.  
  26.    function Acceleration return Accelerations is 
  27.      (Swarm_Monitor.Acceleration (Current_Task).all.Read); 
  28.  
  29.    -------------- 
  30.    -- Steering -- 
  31.    -------------- 
  32.  
  33.    procedure Set_Destination (V : Vector_3D) is 
  34.  
  35.    begin 
  36.       Swarm_Monitor.Controls (Current_Task).all.Set_Steering (V); 
  37.    end Set_Destination; 
  38.  
  39.    -------------- 
  40.    -- Thruttle -- 
  41.    -------------- 
  42.  
  43.    procedure Set_Throttle (T : Throttle_T) is 
  44.  
  45.    begin 
  46.       Swarm_Monitor.Controls (Current_Task).all.Set_Throttle (T); 
  47.    end Set_Throttle; 
  48.  
  49.    function Throttle_Is_On_Idle return Boolean is 
  50.      (Swarm_Monitor.Controls (Current_Task).all.Read_Throttle = Idle_Throttle); 
  51.  
  52.    --------------- 
  53.    -- Messaging -- 
  54.    --------------- 
  55.  
  56.    procedure Send (Message : Inter_Vehicle_Messages) is 
  57.  
  58.    begin 
  59.       Swarm_Monitor.Comms (Current_Task).all.Send (Message); 
  60.    end Send; 
  61.  
  62.    procedure Receive (Message : out Inter_Vehicle_Messages) is 
  63.  
  64.    begin 
  65.       Swarm_Monitor.Comms (Current_Task).all.Receive (Message); 
  66.    end Receive; 
  67.  
  68.    function Messages_Waiting return Boolean is 
  69.      (Swarm_Monitor.Comms (Current_Task).all.Has_Incoming_Messages); 
  70.  
  71.    ------------ 
  72.    -- Energy -- 
  73.    ------------ 
  74.  
  75.    function Current_Charge return Vehicle_Charges is 
  76.      (Swarm_Monitor.Charge (Current_Task).Level); 
  77.  
  78.    function Current_Discharge_Per_Sec return Real is 
  79.      (Charging_Setup.Constant_Discharge_Rate_Per_Sec + Charging_Setup.Propulsion_Discharge_Rate_Per_Sec * abs (Acceleration)); 
  80.  
  81.    function Energy_Globes_Around return Energy_Globes is 
  82.  
  83.       Globes_Found          : Natural                         := 0; 
  84.       Globes_Detected       : array (Globes'Range) of Boolean := (others => False); 
  85.       This_Element_Position : constant Positions              := Position; 
  86.  
  87.    begin 
  88.       for Globe_Ix in Globes'Range loop 
  89.          if abs (This_Element_Position - Globes (Globe_Ix).Position.all.Read) <= Energy_Globe_Detection then 
  90.             Globes_Detected (Globe_Ix) := True; 
  91.             Globes_Found := Globes_Found + 1; 
  92.          end if; 
  93.       end loop; 
  94.  
  95.       declare 
  96.          Found_Globes : Energy_Globes (1 .. Globes_Found); 
  97.          Found_Globes_Ix : Natural := Globes'First; 
  98.       begin 
  99.          for Globe_Ix in Globes'Range loop 
  100.             if Globes_Detected (Globe_Ix) then 
  101.                Found_Globes (Found_Globes_Ix) := (Position => Globes (Globe_Ix).Position.all.Read, 
  102.                                                   Velocity => Globes (Globe_Ix).Velocity.all.Read); 
  103.                Found_Globes_Ix := Found_Globes_Ix + 1; 
  104.             end if; 
  105.          end loop; 
  106.          return Found_Globes; 
  107.       end; 
  108.    end Energy_Globes_Around; 
  109.  
  110.    -- 
  111.  
  112.    procedure Wait_For_Next_Physics_Update is 
  113.  
  114.    begin 
  115.       Simulator_Tick.Wait_For_Next_Tick; 
  116.    end Wait_For_Next_Physics_Update; 
  117.  
  118.    ----------------- 
  119.    -- Termination -- 
  120.    ----------------- 
  121.  
  122.    protected body Flight_Termination is 
  123.  
  124.       entry Stop when True is 
  125.  
  126.       begin 
  127.          requeue Swarm_Monitor.Process_abort.all.Wait with abort; 
  128.       end Stop; 
  129.  
  130.    end Flight_Termination; 
  131.  
  132.    -- 
  133.  
  134. end Vehicle_Interface;