ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Topic not being created properly

asked 2014-06-06 12:32:05 -0500

choog gravatar image

updated 2014-06-06 12:33:10 -0500

Hello, I am using ROS groovy and I have created a .cpp file that is suppose to use the command_velocity topic in conjunction with ros turtlesim to move the simulated turtlebot in a direction, When I compiled my code everything went fine with catkin_make. Now that I run my code though it seems like the command_velocity topic is not being created or anything is being published at all.

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
int main(int argc, char **argv){
ros::init(argc, argv, "move");
ros::NodeHandle n;
ros::Publisher move_bot = n.advertise<geometry_msgs::Twist>("cmd_vel_mux/input/teleop",1);
geometry_msgs::Twist vel;
vel.angular.z = 1.5;
vel.linear.x = 1.5;
move_bot.publish(vel);

ros::spin();
return 0;
 }

I am not sure what the problem is and I am fairly new to ROS programming any insight would be appreciated, thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-06-06 13:16:10 -0500

Hamid Didari gravatar image

updated 2014-06-06 13:31:00 -0500

turtlesim_node subscribe from /turtle1/command_velocity in ros groovy change:

ros::Publisher move_bot = n.advertise<geometry_msgs::Twist>("cmd_vel_mux/input/teleop",1);

to

ros::Publisher move_bot = n.advertise<geometry_msgs::Twist>("/turtle1/command_velocity",1);

and also in ros groovy use turtlesim/Velocity not geometry_msgs/Twist. geometry_msgs/Twist use in hydro.

this a simple code that send randomly-generated velocity commands to a turtlesim turtle

#include <ros/ros.h>
#include <turtlesim/Velocity.h>  // For turtlesim::Velocity
#include <stdlib.h> // For rand() and RAND_MAX

int main(int argc, char **argv) {
  // Initialize the ROS system and become a node.
  ros::init(argc, argv, "publish_velocity");
  ros::NodeHandle nh;

  // Create a publisher object.
  ros::Publisher pub = nh.advertise<turtlesim::Velocity>(
    "turtle1/command_velocity", 1000);

  // Seed the random number generator.
  srand(time(0));

  // Loop at 2Hz until the node is shut down.
  ros::Rate rate(2);
  while(ros::ok()) {
    // Create and fill in the message.
    turtlesim::Velocity msg;
    msg.linear = float(rand())/float(RAND_MAX);
    msg.angular = 2*float(rand())/float(RAND_MAX) - 1;

    // Publish the message.
    pub.publish(msg);

    // Send a message to rosout with the details.
    ROS_INFO_STREAM("Sending random velocity command:"
      << " linear=" << msg.linear
      << " angular=" << msg.angular);

    // Wait until it's time for another iteration.
    rate.sleep();
  }
}

also yo can use this command if you want publish one msg in one topic:

$rostopic pub /turtle1/command_velocity turtlesim/Velocity -r 1 -- 2.0  0.0
edit flag offensive delete link more

Comments

What if I wanted to publish to the topic that the actualy turtlebot uses? I wouldn't use ros::Publisher move_bot = n.advertise<geometry_msgs::twist>("/turtle1/command_velocity",1); right?

choog gravatar image choog  ( 2014-06-06 13:49:11 -0500 )edit

in ros groovy the turtlebot uses turtlesim::Velocity msg you can use this move_bot = n.advertise<turtlesim::velocity>("/turtle1/command_velocity",1);

Hamid Didari gravatar image Hamid Didari  ( 2014-06-06 14:15:15 -0500 )edit

It works fine in the simulator. Now I was trying to get the actual turtlebot to follow the path. But its not working. I also changed the time from 2 heartz to .5 heartz to see if the robot would recognize the command. But I'm not understanding if turtlebot actually uses the same topic for messages?

choog gravatar image choog  ( 2014-06-06 15:37:39 -0500 )edit

please type this "$roslaunch turtlebot_teleop keyboard_teleop.launch" in your terminal . could you move your robot with key presses?

Hamid Didari gravatar image Hamid Didari  ( 2014-06-07 02:12:46 -0500 )edit

Yes it does. I was able to open up the code for the keyboard_teleop.cpp file and it seems like its publishing the messages on cmd_vel topic. I just have to figure out how to tie it all in together. Thank you for your help

choog gravatar image choog  ( 2014-06-07 21:45:01 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-06-06 12:32:05 -0500

Seen: 542 times

Last updated: Jun 06 '14