|
| 1 | +import time |
| 2 | +from pymycobot.mycobot import MyCobot |
| 3 | + |
| 4 | + |
| 5 | +reset = [153.19, 137.81, -153.54, 156.79, 87.27, 13.62] |
| 6 | +zero = [0,0,0,0,0,0] |
| 7 | +coords = [160, 160, 160, 0, 0, 0] |
| 8 | +sp = 100 |
| 9 | + |
| 10 | +def test(mc): |
| 11 | + print('Start check state api\n') |
| 12 | + |
| 13 | + print('goto zero position') |
| 14 | + mc.send_angles(zero, sp) |
| 15 | + time.sleep(4) |
| 16 | + print('is in position(angle): 1 - true, 0 - false, -1 - error data') |
| 17 | + for _ in range(10): |
| 18 | + print(mc.is_in_position(zero, 0), ' ', end='') |
| 19 | + time.sleep(.5) |
| 20 | + |
| 21 | + print('\nis in position(coords): 1 - true, 0 - false, -1 - error data') |
| 22 | + for _ in range(10): |
| 23 | + print(mc.is_in_position(coords, 1), ' ', end='') |
| 24 | + time.sleep(.5) |
| 25 | + |
| 26 | + mc.send_coords(coords, 100, 0) |
| 27 | + time.sleep(4) |
| 28 | + print('\nis in position(coords): 1 - true, 0 - false, -1 - error data') |
| 29 | + for _ in range(10): |
| 30 | + print(mc.is_in_position(coords, 1), ' ', end='') |
| 31 | + time.sleep(.5) |
| 32 | + |
| 33 | + |
| 34 | + mc.send_angles(zero, 100) |
| 35 | + time.sleep(4) |
| 36 | + print('is moving: 1 - true, 0 - false') |
| 37 | + print(mc.is_moving()) |
| 38 | + time.sleep(3) |
| 39 | + print('is moving: 1 - true, 0 - false') |
| 40 | + print(mc.is_moving()) |
| 41 | + time.sleep(1) |
| 42 | + mc.jog_angle(1, 1, 35) |
| 43 | + |
| 44 | + t = time.time() |
| 45 | + print('is moving: 1 - true, 0 - false') |
| 46 | + while time.time() - t < 20: |
| 47 | + print(mc.is_moving()) |
| 48 | + time.sleep(.5) |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == '__main__': |
| 53 | + print(''' |
| 54 | +-------------------------------------------- |
| 55 | +| This file will test state method: | |
| 56 | +| is_in_position() | |
| 57 | +| is_moving() | |
| 58 | +-------------------------------------------- |
| 59 | + ''') |
| 60 | + time.sleep(3) |
| 61 | + with open('./port.txt') as f: |
| 62 | + port = f.read().strip().replace('\n', '') |
| 63 | + print(port) |
| 64 | + mc = MyCobot(port) |
| 65 | + test(mc) |
| 66 | + |
0 commit comments