Skip to content

huber

borealis.controller.huber

Huber controller SMC.

Created on Tue Jan 10 21:17:12 2023.

@author: A. Vancraeyenest

HuberSMC(ip_address, port=1234, alias='')

Bases: Controller

Class to communicate with Huber controller.

Initialise the connection to the device.

Source code in borealis/controller/huber.py
20
21
22
23
24
25
26
27
28
29
def __init__(self, ip_address: str, port: int = 1234, alias: str = ""):
    """Initialise the connection to the device."""
    self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self._socket.connect((ip_address, port))
    LOGGER.debug("Opening connection on port %d at IP address %s", port, ip_address)

    ans = self._read().decode().strip('\r\n')
    alias = alias if alias !='' else f'HuberSMC {ans}'
    super().__init__(alias=alias)
    LOGGER.info("%s successfully initialised", self)

clean_axis_error(axis_id)

Clean axis related errors.

Source code in borealis/controller/huber.py
 99
100
101
102
103
def clean_axis_error(self, axis_id: str):
    """Clean axis related errors."""
    self._write(f'cerr{axis_id}')
    LOGGER.debug("%s: Error cleared for axis %s.",
                 self.alias, axis_id)

decode_axis_position(pos_msg) staticmethod

Decode single axis position message.

Source code in borealis/controller/huber.py
111
112
113
114
115
@staticmethod
def decode_axis_position(pos_msg):
    """Decode single axis position message."""
    pos = pos_msg.decode().strip(";\r\n").split(":")
    return float(pos[1])

decode_axis_status(sta_msg) staticmethod

Decode single axis status message.

Source code in borealis/controller/huber.py
117
118
119
120
121
122
123
124
125
126
127
128
129
@staticmethod
def decode_axis_status(sta_msg):
    """Decode single axis status message."""
    sta = sta_msg.decode().strip("\r\n").split(":")
    status = {'error number': sta[1],
              'error message': sta[2],
              'position': sta[3],
              'encoder position': sta[4],
              'limit switch status': sta[5],
              'home position status': sta[6],
              'reference position status': sta[7],
              'axis ready': sta[8]}
    return status

get_axis_error(axis_id)

Get error message from a given axis.

Source code in borealis/controller/huber.py
90
91
92
93
94
95
96
97
def get_axis_error(self, axis_id: str):
    """Get error message from a given axis."""
    status = self.get_axis_status(axis_id)
    self.clean_axis_error(axis_id)
    LOGGER.debug("%s: Axis %s error: %s %s",
                 self.alias, axis_id,
                 status['error number'], status['error message'])
    return status['error number'], status['error message']

get_axis_position(axis_id)

Get the dial position for a single axis.

Source code in borealis/controller/huber.py
39
40
41
42
43
def get_axis_position(self, axis_id: str):
    """Get the dial position for a single axis."""
    self._write(f'?p{axis_id}')
    pos = self._read()
    return self.decode_axis_position(pos)

is_axis_ready(axis_id)

Check that a given axis is ready (idle).

Source code in borealis/controller/huber.py
45
46
47
48
49
50
51
52
53
54
def is_axis_ready(self, axis_id: str):
    """Check that a given axis is ready (idle)."""
    status = self.get_axis_status(axis_id)['axis ready']
    if status == '1':
        LOGGER.debug("%s: axis %s ready (i.e. idle).",
                     self.alias, axis_id)
    else:
        LOGGER.debug("%s: axis %s not ready yet (i.e. not idle).",
                     self.alias, axis_id)
    return status == '1'

is_limit_switch_activated(axis_id)

Check if limit switch is active for a given axis.

Source code in borealis/controller/huber.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def is_limit_switch_activated(self, axis_id: str):
    """Check if limit switch is active for a given axis."""
    status = self.get_axis_status(axis_id)
    if status['limit switch status'] == '0':
        return False
    else:
        if status['limit switch status'] == '1':
            # print('Limit switch [-] activated')
            LOGGER.info("%s: Limit switch [-] of axis %s activated.",
                        self.alias, axis_id)
        elif status['limit switch status'] == '2':
            # print('Limit switch [+] activated')
            LOGGER.info("%s: Limit switch [+] of axis %s activated.",
                        self.alias, axis_id)
        return True

move_axis(axis_id, target=0)

Move a single axis to a target position.

Source code in borealis/controller/huber.py
32
33
34
35
36
37
def move_axis(self, axis_id: str, target: float = 0):
    """Move a single axis to a target position."""
    self._write(f'goto{axis_id}:{target}')
    self.wait_motion_end(axis_id, target)
    LOGGER.debug("%s: Moving axis %s to %f (dial).",
                 self.alias, axis_id, target)

set_axis_to_zero(axis_id)

Set axis position to 0.

Source code in borealis/controller/huber.py
72
73
74
75
76
def set_axis_to_zero(self, axis_id: str):
    """Set axis position to 0."""
    self._write(f'zero{axis_id}')
    LOGGER.debug("%s: Axis %s position set to 0 (home).",
                 self.alias, axis_id)