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

How to publish my own msgs to topic?

asked 2013-11-21 13:42:30 -0500

xmfbit gravatar image

I am a beginner in ROS.My operation system is Ubuntu 12.04 and my ROS is hydro.After I read some chapters about the "talker and listener" of The Beginner Tutorials in ROS.wiki,I try to write a publisher to publish message to topic "turtle1/com_vel" so that I can control the turtle to run round.But when I try to make my code,it fails.The terminal reminds me that

  CMake Error at /opt/ros/hydro/share/catkin/cmake/catkinConfig.cmake:72 (find_package):
  Could not find a configuration file for package ros.

  Set ros_DIR to the directory containing a CMake configuration file for ros.
  The file will have one of the following names:

    rosConfig.cmake
    ros-config.cmake

I guess that there is something wrong with my CMakeLists.txt.But after comparing it with the demo in ROS.wiki,I still can't find the error. This is my code in cpp file.In this file,I define a publisher named move_turtle.


 #include "ros/ros.h"
 #include "geometry_msgs/Twist.h"
int main( int argc, char** argv )
{
  // initialization
  ros::init(argc, argv, "move_turtle");
  ros::NodeHandle n;
  ros::Publisher move_pub = n.advertise<geometry_msgs::twist>("turtle1/com_vel",100);
  ros::Rate loop_rate(10);
  //define the moving rule that I want.It is a circle.
  geometry_msgs::Twist com_cicle;
  com_cicle.linear.x=3.0;
  com_cicle.linear.y=com_cicle.linear.z=0.0;
  com_cicle.angular.x=com_cicle.angular.y=0.0;
  com_cicle.angular.z=2.0;
  while(ros::ok())
  {
    //publish the msg to topic /tuttle1/com_vel
    move_pub.pulish(com_cicle);
    ros::spinOnce();
    loop_rate.sleep();
  }
  return 0;
}
And my CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 2.8.3)
project(move_turtle)

find_package(catkin REQUIRED COMPONENTS ros geometry_msgs turtlesim )

catkin_package() include_directories( ${catkin_INCLUDE_DIRS} ) ## Declare a cpp executable add_executable(move_turtle src/move_turtle.cpp) ## Specify libraries to link a library or executable target against target_link_libraries(move_turtle ${catkin_LIBRARIES})

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-11-21 14:02:55 -0500

lindzey gravatar image

replace ros with roscpp in your CMakeLists.txt

edit flag offensive delete link more

Comments

Thanks a lot!I didn't notice that!And I will remember this from now on!

xmfbit gravatar image xmfbit  ( 2013-11-21 23:26:46 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2013-11-21 13:42:30 -0500

Seen: 210 times

Last updated: Nov 21 '13