0

example1_a.cpp

include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
int main(int argc, char **argv)
{
  ros::init(argc, argv, "example1_a");
  ros::NodeHandle n;
  ros::Publisher pub = n.advertise<std_msgs::String>("message", 1000);
  ros::Rate loop_rate(10);
  while (ros::ok())
  {
    std_msgs::String msg;
    std::stringstream ss;
    ss << " I am the example1_a node ";
    msg.data = ss.str();
    //ROS_INFO("%s", msg.data.c_str());
    pub.publish(msg);
    ros::spinOnce();
    loop_rate.sleep();
  }
  return 0;
}

示例1_b.cpp

#include "ros/ros.h"
#include "std_msgs/String.h"

void messageCallback(const std_msgs::String::ConstPtr& msg)
{
  ROS_INFO("I heard: [%s]", msg->data.c_str());
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "example1_b");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subscribe("message", 1000, messageCallback);
  ros::spin();
  return 0;
}

catkin_make 时出错–-pkg chapter2_tutorials

#### Running command: "make cmake_check_build_system" in "/home/ros/catkin_ws/build"
####
####
#### Running command: "make –-pkg chapter2_tutorials -j1 -l1" in "/home/ros/catkin_ws/build"
####
make: *** No rule to make target '–-pkg'.  Stop.
Invoking "make –-pkg chapter2_tutorials -j1 -l1" failed

$ export | grep ROS

ros@ubuntu:~/catkin_ws$ export | grep ROS
declare -x ROSLISP_PACKAGE_DIRECTORIES="/home/ros/catkin_ws/devel/share/common-lisp"
declare -x ROS_DISTRO="kinetic"
declare -x ROS_ETC_DIR="/opt/ros/kinetic/etc/ros"
declare -x ROS_MASTER_URI="http://localhost:11311"
declare -x ROS_PACKAGE_PATH="/home/ros/catkin_ws/src:/opt/ros/kinetic/share"
declare -x ROS_ROOT="/opt/ros/kinetic/share/ros"

谢谢!

4

2 回答 2

0

只需运行catkin_make而不是make

$ catkin_make –-pkg chapter2_tutorials -j1 -l1
于 2017-02-20T09:08:21.147 回答
0

你看过 ROS.org 的教程吗?它们是极好的资源。 http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment

--pkg您应该通过删除标志来获得所需的结果。尝试运行catkin_make chapter2_tutorials

于 2017-02-19T17:05:31.047 回答