Skip to content

Commit 128ef0e

Browse files
committed
Use the Semaphore alphabet for directions
1 parent 89bf73f commit 128ef0e

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

turtlebot4_vision_tutorials/turtlebot4_vision_tutorials/pose_detection.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@
4242
(1, 6): 'Y', (5, 6): 'Z',
4343
}
4444

45+
# Semaphore letters that indicate to drive left
46+
LEFT_LETTERS = [
47+
'B',
48+
'C',
49+
'H',
50+
'I',
51+
'O',
52+
'S',
53+
]
54+
55+
# Semaphore letters that indicate to drive right
56+
RIGHT_LETTERS = [
57+
'E',
58+
'F',
59+
'M',
60+
'W',
61+
'X',
62+
'Z',
63+
]
64+
65+
# Semaphore letters that indicate to drive forward
66+
FORWARD_LETTERS = [
67+
'T',
68+
'U',
69+
'#'
70+
]
71+
4572
KEYPOINT_DICT = {
4673
'nose': 0,
4774
'left_eye': 1,
@@ -215,21 +242,21 @@ def angle_with_y(v):
215242
right_pose = int((right_arm_angle + 202.5) / 45) % 8
216243
left_pose = int((left_arm_angle + 202.5) / 45) % 8
217244
letter = SEMAPHORE_FLAG.get((right_pose, left_pose), None)
245+
218246
dir_temp = Dir.STOP
219-
if right_pose == 2 and (left_pose > 3 and left_pose < 6):
247+
if letter in LEFT_LETTERS:
220248
dir_temp = Dir.LEFT
221-
self.lights_blue_ = True
222-
elif left_pose == 6 and (right_pose > 2 and right_pose < 5):
249+
elif letter in RIGHT_LETTERS:
223250
dir_temp = Dir.RIGHT
224-
elif (left_pose > 6 or left_pose == 0) and right_pose < 2:
251+
elif letter in FORWARD_LETTERS:
225252
dir_temp = Dir.STRAIGHT
226-
if dir_temp != Dir.STOP:
227-
self.lights_blue_ = True
253+
228254
if dir_temp == self.dir:
229255
self.dir_confirm += 1
230256
else:
231257
self.dir_confirm = 1
232258
self.dir = dir_temp
259+
233260
if self.dir_confirm > 4:
234261
cmd_vel_msg = Twist()
235262
if self.dir == Dir.LEFT:

0 commit comments

Comments
 (0)