Skip to content

Commit ad5c4d9

Browse files
committed
update test file
1 parent 6c7f714 commit ad5c4d9

File tree

4 files changed

+143
-125
lines changed

4 files changed

+143
-125
lines changed

tests/basic_test.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import time, random, subprocess
2+
from pymycobot.mycobot import MyCobot
3+
from pymycobot.genre import Angle, Coord
4+
5+
reset = [153.19, 137.81, -153.54, 156.79, 87.27, 13.62]
6+
7+
def test(mycobot):
8+
print('\nStart check basic options\n')
9+
10+
color_name = ['red', 'green', 'blue']
11+
color_code = ['ff0000', '00ff00', '0000ff']
12+
i = random.randint(0, len(color_code) - 1)
13+
mycobot.set_led_color(color_code[i])
14+
print('::set_led_color() ==> color {}\n'.format(color_name[i]))
15+
time.sleep(3)
16+
17+
angles = [0,0,0,0,0,0]
18+
mycobot.send_angles(angles, 100)
19+
print('::send_angles() ==> angles {}, speed 100\n'.format(angles))
20+
time.sleep(3)
21+
22+
print('::get_angles() ==> degrees: {}\n'.format(mycobot.get_angles()))
23+
time.sleep(1)
24+
25+
mycobot.send_angle(Angle.J1.value, 90, 50)
26+
print('::send_angle() ==> angle: joint1, degree: 90, speed: 50\n')
27+
time.sleep(4)
28+
29+
radians = [1,1,1,1,1,1]
30+
mycobot.send_radians(radians, 100)
31+
print('::send_radians() ==> set radians {}, speed 100\n'.format(radians))
32+
time.sleep(3)
33+
34+
print('::get_radians() ==> radians: {}\n'.format(mycobot.get_radians()))
35+
time.sleep(1)
36+
37+
coords = [160, 160, 160, 0, 0, 0]
38+
mycobot.send_coords(coords, 70, 0)
39+
print('::send_coords() ==> send coords {}, speed 70, mode 0\n'.format(coords))
40+
time.sleep(3)
41+
42+
print('::get_coords() ==> coords {}\n'.format(mycobot.get_coords()))
43+
time.sleep(0.5)
44+
45+
mycobot.send_coord(Coord.X.value, -40, 70)
46+
print('::send_coord() ==> send coord id: X, coord value: -40, speed: 70\n')
47+
time.sleep(2)
48+
49+
print('::set_free_mode()\n')
50+
mycobot.send_angles(reset, 100)
51+
time.sleep(5)
52+
mycobot.set_free_mode()
53+
54+
print('=== check end ===\n')
55+
56+
57+
if __name__ == '__main__':
58+
print('''
59+
————————————————————————————————————————————
60+
| This file will test basic option method: |
61+
| set_led_color() |
62+
| send_angles() |
63+
| get_angles() |
64+
| send_angle() |
65+
| send_radians() |
66+
| get_radians() |
67+
| send_coords() |
68+
| get_coords() |
69+
| send_coord() |
70+
| set_free_mode() |
71+
————————————————————————————————————————————
72+
''')
73+
time.sleep(3)
74+
# port = subprocess.check_output(['echo -n /dev/ttyUSB*'],
75+
# shell=True).decode()
76+
port = "/dev/cu.usbserial-0203B030"
77+
# mycobot = MyCobot(port, debug=True)
78+
mycobot = MyCobot(port)
79+
test(mycobot)
80+

tests/loop_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
# port = "/dev/cu.usbserial-0203B030"
99
port = "/dev/cu.usbserial-0213245D"
1010
cobot = MyCobot(port)
11-
# test(cobot)
1211
cobot.send_angles([0,0,0,0,0,0],100)
1312
time.sleep(10)
14-
print('over')
13+
print('start')
1514
for count in range(50):
1615
time.sleep(0.05)
1716
cobot.send_angle(1, (-30), 100)

tests/power_state_test.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import time, random, subprocess
2+
from pymycobot.mycobot import MyCobot
3+
from pymycobot.genre import Angle, Coord
4+
5+
6+
reset = [153.19, 137.81, -153.54, 156.79, 87.27, 13.62]
7+
zero = [0,0,0,0,0,0]
8+
sp = 100
9+
10+
def test(mc):
11+
print('Start check power state api\n')
12+
13+
mc.power_on()
14+
time.sleep(.5)
15+
f = mc.is_power_on()
16+
print('is power on: {}'.format(f))
17+
assert f == 1, 'should be 1'
18+
mc.send_angles(zero, sp)
19+
time.sleep(3)
20+
21+
for _ in range(3):
22+
mc.power_off()
23+
time.sleep(.5)
24+
f = mc.is_power_on()
25+
print('is power on: {}'.format(f))
26+
assert f == 0, 'should be 0'
27+
28+
mc.send_angles(reset, sp)
29+
time.sleep(1)
30+
31+
mc.power_on()
32+
time.sleep(.5)
33+
f = mc.is_power_on()
34+
print('is power on: {}'.format(f))
35+
assert f == 1, 'should be 1'
36+
37+
mc.send_angles(reset, 100)
38+
time.sleep(5)
39+
mc.set_free_mode()
40+
41+
print('=== check end ===\n')
42+
43+
44+
45+
46+
47+
if __name__ == '__main__':
48+
print('''
49+
————————————————————————————————————————————
50+
| This file will test power state method: |
51+
| power_off() |
52+
| power_on() |
53+
| is_power_on() |
54+
————————————————————————————————————————————
55+
''')
56+
time.sleep(3)
57+
port = "/dev/cu.usbserial-0203B030"
58+
mc = MyCobot(port)
59+
test(mc)
60+
61+
62+

tests/test.py

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)