-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfistbump.py
56 lines (42 loc) · 1.48 KB
/
fistbump.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
import rospy
import time
import colorsys
class FistbumpHandler:
def __init__(self, robot):
self.robot = robot
self.bumped = False
self.counter = 0
self.previous_accel = None
self.rate = rospy.Rate(10)
def prompt(self):
time.sleep(0.2)
self.robot.behavior.set_lift_height(0.5)
self.detect_fistbump(8)
def detect_fistbump(self, duration_s):
time_elapsed = 0
while not rospy.is_shutdown():
proximity = self.robot.proximity.last_sensor_reading.distance.distance_mm
if proximity <= 60:
self.counter += 1
else:
self.counter = 0
accel = self.robot.accel.x
if (
self.previous_accel is not None
and not self.bumped
and self.counter >= 1
and abs(accel - self.previous_accel) > 100
):
self.robot.anim.play_animation("anim_fistbump_success_01")
self.bumped = True
hue, sat, _ = colorsys.rgb_to_hsv(0, 153, 255)
resp = self.robot.behavior.set_eye_color(hue, sat)
print("Fistbumped!")
break
self.previous_accel = accel
time_elapsed += 1
if time_elapsed > 10 * duration_s:
print("Fistbump not done")
self.robot.behavior.set_lift_height(0.0)
break
self.rate.sleep()