Skip to content

Commit 414f248

Browse files
author
yuxuan
committed
add muBuddy_Action
1 parent 9abaa83 commit 414f248

26 files changed

+2108
-0
lines changed

demo/myBuddy_Action/ChewingGum.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# coding=utf8
2+
import os
3+
import time
4+
from pymycobot.mybuddy import MyBuddy
5+
import threading
6+
from threading import Lock, Thread
7+
import cv2 as cv
8+
# Establish serial connection
9+
mc = MyBuddy('/dev/ttyACM0', 115200)
10+
11+
12+
13+
# Release the arms and record the points passed
14+
def read():
15+
time.sleep(10)
16+
t = time.time()
17+
record_list = []
18+
print(1)
19+
while time.time() - t < 5:
20+
angles_1 = mc.get_encoders(1)
21+
angles_2 = mc.get_encoders(2)
22+
if angles_1 and angles_2:
23+
record_list.append([angles_1, angles_2])
24+
time.sleep(0.1)
25+
# Print the read location information, copy and save it as a txt file
26+
for i in record_list:
27+
print(i)
28+
29+
30+
# Take out and use the saved location
31+
def write():
32+
time.sleep(1.5)
33+
# The file here uses the saved txt file
34+
data = list(filter(None, open(os.path.join(os.getcwd(), 'ChewingGum.txt')).read().splitlines()))
35+
for angles in data:
36+
data = eval(angles)[0]
37+
data[4] -= 280
38+
mc.set_encoders(1, data, 100)
39+
time.sleep(0.03)
40+
mc.set_encoders(2, eval(angles)[1], 100)
41+
time.sleep(0.2)
42+
time.sleep(1.5)
43+
mc.set_gripper_state(2, 1)
44+
time.sleep(1.5)
45+
# The file here uses the saved txt file
46+
data = list(filter(None, open(os.path.join(os.getcwd(), 'ChewingGum_2.txt')).read().splitlines()))
47+
for angles in data:
48+
data = eval(angles)[0]
49+
data[4] -= 280
50+
mc.set_encoders(1, data, 100)
51+
time.sleep(0.03)
52+
mc.set_encoders(2, eval(angles)[1], 100)
53+
time.sleep(0.2)
54+
time.sleep(1.5)
55+
mc.set_gripper_state(2, 0)
56+
time.sleep(1.5)
57+
# The file here uses the saved txt file
58+
data = list(filter(None, open(os.path.join(os.getcwd(), 'ChewingGum_3.txt')).read().splitlines()))
59+
for angles in data:
60+
data = eval(angles)[0]
61+
data[4] -= 280
62+
mc.set_encoders(1, data, 100)
63+
time.sleep(0.03)
64+
mc.set_encoders(2, eval(angles)[1], 100)
65+
time.sleep(0.2)
66+
67+
68+
# show emoji
69+
def smile():
70+
# The location where the emoji file is stored
71+
cap = cv.VideoCapture("/home/ubuntu/emo/face_video_3_2.mp4")
72+
out_win = "l"
73+
cv.namedWindow(out_win, cv.WINDOW_NORMAL)
74+
cv.setWindowProperty(out_win, cv.WND_PROP_FULLSCREEN, cv.WINDOW_FULLSCREEN)
75+
# infinite loop
76+
while True:
77+
ret, frame = cap.read()
78+
if frame is not None:
79+
print(1)
80+
cv.imshow(out_win, frame)
81+
if cv.waitKey(1) & 0xFF == ord('q') or ret == False:
82+
cap = cv.VideoCapture("/home/ubuntu/emo/look_happy.mp4")
83+
84+
85+
if __name__ == '__main__':
86+
# run with multithreading
87+
t1 = threading.Thread(target=write)
88+
t2 = threading.Thread(target=smile)
89+
t1.start()
90+
t2.start()

demo/myBuddy_Action/ChewingGum.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[[2221, 1326, 2898, 3454, 3191, 1891], [1910, 2804, 1191, 605, 1108, 2685]]
2+
[[2221, 1326, 2898, 3454, 3191, 1891], [1910, 2804, 1191, 605, 1108, 2685]]
3+
[[2221, 1326, 2898, 3452, 3191, 1891], [1910, 2804, 1191, 605, 1108, 2685]]
4+
[[2221, 1326, 2898, 3451, 3191, 1891], [1910, 2803, 1191, 613, 1110, 2685]]
5+
[[2226, 1326, 2898, 3441, 3179, 1891], [1901, 2775, 1191, 647, 1127, 2685]]
6+
[[2232, 1326, 2896, 3433, 3169, 1890], [1885, 2665, 1191, 773, 1158, 2685]]
7+
[[2248, 1326, 2896, 3424, 3152, 1888], [1833, 2544, 1190, 928, 1219, 2685]]
8+
[[2266, 1326, 2895, 3423, 3128, 1888], [1755, 2431, 1190, 1091, 1309, 2685]]
9+
[[2288, 1326, 2895, 3415, 3101, 1888], [1635, 2318, 1190, 1284, 1465, 2685]]
10+
[[2291, 1326, 2895, 3406, 3093, 1886], [1449, 2238, 1190, 1459, 1687, 2685]]
11+
[[2291, 1326, 2895, 3400, 3090, 1885], [1319, 2227, 1190, 1598, 1901, 2685]]
12+
[[2291, 1326, 2895, 3400, 3090, 1885], [1249, 2230, 1190, 1714, 2072, 2685]]
13+
[[2291, 1326, 2895, 3396, 3089, 1885], [1242, 2241, 1190, 1787, 2171, 2685]]
14+
[[2291, 1326, 2895, 3393, 3091, 1885], [1259, 2334, 1190, 1730, 2199, 2685]]
15+
[[2297, 1328, 2895, 3393, 3093, 1885], [1273, 2388, 1190, 1740, 2231, 2684]]
16+
[[2301, 1327, 2895, 3389, 3092, 1885], [1274, 2435, 1190, 1719, 2228, 2678]]
17+
[[2301, 1327, 2895, 3384, 3091, 1885], [1283, 2474, 1190, 1688, 2204, 2670]]
18+
[[2301, 1327, 2895, 3378, 3091, 1885], [1288, 2487, 1190, 1680, 2202, 2666]]
19+
[[2301, 1327, 2895, 3377, 3092, 1885], [1293, 2487, 1190, 1680, 2200, 2666]]
20+
[[2301, 1327, 2895, 3375, 3091, 1885], [1293, 2487, 1190, 1679, 2194, 2666]]
21+
[[2301, 1327, 2895, 3376, 3091, 1885], [1293, 2487, 1190, 1681, 2194, 2666]]
22+
[[2301, 1327, 2895, 3377, 3093, 1885], [1293, 2487, 1190, 1681, 2193, 2666]]
23+
[[2301, 1327, 2895, 3378, 3093, 1885], [1293, 2487, 1190, 1685, 2195, 2666]]
24+
[[2301, 1327, 2895, 3378, 3094, 1885], [1293, 2487, 1190, 1687, 2195, 2666]]
25+
[[2301, 1327, 2894, 3378, 3094, 1885], [1293, 2487, 1190, 1689, 2196, 2666]]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[[2337, 1328, 2855, 3471, 3052, 1907], [1396, 2366, 856, 1347, 2122, 2827]]
2+
[[2337, 1328, 2855, 3471, 3056, 1907], [1396, 2366, 856, 1344, 2125, 2826]]
3+
[[2337, 1328, 2855, 3471, 3058, 1907], [1395, 2366, 856, 1328, 2137, 2825]]
4+
[[2337, 1328, 2855, 3473, 3062, 1907], [1392, 2366, 856, 1338, 2131, 2823]]
5+
[[2336, 1328, 2855, 3475, 3067, 1907], [1396, 2366, 856, 1365, 2136, 2858]]
6+
[[2336, 1328, 2855, 3478, 3069, 1907], [1396, 2366, 856, 1368, 2135, 2847]]
7+
[[2336, 1328, 2855, 3477, 3065, 1907], [1393, 2366, 856, 1374, 2106, 2826]]
8+
[[2356, 1331, 2855, 3468, 3036, 1905], [1386, 2366, 855, 1399, 2106, 2821]]
9+
[[2433, 1331, 2854, 3439, 2954, 1904], [1386, 2366, 845, 1428, 2108, 2807]]
10+
[[2532, 1331, 2854, 3378, 2849, 1892], [1373, 2366, 797, 1416, 2137, 2777]]
11+
[[2627, 1331, 2854, 3299, 2740, 1876], [1362, 2366, 732, 1372, 2154, 2750]]
12+
[[2700, 1331, 2854, 3206, 2650, 1858], [1357, 2366, 649, 1292, 2170, 2738]]
13+
[[2739, 1331, 2854, 3094, 2558, 1835], [1339, 2366, 595, 1242, 2168, 2699]]
14+
[[2760, 1329, 2854, 2943, 2471, 1793], [1335, 2365, 582, 1242, 2167, 2694]]
15+
[[2761, 1329, 2854, 2806, 2385, 1746], [1333, 2364, 524, 1203, 2165, 2676]]
16+
[[2751, 1328, 2854, 2724, 2328, 1740], [1333, 2364, 496, 1175, 2165, 2641]]
17+
[[2711, 1328, 2854, 2657, 2261, 1691], [1333, 2364, 454, 1158, 2164, 2612]]
18+
[[2701, 1312, 2854, 2636, 2259, 1679], [1333, 2364, 446, 1152, 2168, 2534]]
19+
[[2703, 1284, 2854, 2650, 2270, 1679], [1333, 2364, 446, 1150, 2168, 2516]]
20+
[[2701, 1284, 2854, 2656, 2272, 1679], [1332, 2364, 446, 1149, 2164, 2466]]
21+
[[2701, 1284, 2854, 2656, 2273, 1679], [1322, 2364, 446, 1149, 2154, 2392]]
22+
[[2701, 1284, 2854, 2654, 2274, 1678], [1317, 2364, 446, 1140, 2139, 2317]]
23+
[[2701, 1284, 2854, 2653, 2277, 1677], [1318, 2364, 446, 1133, 2101, 2184]]
24+
[[2706, 1284, 2855, 2648, 2281, 1675], [1325, 2366, 446, 1114, 2098, 2042]]
25+
[[2706, 1284, 2856, 2635, 2276, 1673], [1326, 2366, 446, 1099, 2091, 1921]]
26+
[[2706, 1284, 2856, 2630, 2277, 1671], [1326, 2366, 446, 1099, 2088, 1751]]
27+
[[2706, 1284, 2856, 2625, 2278, 1668], [1326, 2366, 447, 1098, 2088, 1695]]
28+
[[2706, 1284, 2856, 2616, 2276, 1666], [1326, 2366, 447, 1096, 2079, 1638]]
29+
[[2706, 1284, 2856, 2607, 2274, 1666], [1326, 2366, 448, 1095, 2060, 1584]]
30+
[[2706, 1284, 2856, 2602, 2274, 1664], [1326, 2366, 448, 1094, 2025, 1530]]
31+
[[2706, 1284, 2856, 2600, 2275, 1664], [1328, 2366, 448, 1093, 2023, 1467]]
32+
[[2706, 1284, 2856, 2599, 2276, 1663], [1350, 2366, 448, 1092, 2019, 1455]]
33+
[[2706, 1284, 2856, 2596, 2276, 1663], [1351, 2366, 448, 1091, 1987, 1403]]
34+
[[2706, 1284, 2856, 2594, 2275, 1663], [1351, 2366, 448, 1084, 1982, 1360]]
35+
[[2706, 1284, 2856, 2592, 2274, 1663], [1351, 2366, 448, 1077, 1978, 1324]]
36+
[[2706, 1284, 2856, 2590, 2273, 1663], [1351, 2366, 448, 1075, 1973, 1293]]
37+
[[2706, 1284, 2856, 2588, 2273, 1663], [1351, 2366, 448, 1066, 1968, 1241]]
38+
[[2706, 1284, 2856, 2587, 2272, 1663], [1351, 2366, 448, 1064, 1967, 1230]]
39+
[[2706, 1284, 2856, 2587, 2271, 1663], [1351, 2366, 448, 1064, 1968, 1231]]
40+
[[2706, 1284, 2856, 2587, 2261, 1663], [1351, 2366, 448, 1064, 1968, 1232]]
41+
[[2706, 1284, 2856, 2587, 2260, 1663], [1351, 2366, 448, 1063, 1967, 1233]]
42+
[[2706, 1284, 2856, 2588, 2258, 1663], [1351, 2366, 448, 1063, 1978, 1246]]
43+
[[2704, 1287, 2856, 2592, 2261, 1664], [1345, 2366, 448, 1079, 2051, 1334]]
44+
[[2705, 1287, 2856, 2595, 2263, 1664], [1344, 2366, 448, 1093, 2096, 1494]]
45+
[[2705, 1287, 2856, 2595, 2262, 1664], [1313, 2366, 448, 1095, 2112, 1677]]
46+
[[2705, 1287, 2856, 2595, 2259, 1665], [1290, 2366, 448, 1098, 2111, 1891]]
47+
[[2705, 1287, 2856, 2596, 2259, 1665], [1290, 2366, 448, 1102, 2108, 2159]]
48+
[[2702, 1287, 2856, 2600, 2259, 1665], [1290, 2366, 448, 1104, 2118, 2310]]
49+
[[2701, 1287, 2856, 2611, 2270, 1665], [1290, 2366, 448, 1111, 2145, 2426]]
50+
[[2701, 1287, 2856, 2629, 2291, 1666], [1290, 2366, 448, 1121, 2141, 2585]]
51+
[[2701, 1287, 2856, 2654, 2317, 1667], [1298, 2366, 448, 1128, 2160, 2604]]
52+
[[2698, 1288, 2856, 2721, 2387, 1673], [1291, 2366, 448, 1115, 2165, 2604]]
53+
[[2678, 1288, 2856, 2861, 2513, 1686], [1289, 2366, 449, 1086, 2160, 2603]]
54+
[[2618, 1288, 2856, 3057, 2657, 1713], [1272, 2365, 449, 1061, 2154, 2595]]
55+
[[2535, 1289, 2855, 3209, 2767, 1733], [1272, 2366, 493, 1078, 2135, 2594]]
56+
[[2471, 1289, 2855, 3310, 2859, 1743], [1277, 2365, 597, 1188, 2127, 2596]]
57+
[[2407, 1289, 2855, 3370, 2944, 1759], [1284, 2364, 689, 1278, 2134, 2598]]
58+
[[2356, 1289, 2855, 3403, 3017, 1774], [1288, 2363, 771, 1355, 2171, 2623]]
59+
[[2317, 1289, 2855, 3405, 3062, 1778], [1327, 2363, 846, 1395, 2194, 2702]]
60+
[[2313, 1289, 2855, 3412, 3074, 1778], [1331, 2363, 871, 1409, 2196, 2733]]
61+
[[2313, 1289, 2855, 3409, 3073, 1778], [1341, 2363, 871, 1407, 2197, 2735]]
62+
[[2313, 1288, 2855, 3404, 3073, 1778], [1352, 2363, 871, 1400, 2194, 2745]]
63+
[[2313, 1286, 2855, 3395, 3072, 1776], [1353, 2363, 871, 1394, 2191, 2749]]
64+
[[2313, 1285, 2855, 3391, 3071, 1776], [1362, 2363, 871, 1388, 2183, 2750]]
65+
[[2313, 1285, 2855, 3387, 3070, 1775], [1363, 2363, 871, 1388, 2180, 2750]]
66+
[[2313, 1285, 2855, 3384, 3070, 1775], [1363, 2363, 871, 1388, 2179, 2750]]
67+
[[2313, 1285, 2855, 3382, 3069, 1774], [1363, 2363, 871, 1387, 2179, 2750]]
68+
[[2313, 1286, 2855, 3382, 3070, 1774], [1363, 2363, 871, 1387, 2179, 2750]]
69+
[[2313, 1285, 2855, 3382, 3071, 1774], [1363, 2363, 871, 1387, 2179, 2750]]
70+
[[2313, 1285, 2855, 3382, 3071, 1773], [1363, 2363, 871, 1387, 2179, 2750]]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[[2309, 1238, 2856, 3496, 3076, 1839], [1443, 2384, 1010, 1531, 2064, 2762]]
2+
[[2309, 1238, 2856, 3494, 3076, 1839], [1446, 2384, 1010, 1535, 2067, 2760]]
3+
[[2309, 1238, 2856, 3493, 3076, 1839], [1446, 2384, 1010, 1532, 2073, 2759]]
4+
[[2309, 1238, 2856, 3492, 3076, 1839], [1443, 2384, 1010, 1533, 2077, 2758]]
5+
[[2309, 1238, 2856, 3492, 3077, 1839], [1441, 2384, 1010, 1521, 2074, 2756]]
6+
[[2309, 1238, 2856, 3492, 3077, 1839], [1441, 2384, 1010, 1519, 2066, 2756]]
7+
[[2309, 1238, 2856, 3492, 3077, 1839], [1442, 2382, 1010, 1517, 2065, 2756]]
8+
[[2309, 1238, 2856, 3492, 3077, 1839], [1444, 2382, 1010, 1513, 2064, 2756]]
9+
[[2309, 1238, 2856, 3492, 3077, 1839], [1447, 2381, 1010, 1479, 2046, 2756]]
10+
[[2309, 1238, 2856, 3492, 3080, 1839], [1448, 2371, 1010, 1466, 2027, 2755]]
11+
[[2309, 1238, 2856, 3489, 3076, 1839], [1448, 2317, 1010, 1500, 2012, 2754]]
12+
[[2309, 1238, 2856, 3489, 3074, 1839], [1449, 2243, 1010, 1522, 1970, 2752]]
13+
[[2309, 1238, 2856, 3489, 3073, 1839], [1458, 2173, 1010, 1524, 1893, 2752]]
14+
[[2309, 1238, 2856, 3489, 3072, 1839], [1501, 2161, 1010, 1379, 1749, 2754]]
15+
[[2309, 1238, 2856, 3488, 3071, 1839], [1591, 2161, 1010, 1266, 1601, 2753]]
16+
[[2309, 1238, 2856, 3487, 3071, 1839], [1708, 2164, 1008, 1155, 1430, 2753]]
17+
[[2309, 1238, 2856, 3487, 3073, 1839], [1826, 2219, 1008, 1057, 1283, 2756]]
18+
[[2309, 1238, 2856, 3488, 3075, 1839], [1885, 2328, 1008, 920, 1205, 2753]]
19+
[[2305, 1238, 2856, 3488, 3081, 1840], [1914, 2453, 1008, 816, 1170, 2756]]
20+
[[2303, 1238, 2856, 3489, 3086, 1840], [1909, 2571, 1009, 708, 1166, 2756]]
21+
[[2291, 1238, 2856, 3489, 3098, 1840], [1907, 2644, 1010, 645, 1163, 2763]]
22+
[[2282, 1238, 2856, 3491, 3108, 1840], [1907, 2675, 1010, 603, 1150, 2772]]
23+
[[2282, 1238, 2856, 3496, 3110, 1841], [1907, 2703, 1010, 605, 1161, 2772]]
24+
[[2278, 1240, 2856, 3498, 3113, 1844], [1907, 2704, 1010, 609, 1164, 2771]]
25+
[[2271, 1241, 2856, 3493, 3123, 1845], [1907, 2704, 1010, 609, 1168, 2771]]

demo/myBuddy_Action/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This is Python Demo for myBuddy
2+
3+
## Firmware Requirements: The latest firmware will do
4+
5+
## catch_the_ball
6+
7+
Use myBuddy's hands to grab the ball on the table, move back and forth.
8+
9+
## ChewingGum
10+
11+
Use the gripper to pour the chewing gum out of the table.
12+
13+
## comeOn
14+
15+
Cheer up with red flag in both hands.
16+
17+
## psydack
18+
19+
psyduck dance.
20+
21+
## pass_the_ball
22+
23+
Pass the ball with both hands.
24+
25+
## petCat
26+
27+
pet the cat
28+
29+
## piano
30+
31+
myBuddy plays the song.
32+
33+
## play_ball_cooperatively
34+
35+
myBuddy spins a ball with both hands.
36+
37+
## praise
38+
39+
myBuddy making a thumbs up gesture.
40+
41+
## reject
42+
43+
myBuddy gesture of rejection with both hands.
44+
45+
## symphony
46+
47+
myBuddy conducts like a musician.
48+
49+
## thanHeart
50+
51+
myBuddy making a heart gesture with both hands.
52+
53+
## dence
54+
55+
myBuddy's dance.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# coding=utf8
2+
import os
3+
import time
4+
from pymycobot.mybuddy import MyBuddy
5+
import threading
6+
from threading import Lock, Thread
7+
import cv2 as cv
8+
9+
# Establish serial connection
10+
mc = MyBuddy('/dev/ttyACM0', 115200)
11+
12+
13+
# Release the arms and record the points passed
14+
def read():
15+
time.sleep(10)
16+
t = time.time()
17+
record_list = []
18+
print(1)
19+
while time.time() - t < 40:
20+
angles_1 = mc.get_encoders(1)
21+
angles_2 = mc.get_encoders(2)
22+
if angles_1 and angles_2:
23+
record_list.append([angles_1, angles_2])
24+
time.sleep(0.1)
25+
# Print the read location information, copy and save it as a txt file
26+
for i in record_list:
27+
print(i)
28+
29+
30+
# Take out and use the saved location
31+
def write():
32+
time.sleep(1.5)
33+
mc.power_on()
34+
# The file here uses the saved txt file
35+
data = list(filter(None, open(os.path.join(os.getcwd(), 'catch_the_ball.txt')).read().splitlines()))
36+
# infinite loop
37+
while True:
38+
for angles in data:
39+
print(angles)
40+
mc.set_encoders(1, eval(angles)[0], 80)
41+
time.sleep(0.05)
42+
mc.set_encoders(2, eval(angles)[1], 80)
43+
time.sleep(0.1)
44+
45+
46+
# show emoji
47+
def smile():
48+
# The location where the emoji file is stored
49+
cap = cv.VideoCapture("/home/ubuntu/emo/face_video_3_2.mp4")
50+
out_win = "l"
51+
cv.namedWindow(out_win, cv.WINDOW_NORMAL)
52+
cv.setWindowProperty(out_win, cv.WND_PROP_FULLSCREEN, cv.WINDOW_FULLSCREEN)
53+
# infinite loop
54+
while True:
55+
ret, frame = cap.read()
56+
if frame is not None:
57+
cv.imshow(out_win, frame)
58+
if cv.waitKey(1) & 0xFF == ord('q') or ret == False:
59+
cap = cv.VideoCapture("/home/ubuntu/emo/look_happy.mp4")
60+
61+
62+
if __name__ == '__main__':
63+
# run with multithreading
64+
t1 = threading.Thread(target=write)
65+
t2 = threading.Thread(target=smile)
66+
t1.start()
67+
t2.start()

0 commit comments

Comments
 (0)