ALEXA ROS VOICE COMMAND TURTLEBOT












1















I have been able to integrated alexa to ROS, and in general terms it works, the problem is that when I send a command to alexa and it publishes a topic, turtlebot keeps listening to it, and for example, when I say forward, that is not a big deal because I can simply tell turtlebot to stop, but I find it kind of a problem when I say turn left or turn right, because it keeps going left or right, I am not sure how to solve this.



Type of messages I am publishing= geometry messages/ twist



My ideas:



1- Create a subscriber that subscribes just for a certain time then close and subscribes when a new command is publish.



Disadvantage: To go forward would required a longer time than going for the sides, so maybe would not solve the problem



2- Create a subscriber that subscribes gets only one message closes and subscribes when a new message is publish.



Disadvantage: to go forward just one time, would not solve this problems but would just create the exact opposite problem



I saw that for the second case I can use this but I am not sure how to.



  ros::topic::waitForMessage(..)


The code I have for the subscriber at the moment is this.



#include <ros/ros.h>
#include <geometry_msgs/Twist.h>

void cmd_vel_callback(const geometry_msgs::Twist& vel_cmd)
{
ROS_INFO("I heard: [%f]", vel_cmd.linear.y);
std::cout << "Twist Received " << std::endl;
}


int main( int argc, char* argv )
{
ros::init(argc, argv, "turtl" );

ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/cmd_vel", 1000, cmd_vel_callback);

while( n.ok() )
{
ros::spin();
}

return 1;
}









share|improve this question



























    1















    I have been able to integrated alexa to ROS, and in general terms it works, the problem is that when I send a command to alexa and it publishes a topic, turtlebot keeps listening to it, and for example, when I say forward, that is not a big deal because I can simply tell turtlebot to stop, but I find it kind of a problem when I say turn left or turn right, because it keeps going left or right, I am not sure how to solve this.



    Type of messages I am publishing= geometry messages/ twist



    My ideas:



    1- Create a subscriber that subscribes just for a certain time then close and subscribes when a new command is publish.



    Disadvantage: To go forward would required a longer time than going for the sides, so maybe would not solve the problem



    2- Create a subscriber that subscribes gets only one message closes and subscribes when a new message is publish.



    Disadvantage: to go forward just one time, would not solve this problems but would just create the exact opposite problem



    I saw that for the second case I can use this but I am not sure how to.



      ros::topic::waitForMessage(..)


    The code I have for the subscriber at the moment is this.



    #include <ros/ros.h>
    #include <geometry_msgs/Twist.h>

    void cmd_vel_callback(const geometry_msgs::Twist& vel_cmd)
    {
    ROS_INFO("I heard: [%f]", vel_cmd.linear.y);
    std::cout << "Twist Received " << std::endl;
    }


    int main( int argc, char* argv )
    {
    ros::init(argc, argv, "turtl" );

    ros::NodeHandle n;
    ros::Subscriber sub = n.subscribe("/cmd_vel", 1000, cmd_vel_callback);

    while( n.ok() )
    {
    ros::spin();
    }

    return 1;
    }









    share|improve this question

























      1












      1








      1


      1






      I have been able to integrated alexa to ROS, and in general terms it works, the problem is that when I send a command to alexa and it publishes a topic, turtlebot keeps listening to it, and for example, when I say forward, that is not a big deal because I can simply tell turtlebot to stop, but I find it kind of a problem when I say turn left or turn right, because it keeps going left or right, I am not sure how to solve this.



      Type of messages I am publishing= geometry messages/ twist



      My ideas:



      1- Create a subscriber that subscribes just for a certain time then close and subscribes when a new command is publish.



      Disadvantage: To go forward would required a longer time than going for the sides, so maybe would not solve the problem



      2- Create a subscriber that subscribes gets only one message closes and subscribes when a new message is publish.



      Disadvantage: to go forward just one time, would not solve this problems but would just create the exact opposite problem



      I saw that for the second case I can use this but I am not sure how to.



        ros::topic::waitForMessage(..)


      The code I have for the subscriber at the moment is this.



      #include <ros/ros.h>
      #include <geometry_msgs/Twist.h>

      void cmd_vel_callback(const geometry_msgs::Twist& vel_cmd)
      {
      ROS_INFO("I heard: [%f]", vel_cmd.linear.y);
      std::cout << "Twist Received " << std::endl;
      }


      int main( int argc, char* argv )
      {
      ros::init(argc, argv, "turtl" );

      ros::NodeHandle n;
      ros::Subscriber sub = n.subscribe("/cmd_vel", 1000, cmd_vel_callback);

      while( n.ok() )
      {
      ros::spin();
      }

      return 1;
      }









      share|improve this question














      I have been able to integrated alexa to ROS, and in general terms it works, the problem is that when I send a command to alexa and it publishes a topic, turtlebot keeps listening to it, and for example, when I say forward, that is not a big deal because I can simply tell turtlebot to stop, but I find it kind of a problem when I say turn left or turn right, because it keeps going left or right, I am not sure how to solve this.



      Type of messages I am publishing= geometry messages/ twist



      My ideas:



      1- Create a subscriber that subscribes just for a certain time then close and subscribes when a new command is publish.



      Disadvantage: To go forward would required a longer time than going for the sides, so maybe would not solve the problem



      2- Create a subscriber that subscribes gets only one message closes and subscribes when a new message is publish.



      Disadvantage: to go forward just one time, would not solve this problems but would just create the exact opposite problem



      I saw that for the second case I can use this but I am not sure how to.



        ros::topic::waitForMessage(..)


      The code I have for the subscriber at the moment is this.



      #include <ros/ros.h>
      #include <geometry_msgs/Twist.h>

      void cmd_vel_callback(const geometry_msgs::Twist& vel_cmd)
      {
      ROS_INFO("I heard: [%f]", vel_cmd.linear.y);
      std::cout << "Twist Received " << std::endl;
      }


      int main( int argc, char* argv )
      {
      ros::init(argc, argv, "turtl" );

      ros::NodeHandle n;
      ros::Subscriber sub = n.subscribe("/cmd_vel", 1000, cmd_vel_callback);

      while( n.ok() )
      {
      ros::spin();
      }

      return 1;
      }






      alexa ros voice






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 13:02









      강천사강천사

      64




      64
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Your problem is you cannot just stop subscribing and subscribe again which is not optimal.



          there's 2 way you can do this :




          1. you can remove ros::spin() and use ros::spinOnce() ask subscriber to get new data after your previous task is done (You said for forward moving it takes longer and for sides takes shorter) you can call it after you can verify the task is done anywhere in the code.


          2. get output from subscriber and store it inside another variable and add another control function inside your while(n.ok()) to act on the previous data or to change to new data came from subscriber.







          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300885%2falexa-ros-voice-command-turtlebot%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Your problem is you cannot just stop subscribing and subscribe again which is not optimal.



            there's 2 way you can do this :




            1. you can remove ros::spin() and use ros::spinOnce() ask subscriber to get new data after your previous task is done (You said for forward moving it takes longer and for sides takes shorter) you can call it after you can verify the task is done anywhere in the code.


            2. get output from subscriber and store it inside another variable and add another control function inside your while(n.ok()) to act on the previous data or to change to new data came from subscriber.







            share|improve this answer




























              0














              Your problem is you cannot just stop subscribing and subscribe again which is not optimal.



              there's 2 way you can do this :




              1. you can remove ros::spin() and use ros::spinOnce() ask subscriber to get new data after your previous task is done (You said for forward moving it takes longer and for sides takes shorter) you can call it after you can verify the task is done anywhere in the code.


              2. get output from subscriber and store it inside another variable and add another control function inside your while(n.ok()) to act on the previous data or to change to new data came from subscriber.







              share|improve this answer


























                0












                0








                0







                Your problem is you cannot just stop subscribing and subscribe again which is not optimal.



                there's 2 way you can do this :




                1. you can remove ros::spin() and use ros::spinOnce() ask subscriber to get new data after your previous task is done (You said for forward moving it takes longer and for sides takes shorter) you can call it after you can verify the task is done anywhere in the code.


                2. get output from subscriber and store it inside another variable and add another control function inside your while(n.ok()) to act on the previous data or to change to new data came from subscriber.







                share|improve this answer













                Your problem is you cannot just stop subscribing and subscribe again which is not optimal.



                there's 2 way you can do this :




                1. you can remove ros::spin() and use ros::spinOnce() ask subscriber to get new data after your previous task is done (You said for forward moving it takes longer and for sides takes shorter) you can call it after you can verify the task is done anywhere in the code.


                2. get output from subscriber and store it inside another variable and add another control function inside your while(n.ok()) to act on the previous data or to change to new data came from subscriber.








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 15:53









                Mohammad AliMohammad Ali

                355210




                355210
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300885%2falexa-ros-voice-command-turtlebot%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine