From e0b88a9563adf71a32c5ffc075b4044822c5a680 Mon Sep 17 00:00:00 2001
From: Claudio Scafuri <claudio.scafuri@elettra.eu>
Date: Tue, 28 Jan 2025 16:32:01 +0100
Subject: [PATCH] fix resonance strength, clarify and fix
 ResetResonanceStrength command

---
 TODO                |  1 -
 src/E2Sextupole.cpp | 22 +++++++---------------
 src/E2Sextupole.h   |  2 +-
 src/E2Sextupole.xmi |  2 +-
 src/main.cpp        |  2 +-
 5 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/TODO b/TODO
index 2972583..4aa68f8 100644
--- a/TODO
+++ b/TODO
@@ -1,2 +1 @@
-check and fix ResonanceStrength handling
 fix units
\ No newline at end of file
diff --git a/src/E2Sextupole.cpp b/src/E2Sextupole.cpp
index 4be02d1..b29f69f 100644
--- a/src/E2Sextupole.cpp
+++ b/src/E2Sextupole.cpp
@@ -617,7 +617,7 @@ void E2Sextupole::write_ResonanceStrength(Tango::WAttribute &attr)
 	Tango::DeviceAttribute watt("Current", curr_out[0]);
 	current_dev->write_attribute(watt);
 	wValResStrength = w_val;
-	//*attr_ResonanceStrength_read = w_val;
+	*attr_ResonanceStrength_read = w_val;
 	set_strength[0] = newStrength;
 	strengthAtt->set_write_value(set_strength[0]);
 	/*----- PROTECTED REGION END -----*/	//	E2Sextupole::write_ResonanceStrength
@@ -793,7 +793,7 @@ void E2Sextupole::reset()
 //--------------------------------------------------------
 /**
  *	Command ResetResonanceStrength related method
- *	Description: Reset ResonanceStrength to 0
+ *	Description: Transfer ResonanceStranght to CorrectionStrength and set ResonanceStrength to 0. Strngth is not modified
  *
  */
 //--------------------------------------------------------
@@ -806,24 +806,16 @@ void E2Sextupole::reset_resonance_strength()
 	//	Add your own code
 
 	/* clang-format off */
-	//force to 0 resonance strength
+	//transfer resonance strength to correction strength and than force to 0 resonance strength
 	omni_mutex_lock guardio(iomutex);
-	/*
-	Tango::DevDouble newStrength;
-	newStrength = wValCorrStrength;
-	std::vector<double> req_strength;
-	std::vector<double> curr_out;
-	req_strength.push_back(newStrength);
-	sextupole->compute_currents(magnet_rigidity, req_strength, curr_out);
-	Tango::DeviceAttribute watt("Current", curr_out[0]);
-	current_dev->write_attribute(watt);
-	*/
+
 	wValCorrStrength +=  wValResStrength;
 	wValResStrength = 0.0;
-	//set_strength[0] = newStrength;
-	//strengthAtt->set_write_value(set_strength[0]);
+
 	correctionAtt->set_write_value(wValCorrStrength);
+	*attr_CorrectionStrength_read = wValCorrStrength;
 	resonanceAtt->set_write_value(0.0);
+	*attr_ResonanceStrength_read = 0.0;
 	/*----- PROTECTED REGION END -----*/	//	E2Sextupole::reset_resonance_strength
 }
 //--------------------------------------------------------
diff --git a/src/E2Sextupole.h b/src/E2Sextupole.h
index a938bda..3b12b3a 100644
--- a/src/E2Sextupole.h
+++ b/src/E2Sextupole.h
@@ -286,7 +286,7 @@ public:
 	virtual bool is_Reset_allowed(const CORBA::Any &any);
 	/**
 	 *	Command ResetResonanceStrength related method
-	 *	Description: Reset ResonanceStrength to 0
+	 *	Description: Transfer ResonanceStranght to CorrectionStrength and set ResonanceStrength to 0. Strngth is not modified
 	 *
 	 */
 	virtual void reset_resonance_strength();
diff --git a/src/E2Sextupole.xmi b/src/E2Sextupole.xmi
index 0a7dfe9..9ea46d0 100644
--- a/src/E2Sextupole.xmi
+++ b/src/E2Sextupole.xmi
@@ -75,7 +75,7 @@
       </argout>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
     </commands>
-    <commands name="ResetResonanceStrength" description="Reset ResonanceStrength to 0" execMethod="reset_resonance_strength" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
+    <commands name="ResetResonanceStrength" description="Transfer ResonanceStranght to CorrectionStrength and set ResonanceStrength to 0. Strngth is not modified" execMethod="reset_resonance_strength" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
       <argin description="">
         <type xsi:type="pogoDsl:VoidType"/>
       </argin>
diff --git a/src/main.cpp b/src/main.cpp
index 745a89e..f5f721e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -48,7 +48,7 @@ DECLARE_CRASH_HANDLER
 int main(int argc,char *argv[])
 {
 	INSTALL_CRASH_HANDLER
-	Tango::Util *tg;
+	Tango::Util *tg = nullptr;
 	try
 	{
 		// Initialise the device server
-- 
GitLab