From f2fbf59ca50b3ede8ef2e3471766ee581dfcf2c4 Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Thu, 29 Feb 2024 10:04:31 +0100 Subject: [PATCH] events and current ripple --- .gitignore | 2 +- src/SimulatedE2PS.cpp | 81 +++++++++++++++++++++++++++++++++----- src/SimulatedE2PS.h | 10 +++++ src/SimulatedE2PS.xmi | 7 +++- src/SimulatedE2PSClass.cpp | 14 +++++++ 5 files changed, 102 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 0d4c718..563ccc8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.nse_depinfo +.nse_depinfo* bin obj diff --git a/src/SimulatedE2PS.cpp b/src/SimulatedE2PS.cpp index 5b23c88..2f9a6e5 100644 --- a/src/SimulatedE2PS.cpp +++ b/src/SimulatedE2PS.cpp @@ -151,7 +151,9 @@ void SimulatedE2PS::init_device() /* clang-format off */ /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::init_device_before - // No device property to be read from database + + // Get the device properties from database + get_device_property(); /*----- PROTECTED REGION ID(SimulatedE2PS::init_device) ENABLED START -----*/ /* clang-format on */ @@ -175,6 +177,57 @@ void SimulatedE2PS::init_device() /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::init_device } +//-------------------------------------------------------- +/** + * Method : SimulatedE2PS::get_device_property() + * Description: Read database to initialize property data members. + */ +//-------------------------------------------------------- +void SimulatedE2PS::get_device_property() +{ + /*----- PROTECTED REGION ID(SimulatedE2PS::get_device_property_before) ENABLED START -----*/ + /* clang-format on */ + // Initialize property data members + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::get_device_property_before + + + // Read device properties from database. + Tango::DbData dev_prop; + dev_prop.push_back(Tango::DbDatum("CurrentRipple")); + + // is there at least one property to be read ? + if (dev_prop.size()>0) + { + // Call database and extract values + if (Tango::Util::instance()->_UseDb==true) + get_db_device()->get_property(dev_prop); + + // get instance on SimulatedE2PSClass to get class property + Tango::DbDatum def_prop, cl_prop; + SimulatedE2PSClass *ds_class = + (static_cast<SimulatedE2PSClass *>(get_device_class())); + int i = -1; + + // Try to initialize CurrentRipple from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> currentRipple; + else { + // Try to initialize CurrentRipple from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> currentRipple; + } + // And try to extract CurrentRipple value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> currentRipple; + + } + + /*----- PROTECTED REGION ID(SimulatedE2PS::get_device_property_after) ENABLED START -----*/ + /* clang-format on */ + // Check device property data members init + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::get_device_property_after +} //-------------------------------------------------------- /** @@ -238,14 +291,13 @@ void SimulatedE2PS::read_current(Tango::Attribute &attr) /*----- PROTECTED REGION ID(SimulatedE2PS::read_current) ENABLED START -----*/ /* clang-format on */ // Set the attribute value - double delta=rand_r(&rand_r_seed)/RAND_MAX; + double delta=drand48()-0.5; + if(get_state() == Tango::OFF){ - delta +=0.5; - _current_read = delta *0.0001; + _current_read = delta * currentRipple; } else{ - delta -=0.5; - _current_read = _current +( delta *0.0001 ); + _current_read = _current +( delta * currentRipple ); } attr.set_value(&_current_read); /* clang-format off */ @@ -264,9 +316,8 @@ void SimulatedE2PS::write_current(Tango::WAttribute &attr) { DEBUG_STREAM << "SimulatedE2PS::write_current(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value - attr.get_write_value(_current_read); - attr.get_write_value(_current); - _voltage = _current * _ohm; + Tango::DevDouble w_val; + attr.get_write_value(w_val); /*----- PROTECTED REGION ID(SimulatedE2PS::write_current) ENABLED START -----*/ /* clang-format on */ // Add your own code @@ -342,6 +393,8 @@ void SimulatedE2PS::on() /* clang-format on */ // Add your own code + set_state(Tango::ON); + push_change_event("State"); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::on @@ -358,7 +411,15 @@ void SimulatedE2PS::off() DEBUG_STREAM << "SimulatedE2PS::Off() - " << device_name << std::endl; /*----- PROTECTED REGION ID(SimulatedE2PS::off) ENABLED START -----*/ /* clang-format on */ - + _current_read = 0.0; + _current = 0.0; + _voltage = 0.0; + attr_current->set_write_value(_current); + push_change_event("current",&_current_read); + push_change_event("currentSet",&_current); + set_state(Tango::OFF); + push_change_event("State"); +; // Add your own code /* clang-format off */ diff --git a/src/SimulatedE2PS.h b/src/SimulatedE2PS.h index 6b44b49..e6357f4 100644 --- a/src/SimulatedE2PS.h +++ b/src/SimulatedE2PS.h @@ -86,6 +86,12 @@ class SimulatedE2PS : public TANGO_BASE_CLASS /* clang-format off */ /*----- PROTECTED REGION END -----*/ // SimulatedE2PS::Data Members +// Device property data members +public: + // CurrentRipple: Residual current oscillation [A] + // + // The simulator adds noise of CurrenRipple amplitude to the reading + Tango::DevDouble currentRipple; // Attribute data members public: @@ -133,6 +139,10 @@ public: * Initialize the device */ virtual void init_device(); + /* + * Read the device properties from database + */ + void get_device_property(); /* * Always executed method before execution command method. */ diff --git a/src/SimulatedE2PS.xmi b/src/SimulatedE2PS.xmi index 9225f63..eb8255e 100644 --- a/src/SimulatedE2PS.xmi +++ b/src/SimulatedE2PS.xmi @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="ASCII"?> <pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl"> <classes name="SimulatedE2PS" pogoRevision="9.8"> - <description description="Simulated power supply for Elettra 2.0 tests (digiltal twin).
Tango interface Loosely based on NGPS tango device" title="SimulatedE2PS" sourcePath="/homelocal/claudio/src/gitlab/dt/ds/simulatede2ps/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="false" hasConcreteProperty="false" hasAbstractCommand="false" hasAbstractAttribute="false"> + <description description="Simulated power supply for Elettra 2.0 tests (digiltal twin).
Tango interface Loosely based on NGPS tango device" title="SimulatedE2PS" sourcePath="/homelocal/claudio/src/gitlab/dt/ds/simulatede2ps/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false"> <inheritances classname="Device_Impl" sourcePath=""/> <identification contact="at elettra.eu - claudio.scafuri" author="claudio.scafuri" emailDomain="elettra.eu" classFamily="Simulators" siteSpecific="" platform="All Platforms" bus="Not Applicable" manufacturer="none" reference=""> <keyWords>Power supply</keyWords> @@ -10,6 +10,11 @@ <keyWords>Digital twin</keyWords> </identification> </description> + <deviceProperties name="CurrentRipple" description="Residual current oscillation [A]

The simulator adds noise of CurrenRipple amplitude to the reading"> + <type xsi:type="pogoDsl:DoubleType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <DefaultPropValue>0.0025</DefaultPropValue> + </deviceProperties> <commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0"> <argin description="none"> <type xsi:type="pogoDsl:VoidType"/> diff --git a/src/SimulatedE2PSClass.cpp b/src/SimulatedE2PSClass.cpp index fd66f1c..32c3963 100644 --- a/src/SimulatedE2PSClass.cpp +++ b/src/SimulatedE2PSClass.cpp @@ -331,6 +331,20 @@ void SimulatedE2PSClass::set_default_property() // Set Default Class Properties // Set Default device Properties + prop_name = "CurrentRipple"; + prop_desc = "Residual current oscillation [A]\n\nThe simulator adds noise of CurrenRipple amplitude to the reading"; + prop_def = "0.0025"; + vect_data.clear(); + vect_data.push_back("0.0025"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); } //-------------------------------------------------------- -- GitLab