|
| 1 | +-------------------------------------------------------------------------------- |
| 2 | +-- Thr_Firing_Remainder Component Implementation Body |
| 3 | +-------------------------------------------------------------------------------- |
| 4 | + |
| 5 | +with Thr_Force_Cmd; |
| 6 | +with Thr_On_Time_Cmd; |
| 7 | +with Thr_Firing_Remainder_Force_Cmd.C; |
| 8 | +with Thr_Firing_Remainder_On_Time_Cmd.C; |
| 9 | +with Algorithm_Wrapper_Util; |
| 10 | + |
| 11 | +package body Component.Thr_Firing_Remainder.Implementation is |
| 12 | + |
| 13 | + -- Number of thrusters in the system (8-element data products vs 36-element C API) |
| 14 | + Num_Thrusters : constant := 8; |
| 15 | + |
| 16 | + -------------------------------------------------- |
| 17 | + -- Subprogram for implementation init method: |
| 18 | + -------------------------------------------------- |
| 19 | + -- Initializes the thruster firing remainder algorithm. |
| 20 | + overriding procedure Init (Self : in out Instance) is |
| 21 | + begin |
| 22 | + -- Allocate C++ class on the heap |
| 23 | + Self.Alg := Create; |
| 24 | + end Init; |
| 25 | + |
| 26 | + not overriding procedure Destroy (Self : in out Instance) is |
| 27 | + begin |
| 28 | + -- Free the C++ heap data. |
| 29 | + Destroy (Self.Alg); |
| 30 | + end Destroy; |
| 31 | + |
| 32 | + not overriding procedure Configure_Thrusters ( |
| 33 | + Self : in out Instance; |
| 34 | + Config : access constant Thr_Firing_Remainder_Array_Config) |
| 35 | + is |
| 36 | + begin |
| 37 | + Set_Thrusters (Self.Alg, Config); |
| 38 | + end Configure_Thrusters; |
| 39 | + |
| 40 | + --------------------------------------- |
| 41 | + -- Invokee connector primitives: |
| 42 | + --------------------------------------- |
| 43 | + -- Run the algorithm up to the current time. |
| 44 | + overriding procedure Tick_T_Recv_Sync (Self : in out Instance; Arg : in Tick.T) is |
| 45 | + use Data_Product_Enums; |
| 46 | + use Data_Product_Enums.Data_Dependency_Status; |
| 47 | + use Algorithm_Wrapper_Util; |
| 48 | + |
| 49 | + -- Grab data dependencies: |
| 50 | + Force_Dep : Thr_Force_Cmd.T; |
| 51 | + Force_Status : constant Data_Dependency_Status.E := |
| 52 | + Self.Get_Thruster_Force_Cmd (Value => Force_Dep, Stale_Reference => Arg.Time); |
| 53 | + begin |
| 54 | + -- Update the parameters: |
| 55 | + Self.Update_Parameters; |
| 56 | + |
| 57 | + if Is_Dep_Status_Success (Force_Status) then |
| 58 | + declare |
| 59 | + -- Unpack 8-element dependency |
| 60 | + Force_Dep_U : constant Thr_Force_Cmd.U := Thr_Force_Cmd.Unpack (Force_Dep); |
| 61 | + |
| 62 | + -- Build 36-element C input (zeroed, then copy 8 thruster values) |
| 63 | + Force_36 : aliased Thr_Firing_Remainder_Force_Cmd.C.U_C := (Thr_Force => [others => 0.0]); |
| 64 | + begin |
| 65 | + for I in 0 .. Num_Thrusters - 1 loop |
| 66 | + Force_36.Thr_Force (I) := Force_Dep_U.Thr_Force (I); |
| 67 | + end loop; |
| 68 | + |
| 69 | + declare |
| 70 | + -- Call the C algorithm |
| 71 | + On_Time_36 : constant Thr_Firing_Remainder_On_Time_Cmd.C.U_C := |
| 72 | + Update (Self.Alg, Force_36'Unchecked_Access); |
| 73 | + |
| 74 | + -- Extract first 8 elements for output |
| 75 | + On_Time_Result : Thr_On_Time_Cmd.U := (On_Time_Request => [others => 0.0]); |
| 76 | + begin |
| 77 | + for I in 0 .. Num_Thrusters - 1 loop |
| 78 | + On_Time_Result.On_Time_Request (I) := On_Time_36.On_Time_Request (I); |
| 79 | + end loop; |
| 80 | + |
| 81 | + Self.Data_Product_T_Send (Self.Data_Products.On_Time_Cmd ( |
| 82 | + Arg.Time, |
| 83 | + Thr_On_Time_Cmd.Pack (On_Time_Result) |
| 84 | + )); |
| 85 | + end; |
| 86 | + end; |
| 87 | + end if; |
| 88 | + end Tick_T_Recv_Sync; |
| 89 | + |
| 90 | + -- The parameter update connector. |
| 91 | + overriding procedure Parameter_Update_T_Modify (Self : in out Instance; Arg : in out Parameter_Update.T) is |
| 92 | + begin |
| 93 | + -- Process the parameter update, staging or fetching parameters as requested. |
| 94 | + Self.Process_Parameter_Update (Arg); |
| 95 | + end Parameter_Update_T_Modify; |
| 96 | + |
| 97 | + ----------------------------------------------- |
| 98 | + -- Parameter handlers: |
| 99 | + ----------------------------------------------- |
| 100 | + -- This procedure is called when the parameters of a component have been updated. |
| 101 | + overriding procedure Update_Parameters_Action (Self : in out Instance) is |
| 102 | + begin |
| 103 | + -- Set algorithm configuration from parameters. |
| 104 | + Set_Thr_Min_Fire_Time (Self.Alg, Self.Thr_Min_Fire_Time.Value); |
| 105 | + Set_Control_Period (Self.Alg, Self.Control_Period.Value); |
| 106 | + Set_On_Time_Saturation_Factor (Self.Alg, Self.On_Time_Saturation_Factor.Value); |
| 107 | + Set_Thrust_Pulsing_Regime (Self.Alg, |
| 108 | + Thr_Firing_Remainder_Pulsing_Regime'Val (Natural (Self.Thrust_Pulsing_Regime.Value))); |
| 109 | + end Update_Parameters_Action; |
| 110 | + |
| 111 | + -- Invalid Parameter handler. This procedure is called when a parameter's type is found to be invalid: |
| 112 | + overriding procedure Invalid_Parameter (Self : in out Instance; Par : in Parameter.T; Errant_Field_Number : in Unsigned_32; Errant_Field : in Basic_Types.Poly_Type) is |
| 113 | + pragma Annotate (GNATSAS, Intentional, "subp always fails", "intentional assertion"); |
| 114 | + begin |
| 115 | + -- None of the parameters should be invalid in this case. |
| 116 | + pragma Assert (False); |
| 117 | + end Invalid_Parameter; |
| 118 | + |
| 119 | + ----------------------------------------------- |
| 120 | + -- Data dependency handlers: |
| 121 | + ----------------------------------------------- |
| 122 | + -- Invalid data dependency handler. This procedure is called when a data dependency's id or length are found to be invalid: |
| 123 | + overriding procedure Invalid_Data_Dependency (Self : in out Instance; Id : in Data_Product_Types.Data_Product_Id; Ret : in Data_Product_Return.T) is |
| 124 | + pragma Annotate (GNATSAS, Intentional, "subp always fails", "intentional assertion"); |
| 125 | + begin |
| 126 | + -- None of the data dependencies should be invalid in this case. |
| 127 | + pragma Assert (False); |
| 128 | + end Invalid_Data_Dependency; |
| 129 | + |
| 130 | +end Component.Thr_Firing_Remainder.Implementation; |
0 commit comments