Coverage for / opt / hostedtoolcache / Python / 3.11.14 / x64 / lib / python3.11 / site-packages / rattlesnake / components / abstract_control_law.py: 100%
9 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-27 18:22 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-27 18:22 +0000
1# -*- coding: utf-8 -*-
2"""
3Abstract base law that new Random Vibration Environment control laws can inherit
4from.
6Rattlesnake Vibration Control Software
7Copyright (C) 2021 National Technology & Engineering Solutions of Sandia, LLC
8(NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
9Government retains certain rights in this software.
11This program is free software: you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation, either version 3 of the License, or
14(at your option) any later version.
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
21You should have received a copy of the GNU General Public License
22along with this program. If not, see <https://www.gnu.org/licenses/>.
23"""
25from abc import ABC, abstractmethod
26import numpy as np
29class AbstractControlClass(ABC):
30 """Abstract class to define a random vibration control law"""
32 @abstractmethod
33 def __init__(
34 self,
35 specification: np.ndarray, # The specification to control to
36 warning_levels: np.ndarray, # Warning threshold levels
37 abort_levels: np.ndarray, # Abort levels
38 extra_control_parameters: str, # Extra parameters specified by the controller
39 transfer_function: np.ndarray = None, # Transfer Functions
40 buzz_cpsd: np.ndarray = None, # Buzz test in case cross terms are to be computed
41 last_response_cpsd: np.ndarray = None, # Last Response for Error Correction
42 last_output_cpsd: np.ndarray = None, # Last output for Drive-based control
43 ):
44 """
45 Initializes the control law
47 Note that to facilitate the updating of the control law while the test
48 is running, the init function will take all control data. If control
49 is not running, these will be Nones.
51 Parameters
52 ----------
53 specification : np.ndarray
54 A complex 3d numpy ndarray with dimensions frequency lines x control
55 channels x control channels representing the specification defined
56 by a CPSD matrix
57 warning_levels : np.ndarray
58 A real 2D numpy ndarray with dimensions frequency lines x control
59 channels representing ASD levels at which the system is approaching
60 abort. Control law authors may wish to use this threshold to make
61 changes in their control law.
62 abort_levels : np.ndarray
63 A real 2D numpy ndarray with dimensions frequency lines x control
64 channels representing ASD levels at which the system will abort.
65 Control law authors may wish to use this threshold to make
66 changes in their control law to prevent producing a signal that
67 would force the system to abort.
68 extra_control_parameters : str
69 A string containing any extra parameters that might need to be
70 passed to the control law. This should be parsed by the __init__
71 function.
72 transfer_function : np.ndarray, optional
73 A complex 3d numpy ndarray with dimensions frequency lines x control
74 channels x excitation sources representing the FRF matrix measured
75 by the system identification process between drive voltages and
76 control response. Will only be passed if the control is switched
77 mid-run. The default is None.
78 buzz_cpsd : np.ndarray, optional
79 A complex 3d numpy ndarray with dimensions frequency lines x control
80 channels x control channels representing the CPSD matrix measured
81 by the system identification process. Will only be passed if the
82 control is switched mid-run. The default is None.
83 last_response_cpsd : np.ndarray, optional
84 A complex 3d numpy ndarray with dimensions frequency lines x control
85 channels x control channels representing the last CPSD matrix of
86 control channel responses. Will only be passed if the
87 control is switched mid-run. The default is None.
88 last_output_cpsd : np.ndarray, optional
89 A complex 3d numpy ndarray with dimensions frequency lines x drive
90 channels x drive channels representing the last CPSD matrix of
91 drive outputs. Will only be passed if the
92 control is switched mid-run. The default is None.
93 """
95 @abstractmethod
96 def system_id_update(
97 self,
98 transfer_function: np.ndarray, # The transfer function from the system identification
99 buzz_cpsd: np.ndarray, # The CPSD from the system identification
100 ):
101 """
102 Updates the control law with the data from the system identification
104 Parameters
105 ----------
106 transfer_function : np.ndarray
107 A complex 3d numpy ndarray with dimensions frequency lines x control
108 channels x excitation sources representing the FRF matrix measured
109 by the system identification process between drive voltages and
110 control response
111 buzz_cpsd : np.ndarray
112 A complex 3d numpy ndarray with dimensions frequency lines x control
113 channels x control channels representing the CPSD matrix measured
114 by the system identification process
116 """
118 @abstractmethod
119 def control(
120 self,
121 transfer_function: np.ndarray, # The last update of the transfer function
122 last_response_cpsd: np.ndarray = None, # Last Response for Error Correction
123 last_output_cpsd: np.ndarray = None, # Last output for Drive-based control
124 ) -> np.ndarray:
125 """
126 Perform the control operations
128 Parameters
129 ----------
130 transfer_function : np.ndarray
131 A complex 3d numpy ndarray with dimensions frequency lines x control
132 channels x excitation sources representing the FRF matrix measured
133 by the system identification process between drive voltages and
134 control response
135 last_response_cpsd : np.ndarray
136 A complex 3d numpy ndarray with dimensions frequency lines x control
137 channels x control channels representing the last CPSD matrix of
138 control channel responses. If no previous data exists (first time
139 through control) it will be None. The default is None.
140 last_output_cpsd : np.ndarray
141 A complex 3d numpy ndarray with dimensions frequency lines x drive
142 channels x drive channels representing the last CPSD matrix of
143 drive outputs. If no previous data exists (first time
144 through control) it will be None. The default is None.
146 Returns
147 -------
148 next_output_cpsd : np.ndarray
149 A complex 3d numpy ndarray with dimensions frequency lines x drive
150 channels x drive channels representing the new CPSD matrix of
151 drive outputs that should be played to the shakers. If None is
152 returned instead, it will signal the software to shut down.
153 """