To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit b16daa8d authored by mikolajr's avatar mikolajr
Browse files

In ILS2T device: use f-strings

parent 11147ec0
......@@ -314,8 +314,8 @@ class ILS2T(SingleCommDevice):
cleaned_io_scanning_mode = self._clean_ioscanning_mode_values(kwargs)
action_bits = "{0:03b}".format(cleaned_io_scanning_mode["action"])
mode_bits = "{0:04b}".format(cleaned_io_scanning_mode["mode"])
action_bits = f"{cleaned_io_scanning_mode['action']:03b}"
mode_bits = f"{cleaned_io_scanning_mode['mode']:04b}"
builder = BinaryPayloadBuilder(byteorder=Endian.Big, wordorder=Endian.Big)
# add the first byte: Drive control
......@@ -374,9 +374,7 @@ class ILS2T(SingleCommDevice):
all_keys = set(self.DEFAULT_IO_SCANNING_CONTROL_VALUES.keys())
superfluous_keys = io_scanning_keys.difference(all_keys)
if superfluous_keys:
raise ValueError(
"Unrecognized mode keys: {}".format(list(superfluous_keys))
)
raise ValueError(f"Unrecognized mode keys: {list(superfluous_keys)}")
# fill up io_scanning_values with defaults, if they are not set
for mode_key, default_value in self.DEFAULT_IO_SCANNING_CONTROL_VALUES.items():
......@@ -387,21 +385,22 @@ class ILS2T(SingleCommDevice):
# JOG mode
if io_scanning_values["mode"] == self.Mode.JOG:
if not io_scanning_values["action"] == self.ACTION_JOG_VALUE:
raise IoScanningModeValueError(
"Wrong action: {}".format(io_scanning_values["action"])
)
io_scanning_value = io_scanning_values["action"]
if not io_scanning_value == self.ACTION_JOG_VALUE:
raise IoScanningModeValueError(f"Wrong action: {io_scanning_value}")
io_scanning_value = io_scanning_values["ref_16"]
try:
self.Ref16Jog(io_scanning_values["ref_16"])
self.Ref16Jog(io_scanning_value)
except ValueError:
raise IoScanningModeValueError(
"Wrong value in ref_16 ({})".format(io_scanning_values["ref_16"])
f"Wrong value in ref_16 ({io_scanning_value})"
)
if not io_scanning_values["ref_32"] == 0:
io_scanning_value = io_scanning_values["ref_32"]
if not io_scanning_value == 0:
raise IoScanningModeValueError(
"Wrong value in ref_32 ({})".format(io_scanning_values["ref_32"])
f"Wrong value in ref_32 ({io_scanning_value})"
)
return io_scanning_values
......@@ -409,29 +408,28 @@ class ILS2T(SingleCommDevice):
# PTP mode
if io_scanning_values["mode"] == self.Mode.PTP:
io_scanning_value = io_scanning_values["action"]
try:
self.ActionsPtp(io_scanning_values["action"])
self.ActionsPtp(io_scanning_value)
except ValueError:
raise IoScanningModeValueError(
"Wrong action: {}".format(io_scanning_values["action"])
)
raise IoScanningModeValueError(f"Wrong action: {io_scanning_value}")
if not self._is_valid_rpm(io_scanning_values["ref_16"]):
io_scanning_value = io_scanning_values["ref_16"]
if not self._is_valid_rpm(io_scanning_value):
raise IoScanningModeValueError(
"Wrong value in ref_16 ({})".format(io_scanning_values["ref_16"])
f"Wrong value in ref_16 ({io_scanning_value})"
)
if not self._is_int32(io_scanning_values["ref_32"]):
io_scanning_value = io_scanning_values["ref_32"]
if not self._is_int32(io_scanning_value):
raise IoScanningModeValueError(
"Wrong value in ref_32 ({})".format(io_scanning_values["ref_32"])
f"Wrong value in ref_32 ({io_scanning_value})"
)
return io_scanning_values
# default
raise IoScanningModeValueError(
"Wrong mode: {}".format(io_scanning_values["mode"])
)
raise IoScanningModeValueError(f"Wrong mode: {io_scanning_values['mode']}")
def _is_valid_rpm(self, num: int) -> bool:
"""
......@@ -513,9 +511,9 @@ class ILS2T(SingleCommDevice):
max_step = self.RegDatatype.INT32.max # type: ignore
# use _is_int32 instead?
if not abs(steps) < max_step:
logging.warning("number of steps is too big: {}".format(steps))
logging.warning(f"number of steps is too big: {steps}")
logging.info("Perform number of steps: {}".format(steps))
logging.info(f"Perform number of steps: {steps}")
self.do_ioscanning_write(
enable_driver_en=1,
......@@ -535,9 +533,9 @@ class ILS2T(SingleCommDevice):
max_position = self.RegDatatype.INT32.max # type: ignore
# use _is_int32 instead?
if not abs(position) < max_position:
logging.warning("position is out of range: {}".format(position))
logging.warning(f"position is out of range: {position}")
logging.info("Absolute position: {}".format(position))
logging.info(f"Absolute position: {position}")
self.do_ioscanning_write(
enable_driver_en=1,
......@@ -553,7 +551,7 @@ class ILS2T(SingleCommDevice):
:param steps: Number of steps.
"""
logging.info("Motor steps requested: {}".format(steps))
logging.info(f"Motor steps requested: {steps}")
position_before = self.get_position()
......@@ -572,34 +570,22 @@ class ILS2T(SingleCommDevice):
if position_before + steps != position_after:
flt_dict = self.get_error_code()
self.flt_list.append(flt_dict)
log_msg = (
f"The position does not align with the requested step number. "
f"Before: {position_before}, after: {position_after}, "
f"requested: {steps}, "
f"real difference: {position_after - position_before,}"
)
if "empty" in flt_dict[0].keys():
logging.warning(
"no error in drive, " "something different must have gone wrong"
)
logging.warning(
"The position does not align with the requested step "
"number. Before: {0}, after: {1}, requested: {2}, "
"real difference: {3}".format(
position_before,
position_after,
steps,
position_after - position_before,
)
)
logging.warning(log_msg)
else:
# Despite drive error/malfunction don't break the code/experiment
# execution by raising an error; continuing as nothing happened.
logging.critical("error in drive, drive is know maybe locked")
logging.critical(
"The position does not align with the requested step "
"number. Before: {0}, after: {1}, requested: {2}, "
"real difference: {3}".format(
position_before,
position_after,
steps,
position_after - position_before,
)
)
logging.critical(log_msg)
def absolute_position_and_wait(self, position: int) -> None:
"""
......@@ -608,7 +594,7 @@ class ILS2T(SingleCommDevice):
:param position: absolute position of motor in user defined steps.
"""
logging.info("absolute position requested: {}".format(position))
logging.info(f"absolute position requested: {position}")
position_before = self.get_position()
......@@ -627,24 +613,19 @@ class ILS2T(SingleCommDevice):
if position != position_after:
flt_dict = self.get_error_code()
self.flt_list.append(flt_dict)
log_msg = (
f"The position does not align with the requested absolute position. "
f"Before: {position_before}, after: {position_after}, "
f"requested: {position}."
)
if "empty" in flt_dict[0].keys():
logging.warning(
"no error in drive, " "something different must have gone wrong"
)
logging.warning(
"The position does not align with the requested absolute position. "
"Before: {0}, after: {1}, requested: {2}".format(
position_before, position_after, position,
)
)
logging.warning(log_msg)
else:
logging.critical("error in drive, drive is know maybe locked")
logging.critical(
"The position does not align with the requested absolute position. "
"Before: {0}, after: {1}, requested: {2}".format(
position_before, position_after, position,
)
)
logging.critical(log_msg)
def disable(self) -> None:
"""
......@@ -722,12 +703,12 @@ class ILS2T(SingleCommDevice):
"""
if not self._is_int32(revolutions):
err_msg = "Wrong scaling factor: revolutions = {}".format(revolutions)
err_msg = f"Wrong scaling factor: revolutions = {revolutions}"
logging.error(err_msg)
raise ScalingFactorValueError(err_msg)
if not self._is_int32(steps):
err_msg = "Wrong scaling factor: steps = {}".format(steps)
err_msg = f"Wrong scaling factor: steps = {steps}"
logging.error(err_msg)
raise ScalingFactorValueError(err_msg)
......@@ -812,9 +793,7 @@ class ILS2T(SingleCommDevice):
:param fast: RPM for fast jog mode.
"""
logging.info(
"Setting Jog RPM. Slow = {0} RPM, Fast = {1} RPM.".format(slow, fast)
)
logging.info(f"Setting Jog RPM. Slow = {slow} RPM, Fast = {fast} RPM.")
self.com.write_registers(self.RegAddr.JOGN_SLOW.value, [0, slow])
self.com.write_registers(self.RegAddr.JOGN_FAST.value, [0, fast])
......@@ -893,9 +872,7 @@ class ILS2T(SingleCommDevice):
self.com.write_registers(self.RegAddr.RAMP_N_MAX.value, [0, rpm])
else:
raise ILS2TException(
"RPM out of range: {rpm} not in (0, {rpm_max}".format(
rpm=rpm, rpm_max=self.config.rpm_max_init,
)
f"RPM out of range: {rpm} not in (0, {self.config.rpm_max_init}]"
)
def set_ramp_type(self, ramp_type: int = -1) -> None:
......
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