|
| 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 | + |
0 commit comments