简体   繁体   English

在ROS中如何发布自己的主题?

[英]In ROS how to publish my own topic?

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 remind me that 我是ROS的初学者。我的操作系统是Ubuntu 12.04,我的ROS是Hydro。在阅读了ROS.wiki的“初学者教程”中有关“讲者和听者”的某些章节之后,我尝试写一个发布者来向主题“ turtle1 / com_vel”,以便我可以控制Turtle运行。但是当我尝试编写代码时,它失败了。终端提醒我

  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. 我猜我的CMakeLists.txt出了点问题,但是与ROS.wiki中的演示比较后,我仍然找不到错误。 This is my code in cpp file.In this file,I define a publisher named move_turtle. 这是我在cpp文件中的代码。在此文件中,我定义了一个名为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: 而我的CMakeLists.txt如下:

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

哦...我在'CMakeLists.txt'的第5行中使用'ros'而不是'roscpp',这就是为什么它提醒我在我的路径中没有'ros'软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM