Commit dbd8bf69 authored by Laurent Claustre's avatar Laurent Claustre

Merge branch 'info_axis_improved' into 'master'

Info axis improved

See merge request !2048
parents e60d86ad 4dfc9769
Pipeline #21202 failed with stages
in 54 minutes and 5 seconds
......@@ -327,6 +327,10 @@ class BaseSocket:
class Socket(BaseSocket):
def __info__(self):
info_str = f"TCP SOCKET: host={self._host} port={self._port} \n"
return info_str
def _connect(self, host, port):
fd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
fd.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
......@@ -471,6 +475,10 @@ class Command:
def __str__(self):
return f"{self.__class__.__name__}[{self._host}:{self._port}]"
def __info__(self):
info_str = "TCP COMMAND: host={self._host} port={self._port} \n"
return info_str
@property
def lock(self):
return self._lock
......
......@@ -17,6 +17,10 @@ from bliss.common.logtools import *
class Socket(BaseSocket):
def __info__(self):
info_str = "UDP SOCKET: host={self._host} port={self._port} \n"
return info_str
def _connect(self, host, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_IP, socket.IP_TOS, 0x10)
......
......@@ -910,62 +910,81 @@ class Axis:
Return common axis information about the axis.
PLUS controller specific information.
"""
_info_string = ""
_info_string += f"axis name (R): {self.name}\n"
_info_string += f" state (R): {self.state}\n"
_info_string += f" unit (R): {self.unit}\n"
_info_string += f" offset (R): {self.offset}\n"
_info_string += f" backlash (R): {self.backlash}\n"
_info_string += f" sign (R): {self.sign}\n"
_info_string += f" steps_per_unit (R): {self.steps_per_unit}\n"
_info_string += (
f" tolerance (R) (to check pos. before a move): {self.tolerance}\n"
)
_info_string += f" motion_hooks (R): {self.motion_hooks}\n"
_info_string += f" dial (RW): {self.dial:.5f}\n"
_info_string += f" position (RW): {self.position:.5f}\n"
_info_string += f" _hw_position (R): {self._hw_position:.5f}\n"
_info_string += f" hw_state (R): {self.hw_state}\n"
_info_string += (
f" limits (RW): {self.limits} (config: {self.config_limits})\n"
)
info_string = "AXIS:\n"
try:
# Config parameters.
info_string += f" name (R): {self.name}\n"
info_string += f" unit (R): {self.unit}\n"
info_string += f" offset (R): {self.offset:.5f}\n"
info_string += f" backlash (R): {self.backlash:.5f}\n"
info_string += f" sign (R): {self.sign}\n"
info_string += f" steps_per_unit (R): {self.steps_per_unit:.2f}\n"
info_string += (
f" tolerance (R) (to check pos. before a move): {self.tolerance}\n"
)
except:
info_string += "ERROR: unable to get info (config problem?)\n"
# To avoid error if no acceleration.
try:
# These parameters access to the device.
_low_cfg_limit, _high_cfg_limit = self.config_limits
_lim = f"Low: {self.low_limit:.5f} High: {self.high_limit:.5f}"
_cfg_lim = f"(config Low: {_low_cfg_limit:.5f} High: {_high_cfg_limit:.5f})"
info_string += f" limits (RW): {_lim} {_cfg_lim}\n"
info_string += f" dial (RW): {self.dial:.5f}\n"
info_string += f" position (RW): {self.position:.5f}\n"
except:
info_string += "ERROR: unable to get info (communication problem?)\n"
try:
info_string += f" state (R): {self.state}\n"
except:
info_string += f" ERROR: unable to get state (communication problem?)\n"
# ACCELERATION
try:
_acc = self.acceleration
_acc_config = self.config_acceleration
_acc_time = self.acctime
_acc_time_config = self.config_acctime
_info_string += (
info_string += (
f" acceleration (RW): {_acc:10.5f} (config: {_acc_config:10.5f})\n"
)
_info_string += f" acctime (RW): {_acc_time:10.5f} (config: {_acc_time_config:10.5f})\n"
info_string += f" acctime (RW): {_acc_time:10.5f} (config: {_acc_time_config:10.5f})\n"
except Exception as e:
_info_string += f" acceleration: None\n"
info_string += f" acceleration: None\n"
# To avoid error if no velocity.
# VELOCITY
try:
_vel = self.velocity
_vel_config = self.config_velocity
_info_string += (
info_string += (
f" velocity (RW): {_vel:10.5f} (config: {_vel_config:10.5f})\n"
)
except Exception as e:
_info_string += f" velocity: None\n"
info_string += f" velocity: None\n"
# CONTROLLER
try:
info_string += self.__controller.__info__()
except:
info_string += f"ERROR: Unable to get info from controller\n"
# SPECIFIC AXIS INFO
try:
# use of get_info() rather than __info__() to be able to pass axis as param.
_info_string += self.__controller.get_info(self)
# usage of get_axis_info() to pass axis as param.
info_string += self.__controller.get_axis_info(self)
except Exception as e:
_info_string += f"{self.controller}\n"
info_string += f"{self.controller}\n"
# ENCODER
try:
_info_string += self.encoder.__info__()
info_string += self.encoder.__info__()
except Exception as e:
_info_string += f" encoder: None\n"
info_string += f" encoder: None\n"
return _info_string
return info_string
def sync_hard(self):
"""Forces an axis synchronization with the hardware"""
......
......@@ -124,11 +124,13 @@ class Counter:
def __info__(self, counter_type=None):
info_str = f"'{self.name}` counter info:\n"
info_str += f" counter type = {counter_type} \n" if counter_type else ""
if counter_type == "sampling":
info_str += f" sampling mode = {self.mode.name} \n" if self.mode else ""
info_str += f" fullname = {self.fullname} \n"
info_str += f" unit = {self.unit} \n"
info_str += f" shape = {self.shape} \n"
info_str += f" dtype = {self.dtype} \n"
info_str += f" conversion_function = {self.conversion_function} \n"
# info_str += f" shape = {self.shape} \n"
# info_str += f" dtype = {self.dtype} \n"
# info_str += f" conversion_function = {self.conversion_function} \n"
return info_str
......
......@@ -101,10 +101,5 @@ class Encoder:
def __info__(self):
info_str = "ENCODER:\n"
info_str += f" tolerance (to check pos at end of move): {self.tolerance}\n"
info_str += f" encoder value: {self.controller.read_encoder(self)}\n"
# only 1 read to ensure coherency.
_dial_meas_pos = self.read()
# _user_meas_pos = ???axis.dial2user(_dial_meas_pos)
info_str += f" dial_measured_position: {_dial_meas_pos:10.5f}\n"
# info_str += f" user_measured_position: {_user_meas_pos:10.5f} \n"
info_str += f" dial_measured_position: {self.read():10.5f}\n"
return info_str
......@@ -10,6 +10,7 @@ import time
import gevent
import hashlib
import functools
from collections import namedtuple
from bliss.common.greenlet_utils import protect_from_kill
from bliss.config.channels import Cache
from bliss.controllers.motor import Controller
......@@ -298,7 +299,7 @@ class Icepap(Controller):
return state
def get_info(self, axis):
def get_axis_info(self, axis):
pre_cmd = "%s:" % axis.address
# info_str = "MOTOR : %s\n" % axis.name
info_str = "ICEPAP:\n"
......@@ -313,22 +314,21 @@ class Icepap(Controller):
info_str += f" CLOOP: {_command(self._cnx, pre_cmd + '?PCLOOP')}"
info_str += f" WARNING: {_command(self._cnx, pre_cmd + '?WARNING')}"
info_str += f" ALARM: {_command(self._cnx, pre_cmd + '?ALARM')}\n"
info_str += f" {self.read_encoder_all_types(axis)}\n"
if isinstance(axis, LinkedAxis):
info_str += f"LINKED AXIS:\n"
info_str += f" {self.get_linked_axis()}\n"
return info_str
def __info__(self, axis):
"""
__info__ for CLI help
NB: <axis> is passed as argument
=> __info__ not CLI callable for icepap controller.
def __info__(self):
"""For CLI help.
"""
info_str = "ICEPAP AXIS:\n"
info_str += f" address: {axis.address}\n"
info_str = "ICEPAP CONTROLLER:\n"
info_str += f" controller: {self._cnx._host}\n"
info_str += f" version: {_command(self._cnx, '?VER')}\n"
info_str += f" status: {int(_command(self._cnx, '%s:?STATUS' % axis.address), 16)}\n"
if isinstance(axis, LinkedAxis):
info_str += f" {self.get_linked_axis()}\n"
return info_str
......@@ -442,6 +442,25 @@ class Icepap(Controller):
value = _command(self._cnx, "?ENC %s %d" % (encoder.enctype, encoder.address))
return int(value)
def read_encoder_all_types(self, axis):
"""Return a named-tuple of all ENC value
("ENCIN", "ABSENC", "INPOS", "MOTOR", "AXIS", "SYNC")
"""
# Create new "type" named IceEncoders.
IceEncoders = namedtuple(
"IcepapEncoders", "ENCIN, ABSENC, INPOS, MOTOR, AXIS, SYNC"
)
enc_names = ["ENCIN", "ABSENC", "INPOS", "MOTOR", "AXIS", "SYNC"]
addr = axis.config.get("address")
enc_values = [
_command(self._cnx, f"?ENC {enctype} {addr}") for enctype in enc_names
]
return IceEncoders(*enc_values)
def set_encoder(self, encoder, steps):
_ackcommand(
self._cnx, "ENC %s %d %d" % (encoder.enctype, encoder.address, steps)
......
......@@ -351,14 +351,19 @@ class Mockup(Controller):
motion = Motion(pos, target, vel, accel, self.__hw_limit)
self._axis_moves[axis]["motion"] = motion
def __info__(self, axis):
"""Return information about Controller and Axis"""
info_string = f"Axis: {axis.name}\n"
info_string += f"Controller:\n"
info_string += f" class: {self.__class__}\n"
info_string += f" name: {self.name}\n"
return info_string
def __info__(self):
"""Return information about Controller"""
info_str = f"Controller name: {self.name}\n"
return info_str
def get_axis_info(self, axis):
""" Return 'mockup'-specific info about <axis>
"""
info_str = "MOCKUP AXIS:\n"
info_str += f" this axis ({axis.name}) is a simulation axis\n"
return info_str
def get_id(self, axis):
return "MOCKUP AXIS %s" % (axis.name)
......
......@@ -369,13 +369,21 @@ class PI_E753(Controller):
"""
return self.send(axis, "*IDN?")
def __info__(self):
info_str = "PI {self.model}\n"
info_str += " address:{}\n"
info_str += " "
def get_axis_info(self, axis):
"""Return Controller specific info about <axis>
"""
info_str = "PI INFO:\n"
info_str += f" voltage (SVA) = {self.get_voltage(axis)}\n"
info_str += f" output voltage (VOL) = {self.get_output_voltage(axis)}\n"
info_str += f" closed loop = {self.get_closed_loop(axis)}\n"
return info_str
def __info__(self):
info_str = f"PI {self.model}\n"
info_str += f" {self.comm.__info__()}"
return info_str
@object_method(types_info=("None", "string"))
def get_info(self, axis):
return self.get_hw_info()
......
......@@ -208,7 +208,9 @@ Mainly for tests and debugging purpose.
#### Not declared in config
Example to use in BLISS shell.
```yaml
```python
from bliss.comm.util import get_comm, TCP
conf = {"tcp": {"url": "trucmuch.esrf.fr"}}
opt = {"port":5025}
kom = get_comm(conf, ctype=TCP, **opt)
......
......@@ -47,23 +47,27 @@ def test_info(robz, capsys):
assert robz.controller.name == "test"
captured = robz.__info__()
output = "axis name (R): robz\n"
output += " state (R): READY (Axis is READY)\n"
output = "AXIS:\n"
output += " name (R): robz\n"
output += " unit (R): mm\n"
output += " offset (R): 0.0\n"
output += " backlash (R): 0\n"
output += " offset (R): 0.00000\n"
output += " backlash (R): 0.00000\n"
output += " sign (R): 1\n"
output += " steps_per_unit (R): 10000.0\n"
output += " steps_per_unit (R): 10000.00\n"
output += " tolerance (R) (to check pos. before a move): 0.0001\n"
output += " motion_hooks (R): []\n"
# output += " motion_hooks (R): []\n"
output += " limits (RW): Low: -1000.00000 High: 1000000000.00000 (config Low: -1000.00000 High: 1000000000.00000)\n"
output += " dial (RW): 0.00000\n"
output += " position (RW): 0.00000\n"
output += " _hw_position (R): 0.00000\n"
output += " hw_state (R): READY (Axis is READY)\n"
output += " limits (RW): (-1000.0, 1000000000.0) (config: (-1000.0, 1000000000.0))\n"
output += " state (R): READY (Axis is READY)\n"
# output += " _hw_position (R): 0.00000\n"
# output += " hw_state (R): READY (Axis is READY)\n"
output += " acceleration (RW): 300.00000 (config: 300.00000)\n"
output += " acctime (RW): 0.33333 (config: 0.33333)\n"
output += " velocity (RW): 100.00000 (config: 100.00000)\n"
output += "Controller name: test\n"
output += "MOCKUP AXIS:\n"
output += " this axis (robz) is a simulation axis\n"
output += " encoder: None\n"
# # output += "controller: <bliss.controllers.motors.mockup.Mockup object at 0x7f78ac843d30>\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment