soft_axis.py 1.37 KB
Newer Older
1
2
3
4
5
6
7
8
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.

from bliss.controllers.motors.soft import SoftController
9
from bliss.common.session import get_current_session
10
11
12
13
14
15
16
17


def SoftAxis(
    name,
    obj,
    position="position",
    move="position",
    stop=None,
18
    state=None,
19
20
    low_limit=float("-inf"),
    high_limit=float("+inf"),
21
    tolerance=None,
22
    export_to_session=True,
Perceval Guillou's avatar
Perceval Guillou committed
23
    unit=None,
24
25
):

26
    config = {"low_limit": low_limit, "high_limit": high_limit, "name": name}
27
28
29
30

    if tolerance is not None:
        config["tolerance"] = tolerance

Perceval Guillou's avatar
Perceval Guillou committed
31
32
33
    if unit is not None:
        config["unit"] = unit

34
    controller = SoftController(name, obj, config, position, move, stop, state)
35
    controller._controller_init()
36
37

    axis = controller.get_axis(name)
Jibril Mammeri's avatar
Jibril Mammeri committed
38
    axis._positioner = False
39
40
41
42

    if export_to_session:
        current_session = get_current_session()
        if current_session is not None:
43
44
45
46
47
48
49
50
            if (
                name in current_session.config.names_list
                or name in current_session.env_dict.keys()
            ):
                raise ValueError(
                    f"Cannot export object to session with the name '{name}', name is already taken! "
                )

51
52
            current_session.env_dict[name] = axis

53
    return axis