Skip to content

Commit ceffacb

Browse files
authored
Merge pull request #12 from Jbsco/thrFiringRemainder
Thr firing remainder
2 parents 4c78165 + be3a7b9 commit ceffacb

21 files changed

+1049
-0
lines changed

src/components/thr_firing_remainder/.all_path

Whitespace-only changes.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
--------------------------------------------------------------------------------
2+
-- Thr_Firing_Remainder Component Implementation Spec
3+
--------------------------------------------------------------------------------
4+
5+
-- Includes:
6+
with Tick;
7+
with Thr_Firing_Remainder_Algorithm_C; use Thr_Firing_Remainder_Algorithm_C;
8+
9+
-- Thruster firing remainder algorithm converts thruster force commands to on-time
10+
-- commands using pulse-width modulation with remainder tracking.
11+
package Component.Thr_Firing_Remainder.Implementation is
12+
13+
-- The component class instance record:
14+
type Instance is new Thr_Firing_Remainder.Base_Instance with private;
15+
16+
--------------------------------------------------
17+
-- Subprogram for implementation init method:
18+
--------------------------------------------------
19+
-- Initializes the thruster firing remainder algorithm.
20+
overriding procedure Init (Self : in out Instance);
21+
not overriding procedure Destroy (Self : in out Instance);
22+
not overriding procedure Configure_Thrusters (
23+
Self : in out Instance;
24+
Config : access constant Thr_Firing_Remainder_Array_Config);
25+
26+
private
27+
28+
-- The component class instance record:
29+
type Instance is new Thr_Firing_Remainder.Base_Instance with record
30+
Alg : Thr_Firing_Remainder_Algorithm_Access := null;
31+
end record;
32+
33+
---------------------------------------
34+
-- Set Up Procedure
35+
---------------------------------------
36+
-- Null method which can be implemented to provide some component
37+
-- set up code. This method is generally called by the assembly
38+
-- main.adb after all component initialization and tasks have been started.
39+
-- Some activities need to only be run once at startup, but cannot be run
40+
-- safely until everything is up and running, ie. command registration, initial
41+
-- data product updates. This procedure should be implemented to do these things
42+
-- if necessary.
43+
overriding procedure Set_Up (Self : in out Instance) is null;
44+
45+
---------------------------------------
46+
-- Invokee connector primitives:
47+
---------------------------------------
48+
-- Run the algorithm up to the current time.
49+
overriding procedure Tick_T_Recv_Sync (Self : in out Instance; Arg : in Tick.T);
50+
-- The parameter update connector.
51+
overriding procedure Parameter_Update_T_Modify (Self : in out Instance; Arg : in out Parameter_Update.T);
52+
53+
---------------------------------------
54+
-- Invoker connector primitives:
55+
---------------------------------------
56+
-- This procedure is called when a Data_Product_T_Send message is dropped due to a full queue.
57+
overriding procedure Data_Product_T_Send_Dropped (Self : in out Instance; Arg : in Data_Product.T) is null;
58+
59+
-----------------------------------------------
60+
-- Parameter primitives:
61+
-----------------------------------------------
62+
-- Description:
63+
-- Parameters for the Thr Firing Remainder component
64+
65+
-- Invalid parameter handler. This procedure is called when a parameter's type is found to be invalid:
66+
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);
67+
-- This procedure is called when the parameters of a component have been updated. The default implementation of this
68+
-- subprogram in the implementation package is a null procedure. However, this procedure can, and should be implemented if
69+
-- something special needs to happen after a parameter update. Examples of this might be copying certain parameters to
70+
-- hardware registers, or performing other special functionality that only needs to be performed after parameters have
71+
-- been updated.
72+
overriding procedure Update_Parameters_Action (Self : in out Instance);
73+
-- This function is called when the parameter operation type is "Validate". The default implementation of this
74+
-- subprogram in the implementation package is a function that returns "Valid". However, this function can, and should be
75+
-- overridden if something special needs to happen to further validate a parameter. Examples of this might be validation of
76+
-- certain parameters beyond individual type ranges, or performing other special functionality that only needs to be
77+
-- performed after parameters have been validated. Note that range checking is performed during staging, and does not need
78+
-- to be implemented here.
79+
overriding function Validate_Parameters (
80+
Self : in out Instance;
81+
Thr_Min_Fire_Time : in Packed_F32.U;
82+
Control_Period : in Packed_F32.U;
83+
On_Time_Saturation_Factor : in Packed_F32.U;
84+
Thrust_Pulsing_Regime : in Packed_Byte.U
85+
) return Parameter_Validation_Status.E is (Parameter_Validation_Status.Valid);
86+
87+
-----------------------------------------------
88+
-- Data dependency primitives:
89+
-----------------------------------------------
90+
-- Description:
91+
-- Data dependencies for the Thr Firing Remainder component.
92+
-- Function which retrieves a data dependency.
93+
-- The default implementation is to simply call the Data_Product_Fetch_T_Request connector. Change the implementation if this component
94+
-- needs to do something different.
95+
overriding function Get_Data_Dependency (Self : in out Instance; Id : in Data_Product_Types.Data_Product_Id) return Data_Product_Return.T is (Self.Data_Product_Fetch_T_Request ((Id => Id)));
96+
97+
-- Invalid data dependency handler. This procedure is called when a data dependency's id or length are found to be invalid:
98+
overriding procedure Invalid_Data_Dependency (Self : in out Instance; Id : in Data_Product_Types.Data_Product_Id; Ret : in Data_Product_Return.T);
99+
100+
end Component.Thr_Firing_Remainder.Implementation;

0 commit comments

Comments
 (0)