Skip to content
GitLab
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
Hide whitespace changes
Inline
Side-by-side
bliss/config/static.py
View file @
ec229a7d
...
...
@@ -1025,6 +1025,10 @@ class Config(metaclass=Singleton):
module_name
=
config_node
.
plugin
if
module_name
is
None
:
module_name
=
"default"
if
module_name
in
[
"emotion"
,
"regulation"
,
"diffractometer"
]:
module_name
=
"bliss_controller"
m
=
__import__
(
"bliss.config.plugins.%s"
%
(
module_name
),
fromlist
=
[
None
])
if
hasattr
(
m
,
"create_object_from_cache"
):
cache_object
=
self
.
_name2cache
.
pop
(
...
...
bliss/controllers/bliss_controller.py
View file @
ec229a7d
...
...
@@ -227,10 +227,15 @@ class BlissController(CounterContainer):
if
isinstance
(
cfg_name
,
str
):
item_class
=
self
.
__find_item_class
(
cfg
,
pkey
)
item_obj
=
None
else
:
# its a referenced object (cfg_name contains the object instance)
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
:
msg
=
f
"
\n
Unable to obtain item
{
cfg_name
}
from
{
self
.
name
}
with:
\n
"
msg
+=
f
" class:
{
item_class
}
\n
"
...
...
@@ -392,16 +397,19 @@ class BlissController(CounterContainer):
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)
"""
Return the instance of a new item owned by this controller.
args:
name: item name
(or instance of a referenced object if item_class is None)
name: item name
cfg : item config
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
...
...
bliss/controllers/bliss_controller_mockup.py
View file @
ec229a7d
...
...
@@ -120,7 +120,9 @@ class BCMockup(BlissController):
elif
self
.
_COUNTER_TAGS
[
tag
][
1
]
==
"icc"
:
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"
:
name
=
cfg
[
"name"
]
tag
=
cfg
[
"tag"
]
...
...
@@ -150,8 +152,7 @@ class BCMockup(BlissController):
elif
parent_key
==
"axes"
:
if
item_class
is
None
:
# mean it is a referenced axis (i.e external axis)
axis
=
name
# the axis instance
name
=
axis
.
name
# the axis name
axis
=
item_obj
tag
=
cfg
[
"tag"
]
# ask for a tag which only concerns this ctrl (local tag)
...
...
@@ -296,9 +297,13 @@ class Operator:
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
parent_key
in
[
"fakeitems"
,
"subsection"
]:
...
...
bliss/controllers/motor.py
View file @
ec229a7d
...
...
@@ -5,6 +5,7 @@
# Copyright (c) 2015-2020 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from
os
import
name
import
numpy
import
functools
from
gevent
import
lock
...
...
@@ -61,7 +62,14 @@ class Controller(BlissController):
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
)
self
.
__motor_config
=
MotorConfig
(
config
)
...
...
@@ -125,12 +133,13 @@ class Controller(BlissController):
return
"Switch"
@
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
item_class
is
None
:
# it is a reference and name is the object
axis
=
name
name
=
axis
.
name
if
item_class
is
None
:
# it is a reference
axis
=
item_obj
else
:
axis
=
item_class
(
name
,
self
,
cfg
)
...
...
bliss/controllers/motors/mockup.py
View file @
ec229a7d
...
...
@@ -72,8 +72,8 @@ class MockupAxis(Axis):
class
Mockup
(
Controller
):
def
__init__
(
self
,
config
):
super
().
__init__
(
config
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
#
config
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
_axis_moves
=
{}
self
.
__encoders
=
{}
...
...
@@ -89,14 +89,16 @@ class Mockup(Controller):
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"
:
switch
=
item_class
(
name
,
self
,
cfg
)
self
.
_switches
[
name
]
=
switch
return
switch
else
:
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
):
...
...
bliss/controllers/regulator.py
View file @
ec229a7d
...
...
@@ -106,7 +106,9 @@ class Controller(BlissController):
item_classes
=
{
"inputs"
:
"Input"
,
"outputs"
:
"Output"
,
"ctrl_loops"
:
"Loop"
}
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
)
# --- For custom attributes and commands.
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
-
`cfg`
: subitem 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
)
).
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:
```
python
@
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
item_class
is
None
:
# it is a reference and name is the object
axis
=
name
name
=
axis
.
name
if
item_class
is
None
:
# it is a reference
axis
=
item_obj
else
:
axis
=
item_class
(
name
,
self
,
cfg
)
...
...
@@ -239,7 +239,7 @@ or
```
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"
:
name
=
cfg
[
"name"
]
tag
=
cfg
[
"tag"
]
...
...
@@ -268,9 +268,8 @@ def _create_subitem_from_config(self, name, cfg, parent_key, item_class):
return
item_class
(
cfg
)
elif
parent_key
==
"axes"
:
if
item_class
is
None
:
# mean it is a referenced axis (i.e external axis)
axis
=
name
# the axis instance
name
=
axis
.
name
# the axis name
if
item_class
is
None
:
# it is a referenced axis (i.e external axis)
axis
=
item_obj
# the axis instance
tag
=
cfg
[
"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):
# === 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
print
(
"=== match=FAILED TO INITIALIZE"
)
print
(
"=== name2instance:"
,
list
(
config
.
_name2instance
.
keys
()))
print
(
"=== name2cache:"
,
list
(
config
.
_name2cache
.
keys
()))
#
print("=== match=FAILED TO INITIALIZE")
#
print("=== name2instance:", list(config._name2instance.keys()))
#
print("=== name2cache:", list(config._name2cache.keys()))
assert
list
(
config
.
_name2instance
.
keys
())
==
[]
assert
list
(
config
.
_name2cache
.
keys
())
==
[]
...
...
@@ -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
# === config._name2cache is also empty because cacheditems have been removed when _controller_init() has failed
print
(
"=== match=FAILED TO INITIALIZE"
)
print
(
"=== name2instance:"
,
list
(
config
.
_name2instance
.
keys
()))
print
(
"=== name2cache:"
,
list
(
config
.
_name2cache
.
keys
()))
#
print("=== match=FAILED TO INITIALIZE")
#
print("=== name2instance:", list(config._name2instance.keys()))
#
print("=== name2cache:", list(config._name2cache.keys()))
assert
list
(
config
.
_name2instance
.
keys
())
==
[]
assert
list
(
config
.
_name2cache
.
keys
())
==
[]
...
...
@@ -161,10 +161,10 @@ def test_broken_controller_init(default_session):
assert
(
roby
.
controller
.
_disabled
==
False
)
# not yet disabled because of lasy hardware init
print
(
"=== assert roby True"
)
print
(
"=== name2instance:"
,
list
(
config
.
_name2instance
.
keys
()))
print
(
"=== name2cache:"
,
list
(
config
.
_name2cache
.
keys
()))
assert
"roby"
in
list
(
config
.
_name2instance
.
keys
())
#
print("=== assert roby True")
#
print("=== name2instance:", list(config._name2instance.keys()))
#
print("=== name2cache:", list(config._name2cache.keys()))
#
assert "roby" in list(config._name2instance.keys())
assert
"roby"
not
in
list
(
config
.
_name2cache
.
keys
()
)
# 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 @@
-
name
:
dummy2
t_value
:
bla
-
plugin
:
bliss_controller
#
emotion
-
plugin
:
emotion
class
:
DummyCtrl
package
:
test_initialization
axes
:
...
...
Write
Preview
Supports
Markdown
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!
Cancel
Please
register
or
sign in
to comment