0
$\begingroup$

Rosanswers logo

Hi Everyone

I am new to ROS and cpp so please be patient ;)

I work with Ubuntu 18.04.4 LTS and ROS Melodic. I installed audio_commen with command sudo apt-get install ros-melodic-audio-common according the side link

After some hours of trying I created completely new package just for this function to eliminate other factors and at the moment it looks pretty simple.

node code:

   #include "ros/ros.h"
   #include <sound_play/sound_play.h>
  
   int main(int argc, char **argv)  {

   ros::init(argc,argv,"audio_common_tutorial");
   ros::NodeHandle n;

   sound_play::SoundClient sc;
   sc.playWaveFromPkg("sound_play", "sounds/BACKINGUP.ogg");
   sc.playWave( "/home/ntuser/catkin_ws/src/audio_common_tutorial/doc/file.wav");

   ros::spin();
   return 0;
   }

I am starting the nodes with launch file:

   <launch>
   <include file="$(find sound_play)/soundplay_node.launch">  </include>

  <node pkg="order_receiver" type="order_receiver" name="order_receiver" output="screen">
   <rosparam command="load" file="$(find order_receiver)/config/default.yaml" />
   </node>
   </launch>

both sounds command failed

     [ WARN] [1587131813.785943539]: Sound command issued, but no node is subscribed to the topic. Perhaps you forgot to run soundplay_node.py

even thouth the node is listed by launching and after command rosnode list

The package WORKS good from command line e.g rosrun sound_play play.py "path" or roslaunch sound_play test.launch

Any ideas and recommendation?

regards


Originally posted by eliza on ROS Answers with karma: 16 on 2020-04-17

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Hi everyone

I solve it. It looks like I need a give a some time to initialize SoundClient. After I implemented a delay before issuing a sound ,everything works.

The code look as follow:

#include "ros/ros.h"
#include <sound_play/sound_play.h>

int main(int argc, char **argv)  {

ros::init(argc,argv,"audio_common_tutorial");
ros::NodeHandle n;

sound_play::SoundClient sc;
ros::Duration(1, 0).sleep();
sc.playWaveFromPkg("sound_play", "sounds/BACKINGUP.ogg");
sc.playWave( "/home/ntuser/catkin_ws/src/audio_common_tutorial/doc/file.wav");

ros::spin();
return 0;
}

If anyone has some smart comment why it is so I am happy to hear it ;)

regards


Originally posted by eliza with karma: 16 on 2020-04-20

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.