Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
filter-wheel
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
Container Registry
Operate
Environments
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
cs
ds
filter-wheel
Commits
9d34b759
Commit
9d34b759
authored
4 years ago
by
Milan Prica
Browse files
Options
Downloads
Patches
Plain Diff
As currently deployed at FERMI.
parents
No related branches found
Branches containing commit
Tags
1.0.0
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+19
-0
19 additions, 0 deletions
Makefile
README.md
+4
-0
4 additions, 0 deletions
README.md
src/FilterWheel.py
+397
-0
397 additions, 0 deletions
src/FilterWheel.py
with
420 additions
and
0 deletions
Makefile
0 → 100644
+
19
−
0
View file @
9d34b759
NAME
=
filterwheel-srv
MAIN
=
FilterWheel.py
DIRNAME
=
$(
NAME:-srv
=
)
MODNAME
=
$(
MAIN:.py
=
)
PY_FILES
+=
$(
wildcard src/
*
.py
)
default
:
bin ${PY_FILES}
@
cp
${
PY_FILES
}
bin/
${
DIRNAME
}
@
echo
"#!/usr/bin/env python
\n
import sys
\n
sys.path.append(sys.path[0]+'/
${
DIRNAME
}
')
\n
from
${
MODNAME
}
import main
\n
if __name__ == '__main__':
\n
main()
\n
"
>
bin/
${
NAME
}
@
chmod
+x bin/
${
NAME
}
bin/
${
DIRNAME
}
/
${
MAIN
}
bin
:
@
test
-d
$@
||
mkdir
-p
$@
/
${
DIRNAME
}
clean
:
@
rm
-fr
bin/ src/
*
~
.PHONY
:
clean
This diff is collapsed.
Click to expand it.
README.md
0 → 100644
+
4
−
0
View file @
9d34b759
# FilterWHeel Tango device server.
The device server controls 7 filter circular holder and runs on top of a smaractmcs2 positioner. Allows for simple tagging and selection of deployed filters.
This diff is collapsed.
Click to expand it.
src/FilterWheel.py
0 → 100755
+
397
−
0
View file @
9d34b759
#!/usr/bin/env python
# "$Name: $";
# "$Header: $";
#==================================================================
#
# file : FilterWheel.py
# description : PyTango utility device for SmarAct filter wheel that
# runs on top of the regular smaractmcs2-server.
# project : TANGO Device Server
# $Author: $ Elettra SPE (ex Elettra Sci.Comp.)
# $Revision: $ 0.1
#
#==================================================================
#
import
sys
import
PyTango
import
numpy
as
np
import
warnings
import
time
#==================================================================
# Device States Description:
#
# DevState.INIT : Initialization
# DevState.ON : Standby/running
# DevState.MOVING : Smaract motors are moving
# DevState.ALARM : Incorrect position
# DevState.FAULT : Connection with motor failed
#==================================================================
class
FilterWheel
(
PyTango
.
Device_4Impl
):
#------------------------------------------------------------------
# Device constructor
#------------------------------------------------------------------
def
__init__
(
self
,
cl
,
name
):
print
'
In Device constructor
'
PyTango
.
Device_4Impl
.
__init__
(
self
,
cl
,
name
)
FilterWheel
.
init_device
(
self
)
#------------------------------------------------------------------
# Device destructor
#------------------------------------------------------------------
def
delete_device
(
self
):
print
'
[Device delete_device method] for device
'
,
str
(
self
.
get_name
())
if
self
.
wheel
is
not
None
:
del
self
.
wheel
#------------------------------------------------------------------
# Device initialization
#------------------------------------------------------------------
def
init_device
(
self
):
print
'
In init device
'
self
.
set_state
(
PyTango
.
DevState
.
INIT
)
self
.
set_status
(
"
Initializing device...
"
)
self
.
get_device_properties
(
self
.
get_device_class
())
#
self
.
last_status_update
=
0
self
.
wheel_step
=
360.0
/
7
self
.
wheel_alive
=
False
try
:
# FilterWheelDevice is a SmarAct MCS2 Tango device.
self
.
wheel
=
PyTango
.
DeviceProxy
(
self
.
FilterWheelDevice
)
self
.
wheel
.
ping
()
self
.
wheel_alive
=
True
except
PyTango
.
DevFailed
:
exctype
,
value
=
sys
.
exc_info
()[:
2
]
print
"
Failed with exception !
"
,
exctype
for
err
in
value
:
print
"
reason
"
,
err
.
reason
print
"
description
"
,
err
.
desc
print
"
origin
"
,
err
.
origin
print
"
severity
"
,
err
.
severity
self
.
attr_Filter1_read
=
""
self
.
attr_Filter2_read
=
""
self
.
attr_Filter3_read
=
""
self
.
attr_Filter4_read
=
""
self
.
attr_Filter5_read
=
""
self
.
attr_Filter6_read
=
""
self
.
attr_Filter7_read
=
""
self
.
attr_CurrentPosition_read
=
0.0
self
.
attr_CurrentIndex_read
=
0
self
.
attr_CurrentFilter_read
=
""
self
.
attr_MotorTitle_read
=
""
if
self
.
wheel_alive
:
self
.
set_state
(
PyTango
.
DevState
.
ON
)
else
:
self
.
set_state
(
PyTango
.
DevState
.
FAULT
)
self
.
set_status
(
"
Connection with device failed.
"
)
#------------------------------------------------------------------
# Always excuted hook method
#------------------------------------------------------------------
def
always_executed_hook
(
self
):
# print "In ", self.get_name(), "::always_executed_hook()"
if
time
.
time
()
-
self
.
last_status_update
>
0.2
:
self
.
update_state_and_status
()
self
.
last_status_update
=
time
.
time
()
def
update_state_and_status
(
self
):
try
:
wheel_state
=
self
.
wheel
.
State
()
wheel_status
=
self
.
wheel
.
Status
()
if
wheel_state
==
PyTango
.
DevState
.
ON
:
selected_filter
=
self
.
selected_filter
()
if
selected_filter
is
not
None
:
self
.
attr_CurrentIndex_read
=
selected_filter
self
.
attr_CurrentFilter_read
=
eval
(
"
self.attr_Filter
"
+
str
(
selected_filter
)
+
"
_read
"
)
self
.
set_status
(
self
.
attr_CurrentFilter_read
+
"
selected
"
)
self
.
set_state
(
PyTango
.
DevState
.
ON
)
else
:
self
.
attr_CurrentIndex_read
=
0
self
.
set_status
(
"
No filter selected
"
)
self
.
set_state
(
PyTango
.
DevState
.
ALARM
)
elif
wheel_state
==
PyTango
.
DevState
.
MOVING
:
self
.
set_state
(
PyTango
.
DevState
.
MOVING
)
self
.
set_status
(
"
Wheel moving
"
)
else
:
self
.
set_state
(
wheel_state
)
self
.
set_status
(
wheel_status
)
except
PyTango
.
DevFailed
:
exctype
,
value
=
sys
.
exc_info
()[:
2
]
print
"
Failed with exception !
"
,
exctype
self
.
set_state
(
PyTango
.
DevState
.
FAULT
)
self
.
set_status
(
"
Connection with device failed.
"
)
def
selected_filter
(
self
):
selected_wheel
=
None
try
:
pos
=
self
.
wheel
.
Position
self
.
debug_stream
(
"
Current motor position
"
+
str
(
pos
))
self
.
attr_CurrentPosition_read
=
pos
if
pos
<-
2.0
:
pos
+=
360.0
if
abs
(
pos
/
self
.
wheel_step
-
round
(
pos
/
self
.
wheel_step
))
<
0.1
:
selected_wheel
=
int
(
abs
(
round
(
pos
/
self
.
wheel_step
)))
+
1
except
PyTango
.
DevFailed
:
exctype
,
value
=
sys
.
exc_info
()[:
2
]
print
"
Failed with exception !
"
,
exctype
self
.
debug_stream
(
"
Selected filter
"
+
str
(
selected_wheel
))
return
selected_wheel
def
select_filter
(
self
,
filter_number
):
if
filter_number
<=
4
:
pos
=
round
(
float
(
filter_number
-
1
)
*
self
.
wheel_step
,
4
)
else
:
pos
=
round
(
float
(
filter_number
-
1
)
*
self
.
wheel_step
-
360.0
,
4
)
try
:
self
.
wheel
.
write_attribute
(
"
Position
"
,
pos
)
except
PyTango
.
DevFailed
:
exctype
,
value
=
sys
.
exc_info
()[:
2
]
print
"
Failed with exception !
"
,
exctype
#==================================================================
#
# FilterWheel read/write attribute methods
#
#==================================================================
def
read_CurrentPosition
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_CurrentPosition_read
)
def
read_CurrentIndex
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_CurrentIndex_read
)
def
read_CurrentFilter
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_CurrentFilter_read
)
def
read_Filter1
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_Filter1_read
)
def
write_Filter1
(
self
,
attr
):
data
=
attr
.
get_write_value
()
self
.
attr_Filter1_read
=
data
def
read_Filter2
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_Filter2_read
)
def
write_Filter2
(
self
,
attr
):
data
=
attr
.
get_write_value
()
self
.
attr_Filter2_read
=
data
def
read_Filter3
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_Filter3_read
)
def
write_Filter3
(
self
,
attr
):
data
=
attr
.
get_write_value
()
self
.
attr_Filter3_read
=
data
def
read_Filter4
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_Filter4_read
)
def
write_Filter4
(
self
,
attr
):
data
=
attr
.
get_write_value
()
self
.
attr_Filter4_read
=
data
def
read_Filter5
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_Filter5_read
)
def
write_Filter5
(
self
,
attr
):
data
=
attr
.
get_write_value
()
self
.
attr_Filter5_read
=
data
def
read_Filter6
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_Filter6_read
)
def
write_Filter6
(
self
,
attr
):
data
=
attr
.
get_write_value
()
self
.
attr_Filter6_read
=
data
def
read_Filter7
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_Filter7_read
)
def
write_Filter7
(
self
,
attr
):
data
=
attr
.
get_write_value
()
self
.
attr_Filter7_read
=
data
def
read_MotorTitle
(
self
,
attr
):
attr
.
set_value
(
self
.
attr_MotorTitle_read
)
def
write_MotorTitle
(
self
,
attr
):
data
=
attr
.
get_write_value
()
self
.
attr_MotorTitle_read
=
data
#==================================================================
#
# FilterWheel command methods
#
#==================================================================
def
SetClear
(
self
):
# self.debug_stream("In SetClear()")
self
.
select_filter
(
1
)
self
.
debug_stream
(
"
Selecting filter 1 (Clear or no-filter)
"
)
def
is_SetClear_allowed
(
self
):
return
self
.
get_state
()
in
(
PyTango
.
DevState
.
ON
,
PyTango
.
DevState
.
ALARM
,)
def
SetFilter
(
self
,
filter_number
):
# self.debug_stream("In SetFilter()")
if
1
<=
filter_number
<=
7
:
self
.
select_filter
(
filter_number
)
self
.
debug_stream
(
"
Selecting filter
"
+
str
(
filter_number
))
else
:
self
.
error_stream
(
"
Invalid filter number.
"
)
PyTango
.
Except
.
throw_exception
(
"
SetFilter Error
"
,
"
Filter number out of range
"
,
"
SetFilter()
"
)
def
is_SetFilter_allowed
(
self
):
return
self
.
get_state
()
in
(
PyTango
.
DevState
.
ON
,
PyTango
.
DevState
.
ALARM
,)
#==================================================================
#
# FilterWheelClass class definition
#
#==================================================================
class
FilterWheelClass
(
PyTango
.
DeviceClass
):
# Class Properties
class_property_list
=
{
}
# Device Properties
device_property_list
=
{
'
FilterWheelDevice
'
:
[
PyTango
.
DevString
,
"
Tango Device that controls the FilterWheel motor.
"
,
[]],
}
# Command definitions
cmd_list
=
{
'
SetClear
'
:
[[
PyTango
.
DevVoid
,
"
none
"
],
[
PyTango
.
DevVoid
,
"
none
"
]],
'
SetFilter
'
:
[[
PyTango
.
DevShort
,
"
Filter number 1-7
"
],
[
PyTango
.
DevVoid
,
"
none
"
]],
}
# Attribute definitions
attr_list
=
{
'
CurrentPosition
'
:
[[
PyTango
.
DevFloat
,
PyTango
.
SCALAR
,
PyTango
.
READ
],
{
'
description
'
:
"
Currently selected filter
"
,
'
Memorized
'
:
"
False
"
,
}],
'
CurrentIndex
'
:
[[
PyTango
.
DevShort
,
PyTango
.
SCALAR
,
PyTango
.
READ
],
{
'
description
'
:
"
Currently selected filter index (1-7), 0 if None
"
,
'
Memorized
'
:
"
False
"
,
}],
'
CurrentFilter
'
:
[[
PyTango
.
DevString
,
PyTango
.
SCALAR
,
PyTango
.
READ
],
{
'
description
'
:
"
Currently selected filter
"
,
'
Memorized
'
:
"
False
"
,
}],
'
Filter1
'
:
[[
PyTango
.
DevString
,
PyTango
.
SCALAR
,
PyTango
.
READ_WRITE
],
{
'
description
'
:
"
Filter at position 1
"
,
'
Memorized
'
:
"
True
"
,
}],
'
Filter2
'
:
[[
PyTango
.
DevString
,
PyTango
.
SCALAR
,
PyTango
.
READ_WRITE
],
{
'
description
'
:
"
Filter at position 2
"
,
'
Memorized
'
:
"
True
"
,
}],
'
Filter3
'
:
[[
PyTango
.
DevString
,
PyTango
.
SCALAR
,
PyTango
.
READ_WRITE
],
{
'
description
'
:
"
Filter at position 3
"
,
'
Memorized
'
:
"
True
"
,
}],
'
Filter4
'
:
[[
PyTango
.
DevString
,
PyTango
.
SCALAR
,
PyTango
.
READ_WRITE
],
{
'
description
'
:
"
Filter at position 4
"
,
'
Memorized
'
:
"
True
"
,
}],
'
Filter5
'
:
[[
PyTango
.
DevString
,
PyTango
.
SCALAR
,
PyTango
.
READ_WRITE
],
{
'
description
'
:
"
Filter at position 5
"
,
'
Memorized
'
:
"
True
"
,
}],
'
Filter6
'
:
[[
PyTango
.
DevString
,
PyTango
.
SCALAR
,
PyTango
.
READ_WRITE
],
{
'
description
'
:
"
Filter at position 6
"
,
'
Memorized
'
:
"
True
"
,
}],
'
Filter7
'
:
[[
PyTango
.
DevString
,
PyTango
.
SCALAR
,
PyTango
.
READ_WRITE
],
{
'
description
'
:
"
Filter at position 7
"
,
'
Memorized
'
:
"
True
"
,
}],
'
MotorTitle
'
:
[[
PyTango
.
DevString
,
PyTango
.
SCALAR
,
PyTango
.
READ_WRITE
],
{
'
description
'
:
"
Motor
'
s given name for the GUI
'
s title label.
"
,
'
memorized
'
:
"
true
"
,
}],
}
#------------------------------------------------------------------
# FilterWheelClass Constructor
#------------------------------------------------------------------
def
__init__
(
self
,
name
):
print
'
In FilterWheelClass constructor
'
PyTango
.
DeviceClass
.
__init__
(
self
,
name
)
self
.
set_type
(
name
)
#==================================================================
#
# FilterWheel class main method
#
#==================================================================
if
__name__
==
'
__main__
'
:
try
:
py
=
PyTango
.
Util
(
sys
.
argv
)
py
.
add_TgClass
(
FilterWheelClass
,
FilterWheel
,
'
FilterWheel
'
)
U
=
PyTango
.
Util
.
instance
()
U
.
server_init
()
U
.
server_run
()
except
PyTango
.
DevFailed
,
e
:
print
'
-------> Received a DevFailed exception:
'
,
e
except
Exception
,
e
:
print
'
-------> An unforeseen exception occured....
'
,
e
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