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

Revision history [back]

click to hide/show revision 1
initial version

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);

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

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.

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

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