Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
E2Sextupole
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dt
ds
E2Sextupole
Commits
679cf848
Commit
679cf848
authored
6 months ago
by
Claudio Scafuri
Browse files
Options
Downloads
Patches
Plain Diff
seprante handling of attribute changes, improvements
parent
38a76b66
No related branches found
Branches containing commit
No related tags found
2 merge requests
!2
Development
,
!1
Development
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
TODO
+2
-0
2 additions, 0 deletions
TODO
src/E2Sextupole.cpp
+85
-47
85 additions, 47 deletions
src/E2Sextupole.cpp
src/E2Sextupole.h
+3
-1
3 additions, 1 deletion
src/E2Sextupole.h
with
90 additions
and
48 deletions
TODO
0 → 100644
+
2
−
0
View file @
679cf848
check and fix ResonanceStrength handling
fix units
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/E2Sextupole.cpp
+
85
−
47
View file @
679cf848
...
...
@@ -211,7 +211,7 @@ void E2Sextupole::init_device()
}
//create MagnetModel::Sextupole - handles calibration tables and interpolations
// we do not use teh EBS shehme with global proprties... yet
// we do not use teh EBS shehme with global prop
e
rties... yet
//TODO: fix/determine format and handling of Elettra 2.0 calibrations
sextupole
=
nullptr
;
...
...
@@ -239,11 +239,6 @@ void E2Sextupole::init_device()
correctionAtt
=
&
get_device_attr
()
->
get_w_attr_by_name
(
"CorrectionStrength"
);
resonanceAtt
=
&
get_device_attr
()
->
get_w_attr_by_name
(
"ResonanceStrength"
);
cursetAtt
=
&
(
get_device_attr
()
->
get_w_attr_by_name
(
"Current"
));
init_strengths
();
// register callback for event subscription with a delay so the memorized variables are read dn updated from DB AFTER init_device() exit
//delayed_subscribe(subscribeDelay);
/*----- PROTECTED REGION END -----*/
// E2Sextupole::init_device
}
...
...
@@ -555,7 +550,7 @@ void E2Sextupole::write_CorrectionStrength(Tango::WAttribute &attr)
omni_mutex_lock
guardio
(
iomutex
);
Tango
::
DevDouble
newStrength
;
//resonanceAtt->get_write_value(_resStrength);
newStrength
=
w_val
+
wValResStrength
;
newStrength
=
w_val
+
wValResStrength
+
*
attr_DesignStrength_read
;
std
::
vector
<
double
>
req_strength
;
std
::
vector
<
double
>
curr_out
;
req_strength
.
push_back
(
newStrength
);
...
...
@@ -565,6 +560,7 @@ void E2Sextupole::write_CorrectionStrength(Tango::WAttribute &attr)
wValCorrStrength
=
w_val
;
set_strength
[
0
]
=
newStrength
;
strengthAtt
->
set_write_value
(
set_strength
[
0
]);
/*----- PROTECTED REGION END -----*/
// E2Sextupole::write_CorrectionStrength
}
//--------------------------------------------------------
...
...
@@ -613,7 +609,7 @@ void E2Sextupole::write_ResonanceStrength(Tango::WAttribute &attr)
*/
omni_mutex_lock
guardio
(
iomutex
);
Tango
::
DevDouble
newStrength
;
newStrength
=
w_val
+
wValCorrStrength
;
newStrength
=
w_val
+
wValCorrStrength
+
*
attr_DesignStrength_read
;
std
::
vector
<
double
>
req_strength
;
std
::
vector
<
double
>
curr_out
;
req_strength
.
push_back
(
newStrength
);
...
...
@@ -621,6 +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;
set_strength
[
0
]
=
newStrength
;
strengthAtt
->
set_write_value
(
set_strength
[
0
]);
/*----- PROTECTED REGION END -----*/
// E2Sextupole::write_ResonanceStrength
...
...
@@ -751,9 +748,9 @@ void E2Sextupole::write_DesignStrength(Tango::WAttribute &attr)
/* clang-format off */
*
attr_DesignStrength_read
=
w_val
;
if
(
design_strength_initialized
==
false
){
subscribe_events
();
design_strength_initialized
=
true
;
INFO_STREAM
<<
"w design strength"
<<
*
attr_DesignStrength_read
;
init_strengths
();
subscribe_events
();
}
/*----- PROTECTED REGION END -----*/
// E2Sextupole::write_DesignStrength
}
...
...
@@ -810,6 +807,7 @@ void E2Sextupole::reset_resonance_strength()
/* clang-format off */
//force to 0 resonance strength
omni_mutex_lock
guardio
(
iomutex
);
/*
Tango::DevDouble newStrength;
newStrength = wValCorrStrength;
std::vector<double> req_strength;
...
...
@@ -818,9 +816,12 @@ void E2Sextupole::reset_resonance_strength()
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
]);
//set_strength[0] = newStrength;
//strengthAtt->set_write_value(set_strength[0]);
correctionAtt
->
set_write_value
(
wValCorrStrength
);
resonanceAtt
->
set_write_value
(
0.0
);
/*----- PROTECTED REGION END -----*/
// E2Sextupole::reset_resonance_strength
}
...
...
@@ -877,7 +878,7 @@ void E2Sextupole::set_current_write(const double& curr)
set_current
[
0
]
=
curr
;
}
// ------------------------------------------------------------
void
E2Sextupole
::
init_strengths
(
void
)
// initialize strengths from power supply value
void
E2Sextupole
::
init_strengths
(
void
)
// initialize strengths from power supply value
TODO: separate read and set values
{
Tango
::
DeviceAttribute
da
;
try
{
...
...
@@ -886,7 +887,7 @@ void E2Sextupole::init_strengths(void) // initialize strengths from power supply
da
>>
outval
;
std
::
vector
<
Tango
::
DevDouble
>
_current
;
std
::
vector
<
Tango
::
DevDouble
>
_strength
;
_current
.
push_back
(
outval
[
1
]);
_current
.
push_back
(
outval
[
1
]);
//use set value of current
sextupole
->
compute_strengths
(
magnet_rigidity_inv
,
_current
,
_strength
);
cursetAtt
->
set_write_value
(
_current
[
0
]);
...
...
@@ -895,10 +896,11 @@ void E2Sextupole::init_strengths(void) // initialize strengths from power supply
strengthAtt
->
set_write_value
(
_strength
[
0
]);
*
attr_Strength_read
=
_strength
[
0
];
set_strength
[
0
]
=
_strength
[
0
];
Tango
::
DevDouble
corr
=
_strength
[
0
]
-
*
attr_DesignStrength_read
;
correctionAtt
->
set_write_value
(
_strength
[
0
]
);
*
attr_CorrectionStrength_read
=
_strength
[
0
]
;
wValCorrStrength
=
_strength
[
0
]
;
correctionAtt
->
set_write_value
(
corr
);
*
attr_CorrectionStrength_read
=
corr
;
wValCorrStrength
=
corr
;
resonanceAtt
->
set_write_value
(
0.0
);
// start with resonance strength always at 0!
*
attr_ResonanceStrength_read
=
0.0
;
...
...
@@ -909,28 +911,48 @@ void E2Sextupole::init_strengths(void) // initialize strengths from power supply
}
}
//------------------------------------------------------------
void
E2Sextupole
::
update_values
(
void
)
// handle changes poer poer supply read current (actula current)
void
E2Sextupole
::
update_values_read
(
void
)
{
/*
sextupole->compute_strengths(magnet_rigidity_inv, set_current, set_strength);
attr_Strength_read[0] = set_strength[0];
attr_ResonanceStrength_read[0] = attr_Strength_read[0] - wValCorrStrength;
attr_CorrectionStrength_read[0] = attr_Strength_read[0] - attr_ResonanceStrength_read[0];
*/
//----------------------------------------------
//INFO_STREAM << "design strength: " << *attr_DesignStrength_read;
if
(
isnan
(
*
attr_Current_read
)){
//handle error
attr_Strength_read
[
0
]
=
NAN
;
return
;
}
//INFO_STREAM << "update values read";
std
::
vector
<
Tango
::
DevDouble
>
read_curr
;
std
::
vector
<
Tango
::
DevDouble
>
read_strength
;
omni_mutex_lock
guardio
(
iomutex
);
read_curr
.
push_back
(
*
attr_Current_read
);
sextupole
->
compute_strengths
(
magnet_rigidity_inv
,
read_curr
,
read_strength
);
attr_Strength_read
[
0
]
=
read_strength
[
0
];
//attr_ResonanceStrength_read[0] = attr_Strength_read[0] - wValCorrStrength;
attr_CorrectionStrength_read
[
0
]
=
attr_Strength_read
[
0
]
-
(
attr_DesignStrength_read
[
0
]
+
attr_ResonanceStrength_read
[
0
]);
}
//------------------------------------------------------------
// hndle change of write set point of power supply cunnrent
void
E2Sextupole
::
update_values_write
(
void
)
{
if
(
isnan
(
*
attr_Current_read
)){
//handle error
attr_Strength_read
[
0
]
=
NAN
;
return
;
}
INFO_STREAM
<<
"update values write"
;
std
::
vector
<
Tango
::
DevDouble
>
read_curr
;
std
::
vector
<
Tango
::
DevDouble
>
read_strength
;
omni_mutex_lock
guardio
(
iomutex
);
read_curr
.
push_back
(
set_current
[
0
]);
//must use the write value
sextupole
->
compute_strengths
(
magnet_rigidity_inv
,
read_curr
,
read_strength
);
wValCorrStrength
=
read_strength
[
0
]
-
(
wValResStrength
+
*
attr_DesignStrength_read
);
correctionAtt
->
set_write_value
(
wValCorrStrength
);
}
//------------------------------------------------------------
// handel che of power supply state - may just filter values
void
E2Sextupole
::
update_values_state
(
void
)
{
//handle state - status
//INFO_STREAM << "update values state";
switch
(
get_state
())
{
case
Tango
::
ON
:
set_status
(
"On"
);
...
...
@@ -988,27 +1010,43 @@ CurrentEventCallback::CurrentEventCallback(E2Sextupole* sext) //callback constru
}
void
CurrentEventCallback
::
push_event
(
Tango
::
EventData
*
ev
)
//callback core method
{
bool
update_read
=
false
;
bool
update_write
=
false
;
bool
update_state
=
false
;
if
(
ev
->
err
)
{
//TODO hanlde error
//std::cerr << ev->err << " " << ev->attr_name << std::endl;
e2_sext
->
set_state
(
Tango
::
FAULT
);
e2_sext
->
set_status
(
"event error"
);
*
e2_sext
->
attr_Current_read
=
NAN
;
e2_sext
->
update_values_read
();
return
;
}
omni_mutex_lock
guardio
(
e2_sext
->
iomutex
);
//TODO add method to update the corrector when on value changes
std
::
string
fullattrname
=
ev
->
attr_name
;
std
::
size_t
pos
=
fullattrname
.
find_last_of
(
"/"
);
std
::
string
attrname
=
fullattrname
.
substr
(
pos
+
1
);
if
(
attrname
==
"current"
)
*
(
ev
->
attr_value
)
>>
*
(
e2_sext
->
attr_Current_read
);
if
(
attrname
==
"currentset"
){
Tango
::
DevDouble
newcurr
;
*
(
ev
->
attr_value
)
>>
newcurr
;
e2_sext
->
set_current_write
(
newcurr
);
}
if
(
attrname
==
"state"
)
{
Tango
::
DevState
st
;
*
(
ev
->
attr_value
)
>>
st
;
e2_sext
->
set_state
(
st
);
{
omni_mutex_lock
guardio
(
e2_sext
->
iomutex
);
//TODO add method to update the corrector when on value changes
std
::
string
fullattrname
=
ev
->
attr_name
;
std
::
size_t
pos
=
fullattrname
.
find_last_of
(
"/"
);
std
::
string
attrname
=
fullattrname
.
substr
(
pos
+
1
);
if
(
attrname
==
"current"
)
{
*
(
ev
->
attr_value
)
>>
*
(
e2_sext
->
attr_Current_read
);
update_read
=
true
;
}
if
(
attrname
==
"currentset"
)
{
Tango
::
DevDouble
newcurr
;
*
(
ev
->
attr_value
)
>>
newcurr
;
e2_sext
->
set_current_write
(
newcurr
);
update_write
=
true
;
}
if
(
attrname
==
"state"
)
{
Tango
::
DevState
st
;
*
(
ev
->
attr_value
)
>>
st
;
e2_sext
->
set_state
(
st
);
update_state
=
true
;
}
}
e2_sext
->
update_values
();
if
(
update_read
)
e2_sext
->
update_values_read
();
if
(
update_write
)
e2_sext
->
update_values_write
();
if
(
update_state
)
e2_sext
->
update_values_state
();
}
/*----- PROTECTED REGION END -----*/
// E2Sextupole::namespace_ending
...
...
This diff is collapsed.
Click to expand it.
src/E2Sextupole.h
+
3
−
1
View file @
679cf848
...
...
@@ -313,7 +313,9 @@ public:
// Additional Method prototypes
void
calc_rigidity
(
const
double
&
energy
);
void
set_current_write
(
const
double
&
curr
);
void
update_values
(
void
);
//update internal calculated values
void
update_values_write
(
void
);
//update internal calculated values when current write value is updated;
void
update_values_read
(
void
);
//update internal calculated values when current read value is updated;
void
update_values_state
(
void
);
//update internal calculated values when power supply state is updated;
void
init_strengths
(
void
);
// initialize strengths from power supply values
void
subscribe_events
(
void
);
//subcribe events to power supply
//void delayed_subscribe(int delayedMs);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment