-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
audible feedback #15
Open
antonioc76
wants to merge
13
commits into
main
Choose a base branch
from
feat/audible_feedback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
audible feedback #15
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9b1153f
copy/paste source for ROS-TCP-Endpoint per install instructions and r…
danielbrownmsm 1ba05c7
Merge remote-tracking branch 'origin/feat/ros-unity-integration' into…
antonioc76 5b983ff
tcp endpoint, also can switch to autonomous mode using the controller
antonioc76 63490b5
creating a class for playing audio files that the audible feedback no…
antonioc76 e9e8cc8
vivalavida
antonioc76 630fe8c
working but can't stop the audio playback
antonioc76 ded6d25
just_playback
antonioc76 36f24f8
audible feedback node finished
antonioc76 21790fc
oops i logging
antonioc76 95a78ce
Merge branch 'feat/manual' into feat/audible_feedback
antonioc76 323c025
added some sounds, just_playback can be overloaded though
antonioc76 6970891
finished audible feedback node. Added main track example, play and pa…
antonioc76 e720cea
responding to feedback on PR
antonioc76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
|
||
project(autonav_hardware) | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
# find dependencies | ||
find_package(ament_cmake REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
find_package(rclpy REQUIRED) | ||
find_package(rosidl_default_generators REQUIRED) | ||
find_package(autonav_shared REQUIRED) | ||
find_package(autonav_msgs REQUIRED) | ||
# uncomment the following section in order to fill in | ||
# further dependencies manually. | ||
# find_package(<dependency> REQUIRED) | ||
|
||
# C++ | ||
|
||
# Inlcude Cpp "include" directory | ||
include_directories(include) | ||
|
||
# Create Cpp executables | ||
#add_executable(executable_name path_to_executable/executable.cpp) | ||
#ament_target_dependencies(executable_name rclcpp other_dependencies) | ||
|
||
# Install Cpp executables | ||
install(TARGETS | ||
# install executables by name | ||
# executable_name | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
# Python | ||
|
||
# Use only if not using rosidl_generate_interfaces | ||
# Install Python modules | ||
#ament_python_install_package(${PROJECT_NAME}) | ||
|
||
# Install Python programs | ||
install(PROGRAMS | ||
# add programs in format: | ||
#/path_to_program/program.py | ||
src/audible_feedback.py | ||
src/simple_audible_feedback_publisher.py | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
|
||
if(BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
# the following line skips the linter which checks for copyrights | ||
# comment the line when a copyright and license is added to all source files | ||
set(ament_cmake_copyright_FOUND TRUE) | ||
# the following line skips cpplint (only works in a git repo) | ||
# comment the line when this package is in a git repo and when | ||
# a copyright and license is added to all source files | ||
set(ament_cmake_cpplint_FOUND TRUE) | ||
ament_lint_auto_find_test_dependencies() | ||
endif() | ||
|
||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>autonav_hardware</name> | ||
<version>2025.0.1</version> | ||
<description>Contains ROS nodes responsible for interacting with hardware devices</description> | ||
<maintainer email="[email protected]">tony</maintainer> | ||
<license>MIT</license> | ||
|
||
<build_depend>rosidl_default_generators</build_depend> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<buildtool_depend>ament_cmake_python</buildtool_depend> | ||
|
||
<depend>rclpy</depend> | ||
<depend>autonav_shared</depend> | ||
<depend>autonav_msgs</depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
<test_depend>ament_lint_common</test_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
155 changes: 155 additions & 0 deletions
155
autonav_ws/src/autonav_hardware/src/audible_feedback.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#!/usr/bin/env python3 | ||
|
||
|
||
import rclpy | ||
from autonav_msgs.msg import AudibleFeedback | ||
|
||
from autonav_shared.node import Node | ||
from autonav_shared.types import LogLevel, DeviceState, SystemState | ||
import time | ||
import os | ||
from just_playback import Playback | ||
import PySoundSphere | ||
|
||
|
||
class AudibleFeedbackConfig: | ||
def __init__(self): | ||
self.volume = 1.0 | ||
self.autonomous_transition_filepath = os.path.expanduser('~/Documents/imposter.mp3') | ||
|
||
|
||
class AudibleFeedbackNode(Node): | ||
def __init__(self): | ||
super().__init__("audible_feedback_node") | ||
self.write_config(AudibleFeedbackConfig()) | ||
self.current_playing_thread = None | ||
self.secondary_tracks = [] | ||
self.main_track = None | ||
self.old_system_state = self.system_state | ||
|
||
# | ||
self.audible_feedback_subscriber = self.create_subscription( | ||
AudibleFeedback, | ||
"/autonav/audible_feedback", | ||
self.on_audible_feedback_received, | ||
20 | ||
) | ||
|
||
self.system_state_monitor = self.create_timer(0.5, self.monitor_system_state) | ||
self.track_monitor = self.create_timer(0.5, self.monitor_tracks) | ||
|
||
def on_audible_feedback_received(self, msg:AudibleFeedback): | ||
self.monitor_tracks() | ||
|
||
# self.log(f"{len(self.secondary_tracks)}", LogLevel.DEBUG) | ||
if msg.stop_all: | ||
self.stop_all() | ||
return | ||
|
||
if msg.pause_all: | ||
self.pause_main_track() | ||
return | ||
|
||
if msg.unpause_all: | ||
self.unpause_main_track() | ||
return | ||
|
||
else: | ||
# self.log(f"playing {msg.filename}") | ||
filename = str(msg.filename) | ||
main_track = msg.main_track | ||
|
||
# self.log(f"heard request to play {msg.filename}") | ||
self.play_sound(filename, main_track) | ||
|
||
|
||
def play_sound(self, filename, main_track: bool): | ||
if main_track and self.main_track is not None: | ||
return | ||
|
||
playback = PySoundSphere.AudioPlayer("ffplay", debug_allow_multiple_playbacks=False) | ||
try: | ||
playback.load(filename) | ||
except: | ||
self.log("invalid filename", LogLevel.ERROR) | ||
return | ||
|
||
playback.volume = self.config.get('volume') | ||
playback.play() | ||
|
||
if main_track: | ||
self.main_track = playback | ||
|
||
else: | ||
self.secondary_tracks.append(playback) | ||
|
||
|
||
def stop_all(self): | ||
if self.main_track is not None: | ||
self.log(f"{self.main_track}") | ||
|
||
for track in self.secondary_tracks: | ||
self.log(f"{track}") | ||
|
||
for track in self.secondary_tracks: | ||
track.stop() | ||
|
||
self.secondary_tracks = [] | ||
try: | ||
self.main_track.stop() | ||
except: | ||
self.log("No main track", LogLevel.ERROR) | ||
|
||
self.main_track = None | ||
|
||
|
||
def pause_main_track(self): | ||
try: | ||
self.main_track.pause() | ||
except: # main track is paused or doesn't exist | ||
pass | ||
|
||
|
||
def unpause_main_track(self): | ||
try: | ||
self.main_track.play() | ||
|
||
except: # main track is playing or doesn't exist | ||
pass | ||
|
||
|
||
def monitor_tracks(self): | ||
if len(self.secondary_tracks) > 16: | ||
self.secondary_tracks.pop() | ||
|
||
|
||
def monitor_system_state(self): | ||
self.monitor_tracks() | ||
if self.system_state == SystemState.AUTONOMOUS and self.old_system_state != SystemState.AUTONOMOUS: | ||
playback = PySoundSphere.AudioPlayer("ffplay", debug_allow_multiple_playbacks = False) | ||
|
||
try: | ||
filename = self.config.get('autonomous_transition_filepath') | ||
except: | ||
self.log("invalid autonomous transition filepath") | ||
return | ||
|
||
playback.load(filename) | ||
playback.volume = self.config.get('volume') | ||
playback.play() | ||
|
||
self.secondary_tracks.append(playback) | ||
self.old_system_state = SystemState.AUTONOMOUS | ||
|
||
else: | ||
self.old_system_state = self.system_state | ||
|
||
|
||
def main(): | ||
rclpy.init() | ||
audible_feedback_node = AudibleFeedbackNode() | ||
rclpy.spin(audible_feedback_node) | ||
rclpy.shutdown() | ||
|
||
if __name__ == "__main__": | ||
main() |
56 changes: 56 additions & 0 deletions
56
autonav_ws/src/autonav_hardware/src/simple_audible_feedback_publisher.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import rclpy | ||
from rclpy.node import Node | ||
|
||
from autonav_msgs.msg import AudibleFeedback | ||
import os | ||
|
||
|
||
class MinimalAudibleFeedbackPublisher(Node): | ||
|
||
def __init__(self): | ||
super().__init__('minimal_publisher') | ||
self.publisher_ = self.create_publisher( | ||
AudibleFeedback, | ||
'/autonav/audible_feedback', | ||
20 | ||
) | ||
|
||
timer_period = 3 # seconds | ||
self.timer = self.create_timer(timer_period, self.timer_callback) | ||
self.i = 0 | ||
|
||
|
||
def timer_callback(self): | ||
msg = AudibleFeedback() | ||
if self.i == 0: | ||
msg.filename = os.path.expanduser("~/Documents/vivalavida.wav") | ||
|
||
elif self.i % 3 == 0: | ||
msg.stop_all = True | ||
|
||
else: | ||
msg.filename = os.path.expanduser("~/Documents/metal-pipe.wav") | ||
|
||
self.publisher_.publish(msg) | ||
self.get_logger().info('Publishing: "%s"' % msg.filename) | ||
self.i += 1 | ||
|
||
|
||
def main(args=None): | ||
rclpy.init(args=args) | ||
|
||
minimal_publisher = MinimalAudibleFeedbackPublisher() | ||
|
||
rclpy.spin(minimal_publisher) | ||
|
||
# Destroy the node explicitly | ||
# (optional - otherwise it will be done automatically | ||
# when the garbage collector destroys the node object) | ||
minimal_publisher.destroy_node() | ||
rclpy.shutdown() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import PySoundSphere | ||
import os | ||
import time | ||
|
||
player = PySoundSphere.AudioPlayer("ffplay") | ||
player.load(os.path.expanduser("~/Documents/vivalavida.wav")) | ||
|
||
player.volume = 1.0 | ||
|
||
print(player) | ||
player.play() | ||
|
||
time.sleep(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<launch> | ||
<node pkg="autonav_example_py" exec="example.py" output="screen" emulate_tty="true" /> | ||
<node pkg="autonav_example_cpp" exec="autonav_example_cpp" output="screen" emulate_tty="true" /> | ||
<node pkg="ros_tcp_endpoint" exec="default_server_endpoint" output="screen" emulate_tty="true" /> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SystemStateTransition might get implemented this year, TBD, so you might be able to change this in the future