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.
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