-
Notifications
You must be signed in to change notification settings - Fork 21
/
demo_motor.py
executable file
·54 lines (41 loc) · 1.45 KB
/
demo_motor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
from pyb00st.movehub import MoveHub
from pyb00st.constants import *
from time import sleep
MY_MOVEHUB_ADD = '00:16:53:A4:CD:7E'
MY_BTCTRLR_HCI = 'hci0'
mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI)
try:
mymovehub.start()
# turn motor A ON for 1000 ms at 100% duty cycle in both directions
mymovehub.run_motor_for_time(MOTOR_A, 1000, 100)
sleep(1)
mymovehub.run_motor_for_time(MOTOR_A, 1000, -100)
sleep(1)
sleep(0.5)
# rotate motor 90 degrees at 100% duty cycle in both directions
mymovehub.run_motor_for_angle(MOTOR_A, 90, 100)
sleep(0.5)
mymovehub.run_motor_for_angle(MOTOR_A, 90, -100)
sleep(0.5)
# turn pair AB ON for 1000 ms at 100% duty cycle in both direction
mymovehub.run_motors_for_time(MOTOR_AB, 1000, 100, 100)
sleep(1)
mymovehub.run_motors_for_time(MOTOR_AB, 1000, 100, -100)
sleep(1)
mymovehub.run_motors_for_time(MOTOR_AB, 1000, -100, -100)
sleep(1)
mymovehub.run_motors_for_time(MOTOR_AB, 1000, -100, 100)
sleep(1)
sleep(0.5)
# rotate pair AB 90 degrees at 100% duty cycle in both direction
mymovehub.run_motors_for_angle(MOTOR_AB, 90, 100, 100)
sleep(0.5)
mymovehub.run_motors_for_angle(MOTOR_AB, 90, 100, -100)
sleep(0.5)
mymovehub.run_motors_for_angle(MOTOR_AB, 90, -100, -100)
sleep(0.5)
mymovehub.run_motors_for_angle(MOTOR_AB, 90, -100, 100)
sleep(0.5)
finally:
mymovehub.stop()