Adding the barking code and the launch file

This commit is contained in:
Nathan BEAUD 2024-04-09 17:15:53 +02:00
parent ef7d32ad8e
commit f19770db80
2 changed files with 29 additions and 0 deletions

22
barking.py Normal file
View File

@ -0,0 +1,22 @@
import pygame
import time
import random
# Initialize pygame mixer
pygame.mixer.init()
# Load the sound file
sound = pygame.mixer.Sound("bark5.wav")
try:
while True:
# Play the sound
sound.play()
# Wait for the sound to finish playing
time.sleep(sound.get_length())
# Wait for a random interval between plays, e.g., 2 to 5 seconds
time.sleep(random.randint(2, 5))
except KeyboardInterrupt:
print("Playback stopped by user.")

View File

@ -0,0 +1,7 @@
<launch>
<!-- Launch barking.py -->
<node name="barking" pkg="my_robot_package" type="barking.py" output="screen"/>
<!-- Launch bring_ball.py -->
<node name="bring_ball" pkg="my_robot_package" type="bring_ball.py" output="screen"/>
</launch>