Skip to content
Snippets Groups Projects
Commit 11651133 authored by pal's avatar pal
Browse files

Add sound for each token that has been placed on the board - remove state...

Add sound for each token that has been placed on the board - remove state event detection on picked tokens
parent da2b3c1e
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<!-- One maintainer tag required, multiple allowed, one person per tag --> <!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: --> <!-- Example: -->
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> --> <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
<maintainer email="aandriella@todo.todo">aandriella</maintainer> <maintainer email="aandriella@iri.upc.edu">Antonio Andriella</maintainer>
<!-- One license tag required, multiple allowed, one license per tag --> <!-- One license tag required, multiple allowed, one license per tag -->
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<!-- Author tags are optional, multiple are allowed, one per tag --> <!-- Author tags are optional, multiple are allowed, one per tag -->
<!-- Authors do not have to be maintainers, but could be --> <!-- Authors do not have to be maintainers, but could be -->
<!-- Example: --> <!-- Example: -->
<!-- <author email="jane.doe@example.com">Jane Doe</author> --> <author email="aandriella@iri.upc.edu">Antonio Andriella</author>
<!-- The *depend tags are used to specify dependencies --> <!-- The *depend tags are used to specify dependencies -->
......
...@@ -13,6 +13,8 @@ import csv ...@@ -13,6 +13,8 @@ import csv
import time import time
import rospy import rospy
from std_msgs.msg import String, Int8 from std_msgs.msg import String, Int8
import pygame
from iri_rfid_board_scanner.msg import BoardIds from iri_rfid_board_scanner.msg import BoardIds
from board_state.msg import StrList from board_state.msg import StrList
...@@ -40,10 +42,19 @@ class GameFramework(): ...@@ -40,10 +42,19 @@ class GameFramework():
initial_board_from_launch = rospy.get_param('/initial_board') initial_board_from_launch = rospy.get_param('/initial_board')
solution_board_from_launch = rospy.get_param('/solution_board')
self.initial_board = {int(k): str(v) for k, v in initial_board_from_launch.items()} self.initial_board = {int(k): str(v) for k, v in initial_board_from_launch.items()}
self.solution_board = {int(k): str(v) for k, v in solution_board_from_launch.items()}
def play_sound(self, file_path, sleep):
'''
play a sound using pygame
'''
pygame.mixer.init()
# pygame.mixer.music.load(parent_dir_of_file+'/sounds/wrong_move_trim.mp3')
pygame.mixer.music.load(parent_dir_of_file + file_path)
pygame.mixer.music.play(0)
time.sleep(sleep)
def get_tokens_id(self): def get_tokens_id(self):
return self.tokens return self.tokens
...@@ -51,9 +62,6 @@ class GameFramework(): ...@@ -51,9 +62,6 @@ class GameFramework():
def get_initial_board(self): def get_initial_board(self):
return self.initial_board return self.initial_board
def get_solution_board(self):
return self.solution_board
#get value from the topic #get value from the topic
def get_electro_board_ids(self): def get_electro_board_ids(self):
return self.electro_board return self.electro_board
...@@ -73,7 +81,7 @@ class GameFramework(): ...@@ -73,7 +81,7 @@ class GameFramework():
''' '''
from_ids_to_tokens = dict() from_ids_to_tokens = dict()
for i in range(len(ids)): for i in range(len(ids)):
from_ids_to_tokens[ids[i]] = tokens[i] from_ids_to_tokens[ids[i]] = "v"+tokens[i]
return from_ids_to_tokens return from_ids_to_tokens
...@@ -86,7 +94,7 @@ class GameFramework(): ...@@ -86,7 +94,7 @@ class GameFramework():
for i in range(len(msg)): for i in range(len(msg)):
if msg[i] == 0: if msg[i] == 0:
# i+1 because the id start # i+1 because the id start
self.electro_board_with_tokens[i+1] = '0' self.electro_board_with_tokens[i+1] = 'v0'
else: else:
self.electro_board_with_tokens[i+1] = from_ids_to_tokens_dict.get(msg[i]) self.electro_board_with_tokens[i+1] = from_ids_to_tokens_dict.get(msg[i])
return self.electro_board_with_tokens return self.electro_board_with_tokens
...@@ -108,7 +116,7 @@ class GameFramework(): ...@@ -108,7 +116,7 @@ class GameFramework():
z = new_board_state.get(x1) == old_board_state.get(x1) z = new_board_state.get(x1) == old_board_state.get(x1)
if not z: if not z:
#print('location', x1) #print('location', x1)
if (new_board_state.get(x1))!='0': if (new_board_state.get(x1))!='v0':
token = (new_board_state.get(x1)) token = (new_board_state.get(x1))
#check where the token is in the new configuration #check where the token is in the new configuration
prev_location = self.get_token_location_from_board_state(old_board_state, token) prev_location = self.get_token_location_from_board_state(old_board_state, token)
...@@ -134,11 +142,11 @@ class GameFramework(): ...@@ -134,11 +142,11 @@ class GameFramework():
for loc, token in self.current_board.items(): for loc, token in self.current_board.items():
if token == (token_id): if token == (token_id):
self.current_board[loc] = '0' self.current_board[loc] = 'v0'
for key in self.current_board.keys(): for key in self.current_board.keys():
if location == key: if location == key:
self.current_board[key] = (token_id) self.current_board[key] = "v"+(token_id)
else: else:
pass pass
...@@ -154,25 +162,38 @@ def main(): ...@@ -154,25 +162,38 @@ def main():
m = GameFramework() m = GameFramework()
initial_board = m.get_initial_board() #initial_board = m.get_initial_board()
current_board = initial_board.copy() #current_board = initial_board.copy()
############################################################### ###############################################################
pub = rospy.Publisher('board_status', StrList, queue_size=10) pub = rospy.Publisher('board_status', StrList, queue_size=10)
rospy.init_node('big_hero', anonymous=True) rospy.init_node('big_hero', anonymous=True)
rate = rospy.Rate(10) # 10hz rate = rospy.Rate(10) # 10hz
event_counter = 0
rospy.sleep(2)
current_board = m.get_electro_board().copy()
while not rospy.is_shutdown(): while not rospy.is_shutdown():
detected_board = m.get_electro_board() detected_board = m.get_electro_board()
detected_movement = m.detect_move(current_board, detected_board) detected_movement = m.detect_move(current_board, detected_board)
if (len(detected_movement)) >= 1 and detected_movement[0][0] != None: if (len(detected_movement)) >= 1 and detected_movement[0][0] != None:
#check if 10 token have been detected
board_state_msg = detected_board.values() board_state_msg = detected_board.values()
m.play_sound("/sounds/pull-out.ogg", 0.2)
pub.publish(board_state_msg) pub.publish(board_state_msg)
event_counter += 1
rate.sleep() rate.sleep()
current_board = detected_board.copy() current_board = detected_board.copy()
print("Movement detected") print("***********************************")
print("Board state "+str(board_state_msg))
print("Event counter "+str(event_counter))
print("***********************************")
else: else:
print("No movement detected") pass
# a.data = [3250, 2682, 6832, 2296, 8865, 7796, 6955, 8236] # a.data = [3250, 2682, 6832, 2296, 8865, 7796, 6955, 8236]
# pub.publish(a) # pub.publish(a)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment