OLD | NEW |
(Empty) | |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import serial |
| 6 |
| 7 class RobotArm(): |
| 8 """Handles the serial communication with the servos/arm used for movement.""" |
| 9 def __init__(self, device_name, num_tries=5, baud=115200, timeout=3.0): |
| 10 self._connection = None |
| 11 connected = False |
| 12 for _ in xrange(num_tries): |
| 13 try: |
| 14 self._connection = serial.Serial('/dev/' + device_name, |
| 15 baud, |
| 16 timeout=timeout) |
| 17 except serial.SerialException as e: |
| 18 pass |
| 19 if self._connection and 'Enter parameters' in self._connection.read(1024): |
| 20 connected = True |
| 21 break |
| 22 if not connected: |
| 23 raise serial.SerialException('Failed to connect to the robot arm.') |
| 24 |
| 25 def StartMotophoMovement(self): |
| 26 if not self._connection: |
| 27 return |
| 28 self._connection.write('9\n') |
| 29 |
| 30 def StopAllMovement(self): |
| 31 if not self._connection: |
| 32 return |
| 33 self._connection.write('0\n') |
OLD | NEW |