Browse Source

调试好可以使用按钮和唤醒词同时触发

corvin 5 years ago
parent
commit
fa285dcbfc

+ 1 - 0
catkin_ws/src/snowboy_wakeup/CMakeLists.txt

@@ -68,6 +68,7 @@ target_link_libraries(hotword_detector
     ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/snowboy/lib/libsnowboy-detect.a
     ${catkin_LIBRARIES}
     ${BLAS_LIBRARIES}
+    -lwringPi
 )
 
 add_executable(hotword_detector_node

+ 21 - 2
catkin_ws/src/snowboy_wakeup/src/hotword_detector_node.cpp

@@ -4,13 +4,17 @@
 #include <audio_common_msgs/AudioData.h>
 #include <dynamic_reconfigure/server.h>
 #include <hotword_detector.h>
+#include <wiringPi.h>
 
+#define BTN_PIN 27
+volatile char btn_click = 0;
 
 namespace snowboy_wakeup
 {
     std::string beep_filename;
     std::string pre_param = "play -q --multi-threaded ";
     std::string all_param;
+
     //!
     //! \brief The HotwordDetectorNode class Wraps the C++ 11 Snowboy detector in a ROS node
     //!
@@ -22,6 +26,7 @@ namespace snowboy_wakeup
 
             bool initialize()
             {
+
                 std::string resource_filename;
                 if (!nh_p_.getParam("resource_filename", resource_filename))
                 {
@@ -86,6 +91,7 @@ namespace snowboy_wakeup
             //!
             HotwordDetector detector_;
 
+
             //!
             //! \brief reconfigureCallback Reconfigure update for sensitiviy and audio level
             //! \param cfg The updated config
@@ -96,6 +102,7 @@ namespace snowboy_wakeup
                 ROS_INFO("SnowboyROS (Re)Configured");
             }
 
+
             //!
             //! \brief audioCallback Audio stream callback
             //! \param msg The audo data
@@ -117,10 +124,11 @@ namespace snowboy_wakeup
 
                     std_msgs::Int32 hotword_msg;
                     int result = detector_.runDetection( &sample_array[0], msg->data.size()/2);
-                    if (result == 1)
+                    if (result == 1 || btn_click == 1)
                     {
+                        btn_click = 0;
                         ROS_DEBUG("wakeUp detected!");
-                        hotword_msg.data = result;
+                        hotword_msg.data = 1;
                         hotword_pub_.publish(hotword_msg);
                         system(all_param.data());
                     }
@@ -138,11 +146,22 @@ namespace snowboy_wakeup
 
 }
 
+//click btn ISR function
+void btnISR()
+{
+    btn_click = 1;
+}
+
 int main(int argc, char** argv)
 {
     ros::init(argc, argv, "snowboy_wakeup_node");
     snowboy_wakeup::HotwordDetectorNode ros_hotword_detector_node;
 
+    wiringPiSetup();
+    pinMode(BTN_PIN, INPUT);
+    pullUpDnControl(BTN_PIN, PUD_UP);
+    wiringPiISR(BTN_PIN, INT_EDGE_RISING, &btnISR);
+
     if (ros_hotword_detector_node.initialize())
     {
         ros::spin();