SHARE
TWEET

Untitled

a guest Oct 30th, 2013 5 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ServoController():
  2.     """ Object that chats with controller over serial and sends him values
  3.        with syntax: <value><servo_letter>"""
  4.  
  5.     def __init__(self, loop, tty):
  6.         """ we need functional loop and tty we should connec to """
  7.         self._s = serial.Serial(tty, 57600)
  8.         self._tty_handle = pyuv.TTY(loop, self._s.fileno(), True)
  9.         self._tty_handle.start_read(self._on_read)
  10.  
  11.     def _on_read(self, status_handle, data, error):
  12.         """ callback called everytime that our pyuv.TTY receives something, in
  13.            this case we didn't defined any response from controller!'"""
  14.         pass
  15.  
  16.     def setPosition(self, position, letter):
  17.         """sets servo to position based on it's letter'"""
  18.         assert 500 <= position <= 2500
  19.  
  20.         position = str(position)
  21.         string = position + letter
  22.  
  23.         self._tty_handle.write(string.encode('UTF-8'))
  24.         print(("ServoController output: ", string))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top