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 import time | |
7 | |
Nico
2017/04/20 17:51:21
likewise
bsheedy
2017/04/20 20:05:00
Done.
| |
8 class RobotArm(): | |
9 """Handles the serial communication with the servos/arm used for movement.""" | |
10 def __init__(self, device_name, num_tries=5, baud=115200, timeout=3.0): | |
11 self._connection = None | |
12 connected = False | |
13 for _ in xrange(num_tries): | |
14 try: | |
15 self._connection = serial.Serial('/dev/' + device_name, | |
16 baud, | |
17 timeout=timeout) | |
18 except serial.SerialException as e: | |
19 pass | |
20 if self._connection and 'Enter parameters' in self._connection.read(1024): | |
21 connected = True | |
22 break | |
23 if not connected: | |
24 raise serial.SerialException('Failed to connect to the robot arm.') | |
25 | |
26 def ResetPosition(self): | |
27 if not self._connection: | |
28 return | |
29 # If the servo stopped very close to the desired position, it can just | |
30 # vibrate instead of moving, so move away before going to the reset | |
31 # position | |
32 self._connection.write('5 300 0 5\n') | |
33 time.sleep(0.5) | |
34 self._connection.write('5 250 0 5\n') | |
35 time.sleep(0.5) | |
36 | |
37 def StartMotophoMovement(self): | |
38 if not self._connection: | |
39 return | |
40 self._connection.write('9\n') | |
41 | |
42 def StopAllMovement(self): | |
43 if not self._connection: | |
44 return | |
45 self._connection.write('0\n') | |
OLD | NEW |