Skip to content

Commit dbc61f0

Browse files
committed
update demo.
1 parent e184017 commit dbc61f0

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ test_test.py
1414

1515
.vscode/.ropeproject/config.py
1616
.vscode/.ropeproject/objectdb
17+
18+
__pycache__/port.cpython-39.pyc
19+
demo/__pycache__/port.cpython-39.pyc

demo/port.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import serial
2+
import serial.tools.list_ports
3+
4+
from pymycobot.mycobot import MyCobot
5+
6+
7+
8+
def setup():
9+
print("")
10+
11+
plist = list(serial.tools.list_ports.comports())
12+
idx = 1
13+
for port in plist:
14+
print("{} : {}".format(idx, port))
15+
idx += 1
16+
17+
_in = input("\nPlease input 1 - {} to choice:".format(idx - 1))
18+
port = str(plist[int(_in) - 1]).split(" - ")[0].strip()
19+
print(port)
20+
print("")
21+
22+
baud = 115200
23+
_baud = input("Please input baud(default:115200):")
24+
try:
25+
baud = int(_baud)
26+
except Exception:
27+
pass
28+
print(baud)
29+
print("")
30+
31+
DEBUG = False
32+
f = input("Wether DEBUG mode[Y/n]:")
33+
if f in ["y", "Y", "yes", "Yes"]:
34+
DEBUG = True
35+
# mc = MyCobot(port, debug=True)
36+
mc = MyCobot(port, baud, debug=DEBUG)
37+
return mc
38+

demo/port.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

demo/send_angle.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
import os
3+
sys.path.append(os.path.dirname(__file__))
4+
from port import setup
5+
6+
if __name__ == "__main__":
7+
mc = setup()
8+
_sp = input('Please input speed(0-100):')
9+
try:
10+
sp = int(_sp)
11+
except Exception:
12+
print('Error: invalid speed, speed is default: 80')
13+
sp = 80
14+
15+
while not False:
16+
angles_str = input('Please input angles, like ("0,0,0,0,0,0"):')
17+
try:
18+
angles_str_l = angles_str.split(',')
19+
if len(angles_str_l) != 6:
20+
raise Exception('')
21+
angles = [float(i) for i in angles_str_l]
22+
except Exception:
23+
print('Error: invalid angles string.')
24+
continue
25+
26+
mc.send_angles(angles, sp)
27+

0 commit comments

Comments
 (0)