Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bliss
bliss
Commits
ec229a7d
Commit
ec229a7d
authored
Jun 21, 2021
by
Perceval Guillou
Browse files
handle ref obj and motor old signature
parent
d72e8235
Changes
9
Show whitespace changes
Inline
Side-by-side
bliss/config/static.py
View file @
ec229a7d
...
@@ -1025,6 +1025,10 @@ class Config(metaclass=Singleton):
...
@@ -1025,6 +1025,10 @@ class Config(metaclass=Singleton):
module_name
=
config_node
.
plugin
module_name
=
config_node
.
plugin
if
module_name
is
None
:
if
module_name
is
None
:
module_name
=
"default"
module_name
=
"default"
if
module_name
in
[
"emotion"
,
"regulation"
,
"diffractometer"
]:
module_name
=
"bliss_controller"
m
=
__import__
(
"bliss.config.plugins.%s"
%
(
module_name
),
fromlist
=
[
None
])
m
=
__import__
(
"bliss.config.plugins.%s"
%
(
module_name
),
fromlist
=
[
None
])
if
hasattr
(
m
,
"create_object_from_cache"
):
if
hasattr
(
m
,
"create_object_from_cache"
):
cache_object
=
self
.
_name2cache
.
pop
(
cache_object
=
self
.
_name2cache
.
pop
(
...
...
bliss/controllers/bliss_controller.py
View file @
ec229a7d
...
@@ -227,10 +227,15 @@ class BlissController(CounterContainer):
...
@@ -227,10 +227,15 @@ class BlissController(CounterContainer):
if
isinstance
(
cfg_name
,
str
):
if
isinstance
(
cfg_name
,
str
):
item_class
=
self
.
__find_item_class
(
cfg
,
pkey
)
item_class
=
self
.
__find_item_class
(
cfg
,
pkey
)
item_obj
=
None
else
:
# its a referenced object (cfg_name contains the object instance)
else
:
# its a referenced object (cfg_name contains the object instance)
item_class
=
None
item_class
=
None
item_obj
=
cfg_name
cfg_name
=
item_obj
.
name
item
=
self
.
_create_subitem_from_config
(
cfg_name
,
cfg
,
pkey
,
item_class
)
item
=
self
.
_create_subitem_from_config
(
cfg_name
,
cfg
,
pkey
,
item_class
,
item_obj
)
if
item
is
None
:
if
item
is
None
:
msg
=
f
"
\n
Unable to obtain item
{
cfg_name
}
from
{
self
.
name
}
with:
\n
"
msg
=
f
"
\n
Unable to obtain item
{
cfg_name
}
from
{
self
.
name
}
with:
\n
"
msg
+=
f
" class:
{
item_class
}
\n
"
msg
+=
f
" class:
{
item_class
}
\n
"
...
@@ -392,16 +397,19 @@ class BlissController(CounterContainer):
...
@@ -392,16 +397,19 @@ class BlissController(CounterContainer):
raise
NotImplementedError
raise
NotImplementedError
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
):
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
,
item_obj
=
None
):
# Called when a new subitem is created (i.e accessed for the first time via self._get_subitem)
# Called when a new subitem is created (i.e accessed for the first time via self._get_subitem)
"""
"""
Return the instance of a new item owned by this controller.
Return the instance of a new item owned by this controller.
args:
args:
name: item name
(or instance of a referenced object if item_class is None)
name: item name
cfg : item config
cfg : item config
parent_key: the config key under which the item was found (ex: 'counters').
parent_key: the config key under which the item was found (ex: 'counters').
item_class: a class to instantiate the item (=None for referenced item)
item_class: a class to instantiate the item (None if item is a reference)
item_obj: the item instance (None if item is NOT a reference)
return: item instance
return: item instance
...
...
bliss/controllers/bliss_controller_mockup.py
View file @
ec229a7d
...
@@ -120,7 +120,9 @@ class BCMockup(BlissController):
...
@@ -120,7 +120,9 @@ class BCMockup(BlissController):
elif
self
.
_COUNTER_TAGS
[
tag
][
1
]
==
"icc"
:
elif
self
.
_COUNTER_TAGS
[
tag
][
1
]
==
"icc"
:
return
"IntegratingCounter"
return
"IntegratingCounter"
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
):
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
,
item_obj
=
None
):
if
parent_key
==
"counters"
:
if
parent_key
==
"counters"
:
name
=
cfg
[
"name"
]
name
=
cfg
[
"name"
]
tag
=
cfg
[
"tag"
]
tag
=
cfg
[
"tag"
]
...
@@ -150,8 +152,7 @@ class BCMockup(BlissController):
...
@@ -150,8 +152,7 @@ class BCMockup(BlissController):
elif
parent_key
==
"axes"
:
elif
parent_key
==
"axes"
:
if
item_class
is
None
:
# mean it is a referenced axis (i.e external axis)
if
item_class
is
None
:
# mean it is a referenced axis (i.e external axis)
axis
=
name
# the axis instance
axis
=
item_obj
name
=
axis
.
name
# the axis name
tag
=
cfg
[
tag
=
cfg
[
"tag"
"tag"
]
# ask for a tag which only concerns this ctrl (local tag)
]
# ask for a tag which only concerns this ctrl (local tag)
...
@@ -296,9 +297,13 @@ class Operator:
...
@@ -296,9 +297,13 @@ class Operator:
class
TestBCMockup
(
BCMockup
):
class
TestBCMockup
(
BCMockup
):
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
):
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
,
item_obj
=
None
):
item
=
super
().
_create_subitem_from_config
(
name
,
cfg
,
parent_key
,
item_class
)
item
=
super
().
_create_subitem_from_config
(
name
,
cfg
,
parent_key
,
item_class
,
item_obj
)
if
item
is
None
:
if
item
is
None
:
if
parent_key
in
[
"fakeitems"
,
"subsection"
]:
if
parent_key
in
[
"fakeitems"
,
"subsection"
]:
...
...
bliss/controllers/motor.py
View file @
ec229a7d
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
# Copyright (c) 2015-2020 Beamline Control Unit, ESRF
# Copyright (c) 2015-2020 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from
os
import
name
import
numpy
import
numpy
import
functools
import
functools
from
gevent
import
lock
from
gevent
import
lock
...
@@ -61,7 +62,14 @@ class Controller(BlissController):
...
@@ -61,7 +62,14 @@ class Controller(BlissController):
Motor controller base class
Motor controller base class
"""
"""
def
__init__
(
self
,
config
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
# config
if
len
(
args
)
==
1
:
config
=
args
[
0
]
else
:
# handle old signature: args = [ name, config, axes, encoders, shutters, switches ]
config
=
args
[
1
]
super
().
__init__
(
config
)
super
().
__init__
(
config
)
self
.
__motor_config
=
MotorConfig
(
config
)
self
.
__motor_config
=
MotorConfig
(
config
)
...
@@ -125,12 +133,13 @@ class Controller(BlissController):
...
@@ -125,12 +133,13 @@ class Controller(BlissController):
return
"Switch"
return
"Switch"
@
check_disabled
@
check_disabled
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
):
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
,
item_obj
=
None
):
if
parent_key
==
"axes"
:
if
parent_key
==
"axes"
:
if
item_class
is
None
:
# it is a reference and name is the object
if
item_class
is
None
:
# it is a reference
axis
=
name
axis
=
item_obj
name
=
axis
.
name
else
:
else
:
axis
=
item_class
(
name
,
self
,
cfg
)
axis
=
item_class
(
name
,
self
,
cfg
)
...
...
bliss/controllers/motors/mockup.py
View file @
ec229a7d
...
@@ -72,8 +72,8 @@ class MockupAxis(Axis):
...
@@ -72,8 +72,8 @@ class MockupAxis(Axis):
class
Mockup
(
Controller
):
class
Mockup
(
Controller
):
def
__init__
(
self
,
config
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
#
config
super
().
__init__
(
config
)
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
_axis_moves
=
{}
self
.
_axis_moves
=
{}
self
.
__encoders
=
{}
self
.
__encoders
=
{}
...
@@ -89,14 +89,16 @@ class Mockup(Controller):
...
@@ -89,14 +89,16 @@ class Mockup(Controller):
self
.
_hw_state
.
create_state
(
"PARKED"
,
"mot au parking"
)
self
.
_hw_state
.
create_state
(
"PARKED"
,
"mot au parking"
)
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
):
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
,
item_obj
=
None
):
if
parent_key
==
"switches"
:
if
parent_key
==
"switches"
:
switch
=
item_class
(
name
,
self
,
cfg
)
switch
=
item_class
(
name
,
self
,
cfg
)
self
.
_switches
[
name
]
=
switch
self
.
_switches
[
name
]
=
switch
return
switch
return
switch
else
:
else
:
return
super
().
_create_subitem_from_config
(
return
super
().
_create_subitem_from_config
(
name
,
cfg
,
parent_key
,
item_class
name
,
cfg
,
parent_key
,
item_class
,
item_obj
)
)
def
steps_position_precision
(
self
,
axis
):
def
steps_position_precision
(
self
,
axis
):
...
...
bliss/controllers/regulator.py
View file @
ec229a7d
...
@@ -106,7 +106,9 @@ class Controller(BlissController):
...
@@ -106,7 +106,9 @@ class Controller(BlissController):
item_classes
=
{
"inputs"
:
"Input"
,
"outputs"
:
"Output"
,
"ctrl_loops"
:
"Loop"
}
item_classes
=
{
"inputs"
:
"Input"
,
"outputs"
:
"Output"
,
"ctrl_loops"
:
"Loop"
}
return
item_classes
[
parent_key
]
return
item_classes
[
parent_key
]
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
):
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
,
item_obj
=
None
):
item
=
item_class
(
self
,
cfg
)
item
=
item_class
(
self
,
cfg
)
# --- For custom attributes and commands.
# --- For custom attributes and commands.
set_custom_members
(
self
,
item
,
self
.
init_obj
)
# really needed ???????
set_custom_members
(
self
,
item
,
self
.
init_obj
)
# really needed ???????
...
...
doc/docs/dev_write_ctrl.md
View file @
ec229a7d
...
@@ -189,19 +189,19 @@ To be able to decide which instance should be created, the method receives 4 arg
...
@@ -189,19 +189,19 @@ To be able to decide which instance should be created, the method receives 4 arg
-
`cfg`
: subitem config
-
`cfg`
: subitem config
-
`parent_key`
: name of the subsection where the item was found (in controller's config)
-
`parent_key`
: name of the subsection where the item was found (in controller's config)
-
`item_class`
: class for the subitem (see
[
BlissController and sub-items
](
dev_write_ctrl.md#BlissController-and-subitems
)
).
-
`item_class`
: class for the subitem (see
[
BlissController and sub-items
](
dev_write_ctrl.md#BlissController-and-subitems
)
).
If
`None`
then the subitem is a reference and the object exist already and is contained in
`name`
.
-
`item_obj`
: the object instance for item as a reference (None if not a reference)
If
`item_class`
is
`None`
then the subitem is a reference and the object exist already and is contained in
`item_obj`
.
Examples:
Examples:
```
python
```
python
@
check_disabled
@
check_disabled
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
):
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
,
item_obj
=
None
):
if
parent_key
==
"axes"
:
if
parent_key
==
"axes"
:
if
item_class
is
None
:
# it is a reference and name is the object
if
item_class
is
None
:
# it is a reference
axis
=
name
axis
=
item_obj
name
=
axis
.
name
else
:
else
:
axis
=
item_class
(
name
,
self
,
cfg
)
axis
=
item_class
(
name
,
self
,
cfg
)
...
@@ -239,7 +239,7 @@ or
...
@@ -239,7 +239,7 @@ or
```
python
```
python
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
):
def
_create_subitem_from_config
(
self
,
name
,
cfg
,
parent_key
,
item_class
,
item_obj
=
None
):
if
parent_key
==
"counters"
:
if
parent_key
==
"counters"
:
name
=
cfg
[
"name"
]
name
=
cfg
[
"name"
]
tag
=
cfg
[
"tag"
]
tag
=
cfg
[
"tag"
]
...
@@ -268,9 +268,8 @@ def _create_subitem_from_config(self, name, cfg, parent_key, item_class):
...
@@ -268,9 +268,8 @@ def _create_subitem_from_config(self, name, cfg, parent_key, item_class):
return
item_class
(
cfg
)
return
item_class
(
cfg
)
elif
parent_key
==
"axes"
:
elif
parent_key
==
"axes"
:
if
item_class
is
None
:
# mean it is a referenced axis (i.e external axis)
if
item_class
is
None
:
# it is a referenced axis (i.e external axis)
axis
=
name
# the axis instance
axis
=
item_obj
# the axis instance
name
=
axis
.
name
# the axis name
tag
=
cfg
[
tag
=
cfg
[
"tag"
"tag"
]
# ask for a tag which only concerns this ctrl (local tag)
]
# ask for a tag which only concerns this ctrl (local tag)
...
...
tests/motors/test_initialization.py
View file @
ec229a7d
...
@@ -128,9 +128,9 @@ def test_broken_controller_init(default_session):
...
@@ -128,9 +128,9 @@ def test_broken_controller_init(default_session):
# === now config._name2instance is still empty because _controller_init() has failed and roby was not instanciated
# === now config._name2instance is still empty because _controller_init() has failed and roby was not instanciated
# === config._name2cache is also empty because cacheditems have been removed when _controller_init() has failed
# === config._name2cache is also empty because cacheditems have been removed when _controller_init() has failed
print
(
"=== match=FAILED TO INITIALIZE"
)
#
print("=== match=FAILED TO INITIALIZE")
print
(
"=== name2instance:"
,
list
(
config
.
_name2instance
.
keys
()))
#
print("=== name2instance:", list(config._name2instance.keys()))
print
(
"=== name2cache:"
,
list
(
config
.
_name2cache
.
keys
()))
#
print("=== name2cache:", list(config._name2cache.keys()))
assert
list
(
config
.
_name2instance
.
keys
())
==
[]
assert
list
(
config
.
_name2instance
.
keys
())
==
[]
assert
list
(
config
.
_name2cache
.
keys
())
==
[]
assert
list
(
config
.
_name2cache
.
keys
())
==
[]
...
@@ -142,9 +142,9 @@ def test_broken_controller_init(default_session):
...
@@ -142,9 +142,9 @@ def test_broken_controller_init(default_session):
# === now config._name2instance is still empty because _controller_init() has failed and roby was not instanciated
# === now config._name2instance is still empty because _controller_init() has failed and roby was not instanciated
# === config._name2cache is also empty because cacheditems have been removed when _controller_init() has failed
# === config._name2cache is also empty because cacheditems have been removed when _controller_init() has failed
print
(
"=== match=FAILED TO INITIALIZE"
)
#
print("=== match=FAILED TO INITIALIZE")
print
(
"=== name2instance:"
,
list
(
config
.
_name2instance
.
keys
()))
#
print("=== name2instance:", list(config._name2instance.keys()))
print
(
"=== name2cache:"
,
list
(
config
.
_name2cache
.
keys
()))
#
print("=== name2cache:", list(config._name2cache.keys()))
assert
list
(
config
.
_name2instance
.
keys
())
==
[]
assert
list
(
config
.
_name2instance
.
keys
())
==
[]
assert
list
(
config
.
_name2cache
.
keys
())
==
[]
assert
list
(
config
.
_name2cache
.
keys
())
==
[]
...
@@ -161,10 +161,10 @@ def test_broken_controller_init(default_session):
...
@@ -161,10 +161,10 @@ def test_broken_controller_init(default_session):
assert
(
assert
(
roby
.
controller
.
_disabled
==
False
roby
.
controller
.
_disabled
==
False
)
# not yet disabled because of lasy hardware init
)
# not yet disabled because of lasy hardware init
print
(
"=== assert roby True"
)
#
print("=== assert roby True")
print
(
"=== name2instance:"
,
list
(
config
.
_name2instance
.
keys
()))
#
print("=== name2instance:", list(config._name2instance.keys()))
print
(
"=== name2cache:"
,
list
(
config
.
_name2cache
.
keys
()))
#
print("=== name2cache:", list(config._name2cache.keys()))
assert
"roby"
in
list
(
config
.
_name2instance
.
keys
())
#
assert "roby" in list(config._name2instance.keys())
assert
"roby"
not
in
list
(
assert
"roby"
not
in
list
(
config
.
_name2cache
.
keys
()
config
.
_name2cache
.
keys
()
)
# roby has been has been initialized and the removed from config cached items
)
# roby has been has been initialized and the removed from config cached items
...
...
tests/test_configuration/dummy.yml
View file @
ec229a7d
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
-
name
:
dummy2
-
name
:
dummy2
t_value
:
bla
t_value
:
bla
-
plugin
:
bliss_controller
#
emotion
-
plugin
:
emotion
class
:
DummyCtrl
class
:
DummyCtrl
package
:
test_initialization
package
:
test_initialization
axes
:
axes
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment