17 #include <ros/common.h>
22 #include <cob_mimic/SetMimicAction.h>
23 #include <cob_mimic/SetMimicGoal.h>
24 #include <cob_mimic/SetMimicFeedback.h>
25 #include <cob_mimic/SetMimicResult.h>
27 #include <cob_mimic/SetMimic.h>
28 #include <cob_mimic/SetMimicRequest.h>
29 #include <cob_mimic/SetMimicResponse.h>
34 #include <boost/thread.hpp>
35 #include <boost/filesystem.hpp>
36 #include <boost/format.hpp>
37 #include <boost/random/mersenne_twister.hpp>
38 #include <boost/random/uniform_real_distribution.hpp>
39 #include <boost/random/uniform_int_distribution.hpp>
86 #if ROS_VERSION_MINIMUM(1, 15, 0) // ros noetic is 1.15.x
90 "--mouse-hide-timeout=0",
96 "--no-video-title-show",
102 int argc =
sizeof( argv ) /
sizeof( *argv );
149 if((lgn = getlogin()) == NULL)
151 lgn = getenv(
"USER");
152 if(lgn == NULL || std::string(lgn) ==
"")
158 std::string username(lgn);
162 std::string mimics_path = pkg_path +
"/common";
170 catch(boost::filesystem::filesystem_error
const & e)
202 if(goal->mimic !=
"falling_asleep" && goal->mimic !=
"sleeping")
207 cob_mimic::SetMimic::Response &res )
215 if(req.mimic !=
"falling_asleep" && req.mimic !=
"sleeping")
221 bool set_mimic(std::string mimic,
int repeat,
float speed,
bool blocking)
224 ROS_INFO(
"New mimic request with: %s", mimic.c_str());
226 active_mimic_= (boost::format(
"Mimic: %1%, repeat: %2%, speed: %3%, blocking: %4%")% mimic % repeat % speed % blocking).str();
228 ROS_INFO(
"Mimic: %s (speed: %f, repeat: %d)", mimic.c_str(), speed, repeat);
233 if ( !boost::filesystem::exists(filename) )
235 if ( !boost::filesystem::exists(mimic) )
237 ROS_ERROR(
"File not found: %s", filename.c_str());
244 ROS_INFO(
"Playing mimic from non-default file: %s", mimic.c_str());
250 repeat = std::max(1, repeat);
251 if(repeat > 1 && !blocking)
253 ROS_WARN_STREAM(
"Mimic repeat ("<<repeat<<
") is overwritten by blocking ("<<blocking<<
"). Will only play once.");
260 ROS_WARN_STREAM(
"Mimic speed ("<<speed<<
") cannot be 0 or negative. Setting Speed to 1.0");
265 if(libvlc_media_player_set_rate(
vlc_player_, speed)!=0){
ROS_ERROR(
"failed to set movie play rate");}
271 ROS_WARN(
"mimic %s preempted between repetitions", mimic.c_str());
280 ROS_ERROR(
"failed to create media for filepath %s", filename.c_str());
299 while(blocking && (libvlc_media_player_is_playing(
vlc_player_) == 1))
302 ROS_DEBUG(
"still playing %s", mimic.c_str());
305 ROS_WARN(
"mimic %s preempted while playing", mimic.c_str());
325 bool copy_dir( boost::filesystem::path
const & source,
326 boost::filesystem::path
const & mimic_folder )
328 namespace fs = boost::filesystem;
332 if(!fs::exists(source) || !fs::is_directory(source))
334 ROS_ERROR_STREAM(
"Source directory " << source.string() <<
" does not exist or is not a directory.");
337 if(fs::exists(mimic_folder))
339 ROS_INFO_STREAM(
"Destination directory " << mimic_folder.string() <<
" already exists.");
343 if(!fs::create_directory(mimic_folder))
345 ROS_ERROR_STREAM(
"Unable to create mimic_folder directory" << mimic_folder.string());
349 catch(fs::filesystem_error
const & e)
355 for(fs::directory_iterator file(source); file != fs::directory_iterator(); ++file)
359 fs::path current(file->path());
360 if(fs::is_directory(current))
363 if( !
copy_dir(current, mimic_folder / current.filename()) )
369 fs::copy_file(current, mimic_folder / current.filename() );
372 catch(fs::filesystem_error
const & e)
391 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"Mimic running");
399 int main(
int argc,
char** argv)