ChimeraTK-ApplicationCore 04.08.00
Loading...
Searching...
No Matches
demoStatusMonitor.cc

For more info see Status Monitor.

For more info see Status Monitor

// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
#include <ChimeraTK/ApplicationCore/ApplicationCore.h>
#include <ChimeraTK/ApplicationCore/EnableXMLGenerator.h>
#include <ChimeraTK/ApplicationCore/ModuleGroup.h>
#include <ChimeraTK/ApplicationCore/PeriodicTrigger.h>
#include <ChimeraTK/ApplicationCore/ScalarAccessor.h>
#include <ChimeraTK/ApplicationCore/StatusMonitor.h>
namespace ctk = ChimeraTK;
// Just simulate a temperature going up and down
using ctk::ApplicationModule::ApplicationModule;
ctk::ScalarOutput<double> temperature{this, "temperature", "degC", "simulated temperature"};
ctk::ScalarPushInput<uint64_t> trigger{this, "/TemperatureTimer/tick", "", ""};
void mainLoop() override {
double direction = 1;
while(true) {
// go down with the temperature if too hot
if(temperature > 50) {
direction = -1;
}
// go up with the temperature if too cold
if(temperature < -50) {
direction = 1;
}
temperature += direction * 1; // one degree steps
trigger.read();
}
}
};
struct ExampleApp : public ctk::Application {
ExampleApp() : Application("exampleApp") {}
~ExampleApp() override { shutdown(); }
// Create an instance of the simulation module. We name it "Simulation".
// There will be a variable /Simulation/temperature from this.
SimulationModule simulation{this, "Simulation", "temperature simulation"};
/* periodic timer to update the temperature*/
ctk::PeriodicTrigger temperatureTimer{this, "TemperatureTimer", "Periodic timer to update temperature"};
// Now we place a monitor next to the temperature variable. First we create a module group, also with the name
// "Simulation". Everything in it will be placed next to the variables from the simulation module.
struct : ctk::ModuleGroup {
using ctk::ModuleGroup::ModuleGroup;
// Inside the module group we place the monitor. In the constructor it gets the name of the variable to monitor, and
// the name of the output variable. The monitor automatically connects to the input variable that is in the same
// hierarchy level. We add output and parameter tags (STATUS and CONFIG, respectively) for easier connetion of the
// variables.
// ctk::RangeMonitor<double> temperatureMonitor{this, "TemperatureMonitor", "monitor for the simulated temperature",
// "temperature", "temperatureStatus", ctk::HierarchyModifier::none, {"STATUS"}, {"CONFIG"}, {}};
ctk::RangeMonitor<double> temperatureMonitor{this, "/Simulation/temperature",
"/TemperatureMonitor/temperatureStatus", "/Config/TemperatureMonitor", "monitor for the simulated temperature",
ctk::TAGS{"MON_OUTPUT"}, ctk::TAGS{"MON_PARAMS"}};
} simulationGroup{this, "Simulation", ""};
ctk::ConfigReader config{this, "Config", "demoStatusMonitor_config.xml"};
};
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
[Snippet: Destructor]
Definition ExampleApp.cc:18
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...