ChimeraTK-ApplicationCore 04.09.00
Loading...
Searching...
No Matches
demoStatusMonitor.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
10#include <ChimeraTK/ApplicationCore/ApplicationCore.h>
11#include <ChimeraTK/ApplicationCore/EnableXMLGenerator.h>
12#include <ChimeraTK/ApplicationCore/ModuleGroup.h>
13#include <ChimeraTK/ApplicationCore/PeriodicTrigger.h>
14#include <ChimeraTK/ApplicationCore/ScalarAccessor.h>
15#include <ChimeraTK/ApplicationCore/StatusMonitor.h>
16
17namespace ctk = ChimeraTK;
18
19// Just simulate a temperature going up and down
21 using ctk::ApplicationModule::ApplicationModule;
22
24 ctk::ScalarOutput<double> temperature{this, "temperature", "degC", "simulated temperature"};
25
27 ctk::ScalarPushInput<uint64_t> trigger{this, "/TemperatureTimer/tick", "", ""};
28
29 void mainLoop() override {
31 temperature = 0;
33 double direction = 1;
34
35 while(true) {
36 // go down with the temperature if too hot
37 if(temperature > 50) {
38 direction = -1;
39 }
40 // go up with the temperature if too cold
41 if(temperature < -50) {
42 direction = 1;
43 }
44
45 temperature += direction * 1; // one degree steps
46
48
50 trigger.read();
51 }
52 }
53};
54
55struct ExampleApp : public ctk::Application {
56 ExampleApp() : Application("exampleApp") {}
57 ~ExampleApp() override { shutdown(); }
58
59 // Create an instance of the simulation module. We name it "Simulation".
60 // There will be a variable /Simulation/temperature from this.
61 SimulationModule simulation{this, "Simulation", "temperature simulation"};
62
63 /* periodic timer to update the temperature*/
64 ctk::PeriodicTrigger temperatureTimer{this, "TemperatureTimer", "Periodic timer to update temperature"};
65
66 // Now we place a monitor next to the temperature variable. First we create a module group, also with the name
67 // "Simulation". Everything in it will be placed next to the variables from the simulation module.
68 struct : ctk::ModuleGroup {
69 using ctk::ModuleGroup::ModuleGroup;
70 // Inside the module group we place the monitor. In the constructor it gets the name of the variable to monitor, and
71 // the name of the output variable. The monitor automatically connects to the input variable that is in the same
72 // hierarchy level. We add output and parameter tags (STATUS and CONFIG, respectively) for easier connetion of the
73 // variables.
74 // ctk::RangeMonitor<double> temperatureMonitor{this, "TemperatureMonitor", "monitor for the simulated temperature",
75 // "temperature", "temperatureStatus", ctk::HierarchyModifier::none, {"STATUS"}, {"CONFIG"}, {}};
76
77 ctk::RangeMonitor<double> temperatureMonitor{this, "/Simulation/temperature",
78 "/TemperatureMonitor/temperatureStatus", "/Config/TemperatureMonitor", "monitor for the simulated temperature",
79 ctk::TAGS{"MON_OUTPUT"}, ctk::TAGS{"MON_PARAMS"}};
80
81 } simulationGroup{this, "Simulation", ""};
82
83 ctk::ConfigReader config{this, "Config", "demoStatusMonitor_config.xml"};
84};
85
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
Generic module to read an XML config file and provide the defined values as constant variables.
friend class Application
Definition ModuleGroup.h:47
bool write(ChimeraTK::VersionNumber versionNumber)=delete
Convenience class for output scalar accessors (always UpdateMode::push)
Convenience class for input scalar accessors with UpdateMode::push.
[Snippet: Class Definition Start]
Definition ExampleApp.h:27
~ExampleApp() override
ctk::PeriodicTrigger temperatureTimer
ctk::RangeMonitor< double > temperatureMonitor
SimulationModule simulation
ctk::ConfigReader config
ExampleApp theExampleApp
InvalidityTracer application module.
const std::unordered_set< std::string > TAGS
Convenience type definition which can optionally be used as a shortcut for the type which defines a l...
Definition EntityOwner.h:27
Simple periodic trigger that fires a variable once per second.
Module for status monitoring depending on range of threshold values.
Example to simulate the working and usage of StatusMonitor.
ctk::ScalarOutput< double > temperature
The value to be monitored.
ctk::ScalarPushInput< uint64_t > trigger
Create trigger for blocking mock read.
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...