M1M3 Support System
Loading...
Searching...
No Matches
ForceController.h
1/*
2 * This file is part of LSST M1M3 support system package.
3 *
4 * Developed for the LSST Telescope & Site Software Systems.
5 * This product includes software developed by the LSST Project
6 * (https://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef FORCECONTROLLER_H_
25#define FORCECONTROLLER_H_
26
27#include <spdlog/spdlog.h>
28#include <vector>
29
30#include <SAL_MTM1M3C.h>
31#include <SAL_MTMountC.h>
32
33#include <AccelerationForceComponent.h>
34#include <ActiveOpticForceComponent.h>
35#include <AzimuthForceComponent.h>
36#include <BalanceForceComponent.h>
37#include <DistributedForces.h>
38#include <ElevationForceComponent.h>
39#include <FinalForceComponent.h>
40#include <ForceActuatorApplicationSettings.h>
41#include <ForceActuatorSettings.h>
42#include <ForcesAndMoments.h>
43#include <LimitTrigger.h>
44#include <OffsetForceComponent.h>
45#include <PID.h>
46#include <SafetyController.h>
47#include <StaticForceComponent.h>
48#include <ThermalForceComponent.h>
49#include <VelocityForceComponent.h>
50#include <cRIO/DataTypes.h>
51
52namespace LSST {
53namespace M1M3 {
54namespace SS {
55
58 int nearCount;
59 int NearZIndices[FA_MAX_NEAR_COUNT];
60 int FarIndices[FA_FAR_COUNT];
61};
62
129public:
130 ForceController(ForceActuatorApplicationSettings *forceActuatorApplicationSettings);
131
132 void reset();
133
139 void updateTMAElevationData(MTMount_elevationC *tmaElevationData);
140
146
147 void updateAppliedForces();
148
160
167 void zeroAccelerationForces();
168
169 void applyActiveOpticForces(float *z);
170 void zeroActiveOpticForces();
171
172 void applyAzimuthForces();
173 void updateTMAAzimuthForces(MTMount_azimuthC *tmaAzimuthData);
174 void zeroAzimuthForces();
175
176 bool applyBalanceForces();
177 bool zeroBalanceForces();
178 void updatePID(int id, PIDParameters parameters);
179
185 void resetPID(int id);
186
190 void resetPIDs();
191
192 void freezePIDs();
193 void thawPIDs();
194
195 void applyElevationForces();
196 void zeroElevationForces();
197
198 void applyOffsetForces(float *x, float *y, float *z);
199 void applyOffsetForcesByMirrorForces(float xForce, float yForce, float zForce, float xMoment,
200 float yMoment, float zMoment);
201 void zeroOffsetForces();
202
203 void applyActuatorOffset(char axis, int index, float offset);
204
205 void applyStaticForces();
206 void zeroStaticForces();
207
208 void applyThermalForces();
209 void updateThermalForces(float temperature);
210 void zeroThermalForces();
211
217 bool applyVelocityForces();
218 void zeroVelocityForces();
219
220 void enableDisableForceComponent(int forceComponentEnum, bool enabled);
221
222private:
223 void _sumAllForces();
224 void _convertForcesToSetpoints();
225
226 bool _checkMirrorMoments();
227 bool _checkNearNeighbors();
228 bool _checkMirrorWeight();
229 bool _checkFarNeighbors();
230
231 static double constexpr _sqrt2 = 1.4142135623730950488016887242097;
232
233 ForceActuatorApplicationSettings *_forceActuatorApplicationSettings;
234 SafetyController *_safetyController;
235
236 AccelerationForceComponent _accelerationForceComponent;
237 ActiveOpticForceComponent _activeOpticForceComponent;
238 AzimuthForceComponent _azimuthForceComponent;
239 BalanceForceComponent _balanceForceComponent;
240 ElevationForceComponent _elevationForceComponent;
241 OffsetForceComponent _offsetForceComponent;
242 StaticForceComponent _staticForceComponent;
243 ThermalForceComponent _thermalForceComponent;
244 VelocityForceComponent _velocityForceComponent;
245 FinalForceComponent _finalForceComponent;
246
247 MTM1M3_appliedCylinderForcesC *_appliedCylinderForces;
248 MTM1M3_appliedForcesC *_appliedForces;
249 MTM1M3_logevent_forceActuatorStateC *_forceActuatorState;
250 MTM1M3_logevent_forceSetpointWarningC *_forceSetpointWarning;
251 MTM1M3_logevent_preclippedCylinderForcesC *_preclippedCylinderForces;
252
253 MTM1M3_inclinometerDataC *_inclinometerData;
254 MTM1M3_pidDataC *_pidData;
255 MTM1M3_logevent_pidInfoC *_pidInfo;
256 MTM1M3_hardpointActuatorDataC *_hardpointActuatorData;
257 MTM1M3_accelerometerDataC *_accelerometerData;
258 MTM1M3_gyroDataC *_gyroData;
259
260 ForceActuatorIndicesNeighbors _neighbors[FA_COUNT];
261
262 float _zero[FA_COUNT];
263 float _mirrorWeight;
264
265 class ForceLimitTrigger : public LimitTrigger<float, float> {
266 public:
267 ForceLimitTrigger() {
268 _axis = 'U';
269 _faId = -1;
270 _counter = 0;
271 }
272
273 ForceLimitTrigger(char axis, int faId) {
274 _axis = axis;
275 _faId = faId;
276 _counter = 0;
277 }
278
279 protected:
280 bool trigger() override {
281 _counter++;
282 // problems are reported when accumulated counter reaches those levels
283 static int levels[4] = {1, 200, 500, 100000};
284 for (int i = 0; i < 4; i++)
285 if (levels[i] == _counter) return true;
286 return ((_counter % levels[3]) == 0);
287 }
288
289 void execute(float limit, float fe) override {
290 SPDLOG_WARN(
291 "Violated {} follow-up error FA ID {} measured error {} "
292 "({}th occurence), limit +-{}",
293 _axis, _faId, fe, _counter, limit);
294 }
295
296 void reset() override {
297 if (_counter > 0) {
298 SPDLOG_INFO(
299 "FA ID {} axis {} following error is back into limits "
300 "after {} failures",
301 _faId, _axis, _counter);
302 _counter = 0;
303 }
304 }
305
306 private:
307 char _axis;
308 int _faId;
309 int _counter;
310 };
311
312 ForceLimitTrigger limitTriggerX[FA_X_COUNT];
313 ForceLimitTrigger limitTriggerY[FA_Y_COUNT];
314 ForceLimitTrigger limitTriggerZ[FA_Z_COUNT];
315
316 static int32_t _toInt24(float force) { return (int32_t)(force * 1000.0); }
317};
318
319} /* namespace SS */
320} /* namespace M1M3 */
321} /* namespace LSST */
322
323#endif /* FORCECONTROLLER_H_ */
Definition AccelerationForceComponent.h:37
Definition ActiveOpticForceComponent.h:36
Definition AzimuthForceComponent.h:37
Distributes balance forces.
Definition BalanceForceComponent.h:54
Definition ElevationForceComponent.h:37
Final force produced as sum of components.
Definition FinalForceComponent.h:43
(Almost) constant force actuator values.
Definition ForceActuatorApplicationSettings.h:87
Coordinate force actuators force calculcation.
Definition ForceController.h:128
void processAppliedForces()
Sums components and run mirror safety checks.
Definition ForceController.cpp:254
void resetPID(int id)
Reset given PID settings to system default (tracking).
Definition ForceController.cpp:345
bool applyAccelerationForces()
Apply acceleration forces.
Definition ForceController.cpp:269
bool applyVelocityForces()
Apply velocity forces.
Definition ForceController.cpp:452
void updateTMAElevationData(MTMount_elevationC *tmaElevationData)
Updates elevation data.
void resetPIDs()
Resets all PIDs to initial (tracking) settings.
Definition ForceController.cpp:350
bool faRaiseFollowingErrorInTolerance()
Tests following error on all actuaturs.
Definition ForceController.cpp:165
Abstract interface class for limiting some action to predefined execution.
Definition LimitTrigger.h:66
Handle user offsets.
Definition OffsetForceComponent.h:40
Controls mirror safety.
Definition SafetyController.h:50
Definition StaticForceComponent.h:39
Applies corrections for mirror cell temperature.
Definition ThermalForceComponent.h:45
Definition VelocityForceComponent.h:37
Definition ForceController.h:56
Parameters for PID calculations.
Definition PIDParameters.h:36