forked from robotstreamer/robotstreamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvibrate.py
79 lines (49 loc) · 1.75 KB
/
vibrate.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from math import sin
from robot_util import times
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor
import time
vibrateSystemActive = False
def setMotorSpeed(mh, motorIndex, direction, s):
motor = mh.getMotor(motorIndex+1)
#print("direction", direction)
if direction == 1:
motor.setSpeed(s)
motor.run(Adafruit_MotorHAT.FORWARD)
if direction == -1:
motor.setSpeed(s)
motor.run(Adafruit_MotorHAT.BACKWARD)
def vibrate(mh, forwardDefinition):
global vibrateSystemActive
if vibrateSystemActive:
print("skip")
else:
vibrateSystemActive = True
for i in range(60):
a = float(i) / 1.0
speed = int(sin(a) * 255.0)
print("speed", speed)
if speed >= 0:
directions = forwardDefinition
else:
directions = times(forwardDefinition, -1)
speed = -speed
print(speed, directions)
for motorIndex in range(4):
setMotorSpeed(mh,
motorIndex,
directions[motorIndex],
speed)
time.sleep(0.05)
turnOffMotors(mh)
vibrateSystemActive = False
#todo: this function should be in a file shared by this and rsbot
def turnOffMotors(mh):
mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(2).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(3).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(4).run(Adafruit_MotorHAT.RELEASE)
def main():
mh = Adafruit_MotorHAT(addr=0x60)
vibrate(mh, [-1,1,-1,1])
if __name__ == "__main__":
main()