Skip to content

Commit cf2d3a0

Browse files
committed
Add bodyRateMiscompare component test
1 parent 26816e9 commit cf2d3a0

7 files changed

+510
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
description: This is a unit test suite for the Body Rate Miscompare component
3+
tests:
4+
- name: Test
5+
description: Run algorithm to ensure integration is sound.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
--------------------------------------------------------------------------------
2+
-- Body_Rate_Miscompare Tests Body
3+
--------------------------------------------------------------------------------
4+
5+
with Basic_Assertions; use Basic_Assertions;
6+
with Nav_Att;
7+
with Body_Rate_Fault;
8+
with Packed_F32x3.Assertion; use Packed_F32x3.Assertion;
9+
with Body_Rate_Fault.Assertion; use Body_Rate_Fault.Assertion;
10+
11+
package body Body_Rate_Miscompare_Tests.Implementation is
12+
13+
-------------------------------------------------------------------------
14+
-- Fixtures:
15+
-------------------------------------------------------------------------
16+
17+
overriding procedure Set_Up_Test (Self : in out Instance) is
18+
begin
19+
-- Allocate heap memory to component:
20+
Self.Tester.Init_Base;
21+
22+
-- Make necessary connections between tester and component:
23+
Self.Tester.Connect;
24+
25+
-- Call component init here.
26+
Self.Tester.Component_Instance.Init;
27+
28+
-- Call the component set up method that the assembly would normally call.
29+
Self.Tester.Component_Instance.Set_Up;
30+
end Set_Up_Test;
31+
32+
overriding procedure Tear_Down_Test (Self : in out Instance) is
33+
begin
34+
-- Free component heap:
35+
Self.Tester.Component_Instance.Destroy;
36+
Self.Tester.Final_Base;
37+
end Tear_Down_Test;
38+
39+
-------------------------------------------------------------------------
40+
-- Tests:
41+
-------------------------------------------------------------------------
42+
43+
-- Run algorithm to ensure integration is sound.
44+
overriding procedure Test (Self : in out Instance) is
45+
T : Component.Body_Rate_Miscompare.Implementation.Tester.Instance_Access renames Self.Tester;
46+
47+
-- Test data based on Python test
48+
type Test_Vector is record
49+
Imu_Angular_Velocity : Packed_F32x3.T;
50+
St_Angular_Velocity : Packed_F32x3.T;
51+
Expected_Angular_Velocity : Packed_F32x3.T;
52+
Expected_Fault : Boolean;
53+
end record;
54+
55+
-- Default threshold is 1.0 rad/s
56+
-- Test 1: Nominal - star tracker and IMU agree (diff < threshold)
57+
-- Test 2: Off-nominal - star tracker and IMU disagree (diff > threshold), output should be IMU rate
58+
Test_Cases : constant array (1 .. 2) of Test_Vector := [
59+
-- Nominal: ST rate close to IMU rate, output should be ST rate
60+
(Imu_Angular_Velocity => [-0.1, 0.2, -0.3],
61+
St_Angular_Velocity => [-0.09, 0.21, -0.29],
62+
Expected_Angular_Velocity => [-0.09, 0.21, -0.29],
63+
Expected_Fault => False),
64+
-- Off-nominal: ST rate far from IMU rate, output should be IMU rate
65+
(Imu_Angular_Velocity => [-0.1, 0.2, -0.3],
66+
St_Angular_Velocity => [1.9, 2.2, 1.7],
67+
Expected_Angular_Velocity => [-0.1, 0.2, -0.3],
68+
Expected_Fault => True)
69+
];
70+
begin
71+
for I in Test_Cases'Range loop
72+
-- Set IMU sensor body data dependency
73+
T.Imu_Body := (
74+
Dv_Frame_Body => [0.0, 0.0, 0.0],
75+
Accel_Body => [0.0, 0.0, 0.0],
76+
Dr_Frame_Body => [0.0, 0.0, 0.0],
77+
Ang_Vel_Body => Test_Cases (I).Imu_Angular_Velocity
78+
);
79+
80+
-- Set star tracker attitude data dependency
81+
T.Star_Tracker_Attitude := (
82+
Time_Tag => 0.0,
83+
Mrp_Bdy_Inrtl => [0.0, 0.0, 0.0],
84+
Omega_Bn_B => Test_Cases (I).St_Angular_Velocity,
85+
Dcm_Cb => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
86+
);
87+
88+
-- Call algorithm:
89+
T.Tick_T_Send ((Time => T.System_Time, Count => 0));
90+
91+
-- Make sure data products produced:
92+
Natural_Assert.Eq (T.Data_Product_T_Recv_Sync_History.Get_Count, I * 2);
93+
Natural_Assert.Eq (T.Body_Rate_History.Get_Count, I);
94+
Natural_Assert.Eq (T.Rate_Fault_Status_History.Get_Count, I);
95+
96+
-- Check body rate output
97+
declare
98+
Rate_Output : constant Nav_Att.T := T.Body_Rate_History.Get (I);
99+
begin
100+
Packed_F32x3_Assert.Eq (
101+
Rate_Output.Omega_Bn_B,
102+
Test_Cases (I).Expected_Angular_Velocity,
103+
Epsilon => 0.0001
104+
);
105+
end;
106+
107+
-- Check fault status
108+
declare
109+
Fault_Output : constant Body_Rate_Fault.T := T.Rate_Fault_Status_History.Get (I);
110+
begin
111+
Body_Rate_Fault_Assert.Eq (
112+
Fault_Output,
113+
(Fault_Detected => Test_Cases (I).Expected_Fault)
114+
);
115+
end;
116+
end loop;
117+
end Test;
118+
119+
end Body_Rate_Miscompare_Tests.Implementation;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--------------------------------------------------------------------------------
2+
-- Body_Rate_Miscompare Tests Spec
3+
--------------------------------------------------------------------------------
4+
5+
-- This is a unit test suite for the Body Rate Miscompare component
6+
package Body_Rate_Miscompare_Tests.Implementation is
7+
8+
-- Test data and state:
9+
type Instance is new Body_Rate_Miscompare_Tests.Base_Instance with private;
10+
type Class_Access is access all Instance'Class;
11+
12+
private
13+
-- Fixture procedures:
14+
overriding procedure Set_Up_Test (Self : in out Instance);
15+
overriding procedure Tear_Down_Test (Self : in out Instance);
16+
17+
-- Run algorithm to ensure integration is sound.
18+
overriding procedure Test (Self : in out Instance);
19+
20+
-- Test data and state:
21+
type Instance is new Body_Rate_Miscompare_Tests.Base_Instance with record
22+
null;
23+
end record;
24+
end Body_Rate_Miscompare_Tests.Implementation;
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
--------------------------------------------------------------------------------
2+
-- Body_Rate_Miscompare Component Tester Body
3+
--------------------------------------------------------------------------------
4+
5+
-- Includes:
6+
with Parameter;
7+
8+
package body Component.Body_Rate_Miscompare.Implementation.Tester is
9+
10+
---------------------------------------
11+
-- Initialize heap variables:
12+
---------------------------------------
13+
procedure Init_Base (Self : in out Instance) is
14+
begin
15+
-- Initialize tester heap:
16+
-- Connector histories:
17+
Self.Data_Product_Fetch_T_Service_History.Init (Depth => 100);
18+
Self.Data_Product_T_Recv_Sync_History.Init (Depth => 100);
19+
-- Data product histories:
20+
Self.Body_Rate_History.Init (Depth => 100);
21+
Self.Rate_Fault_Status_History.Init (Depth => 100);
22+
end Init_Base;
23+
24+
procedure Final_Base (Self : in out Instance) is
25+
begin
26+
-- Destroy tester heap:
27+
-- Connector histories:
28+
Self.Data_Product_Fetch_T_Service_History.Destroy;
29+
Self.Data_Product_T_Recv_Sync_History.Destroy;
30+
-- Data product histories:
31+
Self.Body_Rate_History.Destroy;
32+
Self.Rate_Fault_Status_History.Destroy;
33+
end Final_Base;
34+
35+
---------------------------------------
36+
-- Test initialization functions:
37+
---------------------------------------
38+
procedure Connect (Self : in out Instance) is
39+
begin
40+
Self.Component_Instance.Attach_Data_Product_Fetch_T_Request (To_Component => Self'Unchecked_Access, Hook => Self.Data_Product_Fetch_T_Service_Access);
41+
Self.Component_Instance.Attach_Data_Product_T_Send (To_Component => Self'Unchecked_Access, Hook => Self.Data_Product_T_Recv_Sync_Access);
42+
Self.Attach_Tick_T_Send (To_Component => Self.Component_Instance'Unchecked_Access, Hook => Self.Component_Instance.Tick_T_Recv_Sync_Access);
43+
Self.Attach_Parameter_Update_T_Provide (To_Component => Self.Component_Instance'Unchecked_Access, Hook => Self.Component_Instance.Parameter_Update_T_Modify_Access);
44+
end Connect;
45+
46+
-- Helper function for returning data dependencies:
47+
function Return_Data_Dependency (Self : in out Instance; Arg : in Data_Product_Fetch.T) return Data_Product_Return.T is
48+
use Data_Product_Types;
49+
use Data_Product_Enums.Fetch_Status;
50+
use Sys_Time;
51+
-- Set default return values. These will be overridden below based on test configuration and
52+
-- the ID requested.
53+
Id_To_Return : Data_Product_Types.Data_Product_Id := Self.Data_Dependency_Return_Id_Override;
54+
Length_To_Return : Data_Product_Types.Data_Product_Buffer_Length_Type := Self.Data_Dependency_Return_Length_Override;
55+
Return_Status : Data_Product_Enums.Fetch_Status.E := Self.Data_Dependency_Return_Status_Override;
56+
Buffer_To_Return : Data_Product_Types.Data_Product_Buffer_Type;
57+
Time_To_Return : Sys_Time.T := Self.Data_Dependency_Timestamp_Override;
58+
begin
59+
-- Determine return data product ID:
60+
if Id_To_Return = 0 then
61+
case Arg.Id is
62+
-- ID for Imu_Body:
63+
when 0 => Id_To_Return := 0;
64+
-- ID for Star_Tracker_Attitude:
65+
when 1 => Id_To_Return := 1;
66+
-- If ID can not be found, then return ID out of range error.
67+
when others =>
68+
if Return_Status = Data_Product_Enums.Fetch_Status.Success then
69+
Return_Status := Data_Product_Enums.Fetch_Status.Id_Out_Of_Range;
70+
end if;
71+
end case;
72+
end if;
73+
74+
-- Determine return data product length:
75+
if Length_To_Return = 0 then
76+
case Arg.Id is
77+
-- Length for Imu_Body:
78+
when 0 => Length_To_Return := Imu_Sensor_Body.Size_In_Bytes;
79+
-- Length for Star_Tracker_Attitude:
80+
when 1 => Length_To_Return := St_Att.Size_In_Bytes;
81+
-- If ID can not be found, then return ID out of range error.
82+
when others =>
83+
if Return_Status = Data_Product_Enums.Fetch_Status.Success then
84+
Return_Status := Data_Product_Enums.Fetch_Status.Id_Out_Of_Range;
85+
end if;
86+
end case;
87+
end if;
88+
89+
-- Determine return timestamp:
90+
if Time_To_Return = (0, 0) then
91+
Time_To_Return := Self.System_Time;
92+
end if;
93+
94+
-- Fill the data product buffer:
95+
if Return_Status = Data_Product_Enums.Fetch_Status.Success then
96+
case Arg.Id is
97+
-- Length for Imu_Body:
98+
when 0 =>
99+
Buffer_To_Return (Buffer_To_Return'First .. Buffer_To_Return'First + Imu_Sensor_Body.Size_In_Bytes - 1) :=
100+
Imu_Sensor_Body.Serialization.To_Byte_Array (Self.Imu_Body);
101+
-- Length for Star_Tracker_Attitude:
102+
when 1 =>
103+
Buffer_To_Return (Buffer_To_Return'First .. Buffer_To_Return'First + St_Att.Size_In_Bytes - 1) :=
104+
St_Att.Serialization.To_Byte_Array (Self.Star_Tracker_Attitude);
105+
-- Do not fill. The ID is not recognized.
106+
when others =>
107+
Return_Status := Data_Product_Enums.Fetch_Status.Id_Out_Of_Range;
108+
end case;
109+
end if;
110+
111+
-- Return the data product with the status:
112+
return (
113+
The_Status => Return_Status,
114+
The_Data_Product => (
115+
Header => (
116+
Time => Time_To_Return,
117+
Id => Id_To_Return,
118+
Buffer_Length => Length_To_Return
119+
),
120+
Buffer => Buffer_To_Return
121+
)
122+
);
123+
end Return_Data_Dependency;
124+
125+
---------------------------------------
126+
-- Invokee connector primitives:
127+
---------------------------------------
128+
-- Fetch a data product item from the database.
129+
overriding function Data_Product_Fetch_T_Service (Self : in out Instance; Arg : in Data_Product_Fetch.T) return Data_Product_Return.T is
130+
To_Return : constant Data_Product_Return.T := Self.Return_Data_Dependency (Arg);
131+
begin
132+
-- Push the argument onto the test history for looking at later:
133+
Self.Data_Product_Fetch_T_Service_History.Push (Arg);
134+
return To_Return;
135+
end Data_Product_Fetch_T_Service;
136+
137+
-- The data product invoker connector
138+
overriding procedure Data_Product_T_Recv_Sync (Self : in out Instance; Arg : in Data_Product.T) is
139+
begin
140+
-- Push the argument onto the test history for looking at later:
141+
Self.Data_Product_T_Recv_Sync_History.Push (Arg);
142+
-- Dispatch the data product to the correct handler:
143+
Self.Dispatch_Data_Product (Arg);
144+
end Data_Product_T_Recv_Sync;
145+
146+
-----------------------------------------------
147+
-- Data product handler primitive:
148+
-----------------------------------------------
149+
-- Description:
150+
-- Data products for the Body Rate Miscompare component.
151+
-- Selected body rate output (star tracker rate if rates agree, IMU rate if they
152+
-- disagree)
153+
overriding procedure Body_Rate (Self : in out Instance; Arg : in Nav_Att.T) is
154+
begin
155+
-- Push the argument onto the test history for looking at later:
156+
Self.Body_Rate_History.Push (Arg);
157+
end Body_Rate;
158+
159+
-- Body rate fault detection status
160+
overriding procedure Rate_Fault_Status (Self : in out Instance; Arg : in Body_Rate_Fault.T) is
161+
begin
162+
-- Push the argument onto the test history for looking at later:
163+
Self.Rate_Fault_Status_History.Push (Arg);
164+
end Rate_Fault_Status;
165+
166+
-----------------------------------------------
167+
-- Special primitives for aiding in the staging,
168+
-- fetching, and updating of parameters
169+
-----------------------------------------------
170+
not overriding function Stage_Parameter (Self : in out Instance; Par : in Parameter.T) return Parameter_Update_Status.E is
171+
use Parameter_Enums.Parameter_Update_Status;
172+
use Parameter_Enums.Parameter_Operation_Type;
173+
Param_Update : Parameter_Update.T := (
174+
Table_Id => 1,
175+
Operation => Stage,
176+
Status => Success,
177+
Param => Par
178+
);
179+
begin
180+
Self.Parameter_Update_T_Provide (Param_Update);
181+
return Param_Update.Status;
182+
end Stage_Parameter;
183+
184+
not overriding function Fetch_Parameter (Self : in out Instance; Id : in Parameter_Types.Parameter_Id; Par : out Parameter.T) return Parameter_Update_Status.E is
185+
use Parameter_Enums.Parameter_Update_Status;
186+
use Parameter_Enums.Parameter_Operation_Type;
187+
Param_Update : Parameter_Update.T := (
188+
Table_Id => 1,
189+
Operation => Fetch,
190+
Status => Success,
191+
Param => (Header => (Id => Id, Buffer_Length => 0), Buffer => [others => 0])
192+
);
193+
begin
194+
-- Set the ID to fetch:
195+
Param_Update.Param.Header.Id := Id;
196+
Self.Parameter_Update_T_Provide (Param_Update);
197+
Par := Param_Update.Param;
198+
return Param_Update.Status;
199+
end Fetch_Parameter;
200+
201+
not overriding function Validate_Parameters (Self : in out Instance) return Parameter_Update_Status.E is
202+
use Parameter_Enums.Parameter_Update_Status;
203+
use Parameter_Enums.Parameter_Operation_Type;
204+
Param_Update : Parameter_Update.T := (
205+
Table_Id => 1,
206+
Operation => Validate,
207+
Status => Success,
208+
Param => ((0, 0), [others => 0])
209+
);
210+
begin
211+
Self.Parameter_Update_T_Provide (Param_Update);
212+
return Param_Update.Status;
213+
end Validate_Parameters;
214+
215+
not overriding function Update_Parameters (Self : in out Instance) return Parameter_Update_Status.E is
216+
use Parameter_Enums.Parameter_Update_Status;
217+
use Parameter_Enums.Parameter_Operation_Type;
218+
Param_Update : Parameter_Update.T := (
219+
Table_Id => 1,
220+
Operation => Update,
221+
Status => Success,
222+
Param => ((0, 0), [others => 0])
223+
);
224+
begin
225+
Self.Parameter_Update_T_Provide (Param_Update);
226+
return Param_Update.Status;
227+
end Update_Parameters;
228+
229+
end Component.Body_Rate_Miscompare.Implementation.Tester;

0 commit comments

Comments
 (0)