Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if s_items == physical_elements:
if calculated is not None and self in calculated:
return
user_elements = self.get_user_elements()
positions = self.get_siblings_positions(use=calculated,
write_pos=self.drift_correction)
positions[self] = new_position
pseudo_positions = len(positions) * [None]
for pseudo, position in positions.items():
pseudo_positions[pseudo.axis - 1] = position
curr_physical_positions = self._position.get_physical_positions()
physical_positions = self.controller.calc_all_physical(pseudo_positions,
curr_physical_positions)
if physical_positions.error:
raise PoolException("Cannot calculate motion: "
"calc_all_physical raises exception",
exc_info=physical_positions.exc_info)
else:
if physical_positions.value is None:
raise PoolException("Cannot calculate motion: "
"calc_all_physical returns None")
if items is None:
items = {}
for new_position, element in zip(physical_positions.value, user_elements):
if new_position is None:
raise PoolException("Cannot calculate motion: %s reports "
"position to be None" % element.name)
# TODO: get the configuration for an specific sardana class and
# get rid of AttributeProxy - see sardana-org/sardana#663
config = AttributeProxy(element.name + '/position').get_config()
def get_physical_write_values(self):
ret = []
for value_attr in self.obj.get_physical_value_attribute_iterator():
if value_attr.has_write_value():
value = value_attr.w_value
else:
if not value_attr.has_value():
# if underlying counter doesn't have value yet, it is
# because of a cold start
value_attr.update(propagate=0)
if value_attr.in_error():
raise PoolException("Cannot get '%s' value" % value_attr.obj.name,
exc_info=value_attr.exc_info)
value = value_attr.value
ret.append(value)
return ret
:param write_pos: determines if should try to use the last set point
[default: True]
:type write_pos: bool
:return: a dictionary with siblings write positions
:rtype:
dict """
positions = {}
for sibling in self.siblings:
pos_attr = sibling.get_position(propagate=0)
if use and sibling in use:
pos = use[sibling]
elif pos_attr.has_write_value() and write_pos:
pos = pos_attr.w_value
else:
if pos_attr.in_error():
raise PoolException("Cannot get '%s' position" % sibling.name,
exc_info=pos_attr.exc_info)
pos_value = pos_attr.calc_pseudo()
if pos_value.error:
raise PoolException("Cannot get '%s' position" % sibling.name,
exc_info=pos_value.exc_info)
pos = pos_value.value
positions[sibling] = pos
return positions
physical_positions = self.controller.calc_all_physical(pseudo_positions,
curr_physical_positions)
if physical_positions.error:
raise PoolException("Cannot calculate motion: "
"calc_all_physical raises exception",
exc_info=physical_positions.exc_info)
else:
if physical_positions.value is None:
raise PoolException("Cannot calculate motion: "
"calc_all_physical returns None")
if items is None:
items = {}
for new_position, element in zip(physical_positions.value, user_elements):
if new_position is None:
raise PoolException("Cannot calculate motion: %s reports "
"position to be None" % element.name)
# TODO: get the configuration for an specific sardana class and
# get rid of AttributeProxy - see sardana-org/sardana#663
config = AttributeProxy(element.name + '/position').get_config()
try:
high = float(config.max_value)
except ValueError:
high = None
try:
low = float(config.min_value)
except ValueError:
low = None
if high is not None:
if float(new_position) > high:
msg = "requested movement of %s is above its upper limit"\
% element.name
def get_physical_write_positions(self):
ret = []
for pos_attr in self.obj.get_physical_position_attribute_iterator():
if pos_attr.has_write_value():
value = pos_attr.w_value
else:
if not pos_attr.has_value():
# if underlying moveable doesn't have position yet, it is
# because of a cold start
pos_attr.update(propagate=0)
if pos_attr.in_error():
raise PoolException("Cannot get '%' position" % pos_attr.obj.name,
exc_info=pos_attr.exc_info)
value = pos_attr.value
ret.append(value)
return ret
def get_physical_positions(self):
ret = []
for pos_attr in self.obj.get_physical_position_attribute_iterator():
# if underlying moveable doesn't have position yet, it is because
# of a cold start
if not pos_attr.has_value():
pos_attr.update(propagate=0)
if pos_attr.in_error():
raise PoolException("Cannot get '%' position" % pos_attr.obj.name,
exc_info=pos_attr.exc_info)
ret.append(pos_attr.value)
return ret
def write_Position(self, attr):
self.in_write_position = True
try:
position = attr.get_write_value()
self.debug("write_Position(%s)", position)
try:
self.wait_for_operation()
except:
raise Exception("Cannot move: already in motion")
try:
self.motor_group.position = position
except PoolException, pe:
throw_sardana_exception(pe)
finally:
self.in_write_position = False