-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathchange_pid.py
98 lines (83 loc) · 2.67 KB
/
change_pid.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# coding: utf-8
import time
from turtle import goto
from pymycobot.mycobot import MyCobot
import serial.tools.list_ports
data_id = [21, 22, 23, 24, 26, 27]
mc = []
ports = []
def setup(): #机械臂检测函数,选择正确的串口
global mc
print("")
plist = list(serial.tools.list_ports.comports())
idx = 0
for port in plist:
print("{} : {}".format(idx, port))
idx += 1
if idx == 0:
print("The connected device was not detected. Please try reconnecting.")
exit(1)
_in = input("\nPlease input 0 - {} to choice, you can choice many like: '2,1,3':".format(idx))
idxes = _in.split(',')
try:
idxes = [int(i) for i in idxes]
except Exception:
print('Error: Input format error.')
exit(1)
ports = [str(plist[i]).split(' - ')[0].strip() for i in idxes]
print(ports)
print("")
baud = 115200
_baud = input("Please input baud(default:115200):")
try:
baud = int(_baud)
except Exception:
pass
print(baud)
print("")
for port in ports:
try:
mycobot = MyCobot(port, baud)
except Exception as e:
print(e)
exit(1)
mc.append(mycobot)
def change():
global mc
mode = 1
_mode = input("Please input mode, 1 = high precision, 2 = stabilize (default: 1 ):")
try:
mode = int(_mode)
except Exception:
pass
print(mode)
print("")
for _mycbot in mc:
print(_mycbot)
for i in range(1,7):
if mode == 1:
data = [10, 0, 1, 0, 3, 3]
elif mode == 2:
if i < 4 :
data = [5, 15, 0, 0, 3, 3]
else:
data = [8, 24, 0, 0, 3, 3]
else:
print("Please set the parameter mode !!!")
goto(change())
for j in range(len(data_id)):
_mycbot.set_servo_data(i, data_id[j], data[j])
time.sleep(0.2)
_data = _mycbot.get_servo_data(i, data_id[j])
time.sleep(0.2)
if _data == data[j]:
print("Servo motor :" + str(i) + " data_id : " + str(data_id[j]) + " data: " + str(_data) + " modify successfully ")
else:
print("Servo motor :" + str(i) + " data_id : " + str(data_id[j]) + " data: " + str(_data) + " modify error ")
if __name__ == "__main__": #主函数
setup()
print(mc)
try:
change()
except Exception as e:
print(e)