Advertisement
Guest User

snipet kuim

a guest
Dec 9th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.69 KB | None | 0 0
  1. class Axis(object):
  2.     """IcePAP emulated axis"""
  3.  
  4.     def __init__(self, icepap, address=None, **opts):
  5.         """ COSICAS DE LA CLASSE """
  6.  
  7.     # --- Axis level commands
  8.      def move(self, args=(), cmd_result=None, **kwargs):
  9.         self._destination = float(args)
  10.         velocity = float(getattr(self, "velocity", None)())
  11.         acctime = float(getattr(self, "acctime", None)())
  12.         position = float(getattr(self, "posaxis", None)())
  13.  
  14.         acceleration = velocity / acctime
  15.         self._sign = 1
  16.         if position > self._destination:
  17.             self._sign = -1
  18.  
  19.         self._t1 = velocity / acceleration
  20.  
  21.         self._x0 = position
  22.         self._x1 = self._x0 + self._sign * acceleration * (self._t1 ** 2) / 2
  23.         if self._t1 == self._t2:
  24.             self._x2 = self._x1
  25.         else:
  26.             self._x2 = self._x1 + self._sign * (abs(self._x0 - self._destination) - 2 *
  27.                                                 abs(self._x0 - self._x1))
  28.  
  29.         self._t2 = self._t1 + abs(self._x2 - self._x1) / velocity
  30.         self._t3 = self._t1 + self._t2
  31.         if 2 * self._t1 > self._t3:
  32.             raise RuntimeError("Acceleration time too slow")
  33.        
  34.         """ NECESITO QUE TODOS LOS MOTORES HAGAN ESTA LINEA CASI AL MISMO TIEMPO """
  35.         self._start_time = time.time()
  36.  
  37.         self._log.debug("move %r to %r", self.address, self._destination)
  38.         # setattr(self, "_posaxis", destination)
  39.         return " OK"
  40.  
  41.     posaxis = fpos = axis_command(position)
  42.     pos = axis_command("pos", default=0)
  43.     velocity = axis_command("velocity", default=1000)
  44.     acctime = axis_command("acctime", default=0.25)
  45.  
  46.     move = axis_command(move)
  47.  
  48.     """ ... MUCHO CODIGO ... """
  49.  
  50. def command(f_or_name=None, mode="rw", axes_arg_parser=None, default=None):
  51.    
  52.     """ ... MUCHO CODIGO ... """
  53.  
  54.     @functools.wraps(f)
  55.     def wraps(self, **kwargs):
  56.        
  57.     """ ... MUCHO CODIGO ... """
  58.  
  59.             else:
  60.                 for axis, arg in zip(axes, args):
  61.                     axis = self._get_axis(axis, system=True)
  62.  
  63.  
  64.                     """ MI INTENTO DE THREAD """
  65.                     thread = lambda a, n, ar: result.append(str(getattr(a, n)(ar)))
  66.                     x = threading.Thread(target=thread, args=(axis, name, arg))
  67.                     x.start()
  68.  
  69.                     """ EL VERDADERO CODIGO A THREDEAR QUE LLAMA EL WRAPPER EN LA CLASSE ANTERIOR CON LA FUNCION """
  70.                     # result.append(str(getattr(axis, name)(arg)))
  71.  
  72. """ ... MUCHO CODIGO ... """
  73.  
  74.     return wraps
  75.  
  76.  
  77. read_command = functools.partial(command, mode="r")
  78.  
  79. axes_command = functools.partial(command, axes_arg_parser=axis_value_parse_args)
  80. axes_read_command = functools.partial(axes_command, mode="r")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement