user10011764
user10011764

Reputation:

Troubles to move turtlebot_gazebo

I started a small project where I wanted to move the turtlebot in gazebo. I launched: roslaunch turtlebot_gazebo turtlebot_world.launch

I wrote a code to move it:

#include "ros/ros.h" 
#include "geometry_msgs/TwistWithCovariance.h" 
#include "nav_msgs/Odometry.h" 
#include "gazebo_msgs/LinkState.h" 
#include "geometry_msgs/Twist.h"

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

ros::init(argc,argv,"move");
ros::NodeHandle n;
ros::Publisher move_pub = n.advertise<geometry_msgs::Twist>("moving",1000);
ros::Rate loop_rate(10);

geometry_msgs::Twist msg;
while(ros::ok()){
    msg.linear.x = 0.0;
    msg.linear.y = 0.0;
    msg.linear.z = 20.0;
    move_pub.publish(msg);

    ros::spinOnce();

    loop_rate.sleep();

    }

}

This doesn't work. As you can see i included other msgs and tried it with them but I got the same result. I also tried to find the node turtlebot_teleop_keyboard to find out how it is done by inputs. But i couldn't find the path to it. So what do I have to do to move it? And how can I find the path to the node?

Upvotes: 0

Views: 1217

Answers (2)

unlut
unlut

Reputation: 3775

You are publishing to wrong topic, and wrong parameters.

1- After launching your turtlebot, type "rostopic list" from another terminal and look for topics that contain cmd_vel or cmd_vel_mux. If there is not cmd_vel_mux just publish cmd_vel, otherwise publish one of cmd_vel_mux/input.

2- For Turtlebot's linear movement, only x has any effect.

Example node in my ros-kinetic:

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

    ros::init(argc,argv,"move");
    ros::NodeHandle n;
    ros::Publisher move_pub = n.advertise<geometry_msgs::Twist>("/cmd_vel_mux/input/navi",1000);
    ros::Rate loop_rate(10);

    geometry_msgs::Twist msg;
    while(ros::ok())
    {
        //  linear velocity
        msg.linear.x = 1.0;
        msg.linear.y = 0.0;
        msg.linear.z = 0.0;

        //  angular velocity
        msg.angular.x = 0.0;
        msg.angular.y = 0.0;
        msg.angular.z = 0.0;

        move_pub.publish(msg);

        ros::spinOnce();

        loop_rate.sleep();
    }

}

Upvotes: 2

akshayk07
akshayk07

Reputation: 2200

For Turtlebot, you have topics to publish linear velocities - x, y and z and also angular velocities - x, y and z. What you need to understand is what each of these physically mean.

Linear velocity in x will make it move forward.

Angular velocity in z will make it turn about itself.

Other parameters don't do anything. So, in your code, using the above 2 parameters will move the bot. Rest of the parameters won't affect the bot in any way.

Upvotes: 0

Related Questions