0
$\begingroup$

Rosanswers logo

Hi, I am new to ROS, using ROS Indigo on Ubuntu 14.04. After coding the basic tutorial http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29, I am trying to control the turtle by sending the commands to turtlesim/Pose.

I program the code, CMakeLists.txt, and package.xml properly, and the catkin_make works properly. However, the turtle does not move, and there is no link between /publish_pose node (my publishing node) and /turtlesim node by executing rosrun rqt_graph rqt_graph as follows.

image description

My code of the publishing node is listed below.

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>  // For geometry_msgs::Twist
#include <turtlesim/Pose.h> // rostopic type /turtle1/pose
#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_pose");
  ros::NodeHandle nh;

  // Create a publisher object.
  ros::Publisher pub = nh.advertise<turtlesim::Pose>(
    "/turtle1/pose", 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.  The other four
    // fields, which are ignored by turtlesim, default to 0.
    turtlesim::Pose msg;
    msg.x = float(rand())/float(RAND_MAX);
    msg.y = float(rand())/float(RAND_MAX);
    msg.theta = 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 pose command:"<<" x=" << msg.x<<" y=" << msg.y<<" theta=" << msg.theta);

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

Originally posted by pinocchio on ROS Answers with karma: 101 on 2015-11-02

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Short answer: no you cannot not (at least not using that topic).


Longer: as you can see on wiki/turtlesim - Nodes - turtlesim_node - Subscribed Topics, the turtleX/pose topic is only published to by the turtlesim_node node, so no incoming messages will be expected there (it is only an output). The only subscription is a turtleX/cmd_vel (geometry_msgs/Twist) topic, which is the only way to make the turtle move in the normal manner.

To place the turtle at a certain position without it having to travel there, you should use the turtleX/teleport_* services.


Originally posted by gvdhoorn with karma: 86574 on 2015-11-02

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by pinocchio on 2015-11-02:
thx. will try that.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.