-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemuBot.py
55 lines (42 loc) · 1.49 KB
/
emuBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from pyax12.connection import Connection
import time
import threading
sc = Connection(port="/dev/ttyACM0", baudrate=1000000)
# Set up a dynamixel so that it behaves like joint
def jointMode(ID):
sc.set_ccw_angle_limit(ID,0,False)
sc.set_cw_angle_limit(ID,0,False)
# Set up a dynamixel so that it behaves like wheel
def wheelMode(ID):
sc.set_ccw_angle_limit(ID,0,False)
sc.set_cw_angle_limit(ID,0,False)
# Print useful information about an individual dynamixel servo
def readDxl(ID):
sc.flush()
sc.pretty_print_control_table(ID)
# Move a dynamixel that has been set up as a joint
def moveJoint(ID, position, speed):
sc.goto(ID, int(position), int(speed), False)
# Move a dynamixel that has been set up as a wheel
# Negative speed moves CW, positive speed moves CCW
def moveWheel(ID, speed):
# Convert negative values of speed to between 1024 and 2047
if speed < 0:
# Limit allowed reverse speed to prevent errors
if speed < -1024:
speed = 2047
else:
speed = 1023 + -speed
else:
if speed > 1023:
# Limit allowed forward speed to prevent errors
speed = 1023
sc.flush()
sc.goto(ID, 0, speed, degrees=False)
'''moveWheel(1,100)
moveWheel(2,100)
moveWheel(3,100)
moveWheel(4,100)
moveWheel(5,100)
moveWheel(6,100)
moveWheel(7,100)'''