Skip to content
Snippets Groups Projects
Commit a3190f0a authored by Martin Killenberg's avatar Martin Killenberg
Browse files

added example2c: device initialisation

parent 26a481b7
No related branches found
No related tags found
No related merge requests found
......@@ -4,4 +4,5 @@ eq_fct_name: "LOCAHOST._SVR"
eq_fct_type: 1
{
SVR.RPC_NUMBER: 610498009
SVR.RATE: 6 0 0 0
}
# Note: This CMakeLists.txt is a minimal complete example how to use the
# *installed* application core library. It is not included from the main CMakeLists.txt
# which is used to build ApplicationCore itself.
PROJECT(demo_example2c)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1)
# Use the project template to get the settings required for an application core project
set(${PROJECT_NAME}_MAJOR_VERSION 01)
set(${PROJECT_NAME}_MINOR_VERSION 00)
set(${PROJECT_NAME}_PATCH_VERSION 00)
include(cmake/set_version_numbers.cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
include(cmake/add_dependency.cmake)
include(cmake/set_default_build_to_release.cmake)
include(cmake/set_default_flags.cmake)
# Add the dependencies. We need ApplicationCore and a control system adapter implementation.
add_dependency(ChimeraTK-ApplicationCore 01.09 REQUIRED)
#FIXME: Make the adapter configurable via command line parameter
add_dependency(ChimeraTK-ControlSystemAdapter-DoocsAdapter 00.10 REQUIRED)
AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR} demo_sources)
# The server proper. It depends on application core and the control system adapter implementation.
add_executable(${PROJECT_NAME} ${demo_sources})
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${ChimeraTK-ApplicationCore_LINK_FLAGS} ${ChimeraTK-ControlSystemAdapter-DoocsAdapter_LINK_FLAGS}")
target_link_libraries(${PROJECT_NAME} ${ChimeraTK-ApplicationCore_LIBRARIES} ${ChimeraTK-ControlSystemAdapter-DoocsAdapter_LIBRARIES} )
# We compile the same sources with the GENERATE_XML flag to get an xml generator.
# This one does not depent on a control system adapter implementation.
add_executable(${PROJECT_NAME}-xmlGenerator ${demo_sources})
set_target_properties( ${PROJECT_NAME}-xmlGenerator PROPERTIES COMPILE_FLAGS "-DGENERATE_XML")
set_target_properties(${PROJECT_NAME}-xmlGenerator PROPERTIES LINK_FLAGS "${ChimeraTK-ApplicationCore_LINK_FLAGS}")
target_link_libraries(${PROJECT_NAME}-xmlGenerator ${ChimeraTK-ApplicationCore_LIBRARIES})
# copy the (test) config files to the build directory for tests
FILE( COPY config/ DESTINATION ${PROJECT_BINARY_DIR})
# Tests:
# There are no dedicated tests for this demo. But we run the xml generator to
# check that the variable household can successfully be initialised.
# The test will fail if the xml generator crashes, just a smoke test.
ENABLE_TESTING()
add_test(${PROJECT_NAME}-xmlGenerator ${PROJECT_NAME}-xmlGenerator)
# Installation:
# FIXME: For doocs we need a special treatment when installing to /export/doocs/server (don't install to bin subdirectory, but a directory named like the server). This should go to the project template.
if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/export/doocs/server")
install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}-xmlGenerator RUNTIME DESTINATION ${PROJECT_NAME})
else()
install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}-xmlGenerator RUNTIME DESTINATION bin)
endif()
# Do not install the config. It is only a test config.
# The real config will come from a config generator and usually depends on the instance.
../LICENSE
\ No newline at end of file
../This_project_uses_the_project-template.txt
\ No newline at end of file
../cmake/
\ No newline at end of file
<device_server>
<location name="Bakery">
<import>/</import>
</location>
</device_server>
eq_conf:
eq_fct_name: "LOCAHOST._SVR"
eq_fct_type: 1
{
SVR.RPC_NUMBER: 610498009
SVR.RATE: 6 0 0 0
}
oven_raw (sharedMemoryDummy?map=oven.map)
oven (logicalNameMap?map=oven.xlmap)
# name n_elements address size bar width fracbits signed R/W
APP.0.TEMPERATURE_ADC 1 0 4 0 16 0 0 RO
APP.0.HEATING_CURRENT 1 4 4 0 32 16 0 RW
APP.0.SUPPLY_ADCS 4 8 16 0 16 0 0 RO
APP.0.POWER 1 24 4 0 1 0 0 RW
APP.0.SUPPLY_ADCS_GAIN 4 28 16 0 32 0 0 RW
APP.0.AREA_FW_UPGRADE 1024 256 4096 0 32 0 0 RW
<logicalNameMap>
<module name="heater">
<redirectedRegister name="heatingCurrent">
<targetDevice>oven_raw</targetDevice>
<targetRegister>APP/0/HEATING_CURRENT</targetRegister>
</redirectedRegister>
<redirectedRegister name="temperatureReadback">
<targetDevice>oven_raw</targetDevice>
<targetRegister>APP/0/TEMPERATURE_ADC</targetRegister>
<plugin name="math">
<!-- 16 bit ADC with 10 V, Sensor: 65 V/degC -->
<parameter name="formula">x / 2.^16 * 10. * 65.</parameter>
</plugin>
</redirectedRegister>
<redirectedRegister name="managementVoltage">
<targetDevice>oven_raw</targetDevice>
<targetRegister>APP/0/SUPPLY_ADCS</targetRegister>
<numberOfElements>1</numberOfElements>
<plugin name="math">
<!-- 16 bit ADC with 32 V -->
<parameter name="formula">x / 2.^16 * 32.</parameter>
</plugin>
</redirectedRegister>
<redirectedRegister name="threePhaseVoltages">
<targetDevice>oven_raw</targetDevice>
<targetRegister>APP/0/SUPPLY_ADCS</targetRegister>\
<targetStartIndex>1</targetStartIndex>
<numberOfElements>3</numberOfElements>
<plugin name="math">
<!-- 16 bit ADC with 650 V -->
<parameter name="formula">return[x / 2.^16 * 650.]</parameter>
</plugin>
</redirectedRegister>
<redirectedRegister name="power">
<targetDevice>oven_raw</targetDevice>
<targetRegister>APP/0/POWER</targetRegister>
</redirectedRegister>
</module>
<module name="settings">
<redirectedRegister name="supplyVoltageAdcGains">
<targetDevice>oven_raw</targetDevice>
<targetRegister>APP/0/SUPPLY_ADCS_GAIN</targetRegister>
</redirectedRegister>
</module>
</logicalNameMap>
#include <ChimeraTK/ApplicationCore/ApplicationCore.h>
#include <ChimeraTK/ApplicationCore/PeriodicTrigger.h>
#include <ChimeraTK/ApplicationCore/EnableXMLGenerator.h>
namespace ctk = ChimeraTK;
struct Controller : public ctk::ApplicationModule {
using ctk::ApplicationModule::ApplicationModule;
ctk::ScalarPollInput<double> sp{this, "temperatureSetpoint", "degC", "Description"};
ctk::ScalarPushInput<double> rb{this, "temperatureReadback", "degC", "..."};
ctk::ScalarOutput<double> cur{this, "heatingCurrent", "mA", "..."};
void mainLoop() {
const double gain = 100.0;
while(true) {
readAll(); // waits until rb updated, then reads sp
cur = gain * (sp - rb);
writeAll(); // writes any outputs
}
}
};
struct ExampleApp : public ctk::Application {
ExampleApp() : Application("demoApp2") {}
~ExampleApp() { shutdown(); }
// We can pick any name for the module. "Oven" is what we want to see in the CS
Controller controller{this, "Oven", "The controller of the oven"};
ctk::PeriodicTrigger timer{this, "Timer", "Periodic timer for the controller", 1000};
ctk::DeviceModule oven{this, "oven", &initialiseOven};
ctk::ControlSystemModule cs;
void defineConnections();
static void initialiseOven(ChimeraTK::DeviceModule* oven);
};
static ExampleApp theExampleApp;
void ExampleApp::defineConnections() {
ChimeraTK::setDMapFilePath("example2.dmap");
// Connect everything to the CS (except for the device, which is special)
findTag(".*").connectTo(cs);
// Connect device's "heater" to "Oven" in the CS, and use timer.tick as trigger
oven["heater"].connectTo(cs["Oven"], timer.tick);
}
void ExampleApp::initialiseOven(ChimeraTK::DeviceModule* oven) {
// set the gain factors for the voltage monitoring ADCs
oven->device.write<uint32_t>("/settings/supplyVoltageAdcGains", {20, 1, 1, 1});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment