ROS入门——胡春旭老师《机器人开发实践》在ROS-Melodic下的编译

入门ROS系统,网上接触到的资料大部分都跟古月有关,故买来胡春旭老师(古月)的书籍《机器人开发实践》拜读。书中对仿真以及真实机器人同步做介绍,能一步一步跟着操作下来,非常适合入门。但由于书中提供的仓库源码是基于Kinetic版本的,而我的现有系统是Melodic版本,所以在编译源码中遇到很多问题,幸运的是踩在前辈们的肩膀上,问题都一一解决,现回忆记录如下,供后来者参考。

1.创建工作空间catkin_guyue1

mkdir -p ~/catkin_guyue1/src
cd ~/catkin_guyue1/src
catkin_init_workspace
cd ~/catkin_guyue1
catkin_make
  1. 源码下载
cd ~/catkin_guyue1/src
git clone https://github.com/huchunxu/ros_exploring.git

注意:需要将其中的ros2文件夹移出到其他目录(工作空间以外 ,或者删除),否则编译失败。

  1. 源码编译
cd ~/catkin_guyue1
catkin_make

错误1:关于ECTO的报错
ROS入门——胡春旭老师《机器人开发实践》在ROS-Melodic下的编译_第1张图片
解决方法:
(1)下载ecto源码

cd ~/catkin_guyue1/src
git clone http://github.com/plasmodic/ecto.git
catkin_make -DCATKIN_WHITELIST_PACKAGES="ecto"

(2)安装依赖

$ sudo apt-get install libboost-python-dev libboost-filesystem-dev libboost-system-dev \
        libboost-thread-dev python-setuptools python-gobject python-gtk2 graphviz doxygen \
        python-sphinx

(3)直接编译将报错,修改ecto下的源码
修改两个文件:网盘上传文件失败,在此粘贴文件内容,可覆盖原路径下的相应文件。

文件一: ~/catkin_guyue1/src/ecto/src/lib/util.cpp :

// 
// Copyright (c) 2011, Willow Garage, Inc.
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Willow Garage, Inc. nor the names of its
//       contributors may be used to endorse or promote products derived from
//       this software without specific prior written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
#include 
#include 
#include 
#include 
#include 
#if !defined(_WIN32)
#include 
#endif
#include 
#include 
#include 
#include 
#include 
#include 

#if defined(_WIN32)
// #define UNDNAME_COMPLETE                 (0x0000)
// #define UNDNAME_NO_LEADING_UNDERSCORES   (0x0001) /* Don't show __ in calling convention */
// #define UNDNAME_NO_MS_KEYWORDS           (0x0002) /* Don't show calling convention at all */
// #define UNDNAME_NO_FUNCTION_RETURNS      (0x0004) /* Don't show function/method return value */
// #define UNDNAME_NO_ALLOCATION_MODEL      (0x0008)
// #define UNDNAME_NO_ALLOCATION_LANGUAGE   (0x0010)
// #define UNDNAME_NO_MS_THISTYPE           (0x0020)
// #define UNDNAME_NO_CV_THISTYPE           (0x0040)
// #define UNDNAME_NO_THISTYPE              (0x0060)
// #define UNDNAME_NO_ACCESS_SPECIFIERS     (0x0080) /* Don't show access specifier (public/protected/private) */
// #define UNDNAME_NO_THROW_SIGNATURES      (0x0100)
// #define UNDNAME_NO_MEMBER_TYPE           (0x0200) /* Don't show static/virtual specifier */
// #define UNDNAME_NO_RETURN_UDT_MODEL      (0x0400)
// #define UNDNAME_32_BIT_DECODE            (0x0800)
// #define UNDNAME_NAME_ONLY                (0x1000) /* Only report the variable/method name */
// #define UNDNAME_NO_ARGUMENTS             (0x2000) /* Don't show method arguments */
// #define UNDNAME_NO_SPECIAL_SYMS          (0x4000)
// #define UNDNAME_NO_COMPLEX_TYPE          (0x8000)

// extern "C"
// char * _unDName(
// char * outputString,
// const char * name,
// int maxStringLength,
// void * (* pAlloc )(size_t),
// void (* pFree )(void *),
// unsigned short disableFlags);
// _unDName(0, pName, 0, malloc, free, UNDNAME_NO_ARGUMENTS | UNDNAME_32_BIT_DECODE);

namespace abi
{
  char* __cxa_demangle(const char * const pName,...)
  {
    char * name = new char[std::strlen(pName)];
    std::strcpy(name,pName);
    return name;
  }
}
#endif

namespace ecto
{
  using namespace ecto::except;

  class type_mapping
  {
  public:
    const std::string&
    lookup(const std::type_info& ti)
    {
      const char* mangled = ti.name();
      if (!mangled)
        {
          BOOST_THROW_EXCEPTION(EctoException()
                                << diag_msg("Could get a type name for your type! The world must be ending."));
        }
      return lookup(mangled);
    }

    const std::string&
    lookup(std::string mangled)
    {
      if (mangled == typeid(mangled).name())
        mangled = "std::string";

      dict_t::iterator iter = m.find(mangled);
      if (iter != m.end())
        return iter->second;

      std::string& rv = m[mangled];

      int status=0;
      char* demangled = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status);
      if (status != 0)
        rv = mangled;
      else
        rv = demangled;
      free(demangled);
      return rv;
    }

    static type_mapping& instance() {
      static type_mapping m;
      return m;
    }

  private:
    type_mapping() { }
    
    typedef boost::unordered_map<std::string, std::string> dict_t;
    dict_t m;
  };

  const std::string& name_of(const std::type_info &ti)
  {
    return type_mapping::instance().lookup(ti);
  }
  const std::string& name_of(const std::string &s)
  {
    return type_mapping::instance().lookup(s);
  }

  template<>
  const std::string& name_of<std::string>()
  {
    static const std::string& name_cache = "std::string";
    return name_cache;
  }

  std::string
  symbolic_name_of(const std::string& t_name)
  {
    std::string result = t_name;
    boost::replace_all(result, " ", "_");
    boost::replace_all(result, "<", "_");
    boost::replace_all(result, ">", "_");
    boost::replace_all(result, "::", "_");
    return result;
  }

  template<>
  const std::string& symbolic_name_of<std::string>()
  {
    static const std::string name_cache = symbolic_name_of("std::string");
    return name_cache;
  }
}

文件二:~/catkin_guyue1/src/ecto/src/lib/plasm/impl.hpp

/*
 * Copyright (c) 2011, Willow Garage, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the Willow Garage, Inc. nor the names of its
 *       contributors may be used to endorse or promote products derived from
 *       this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
#pragma once

#include 
#include 

#include 

namespace ecto {

  struct plasm::impl
  {
    impl();

    //insert a cell into the graph, will retrieve the
    //vertex descriptor if its already in the graph...
    graph::graph_t::vertex_descriptor insert_module(cell_ptr m);

    void connect(cell_ptr from, std::string output, cell_ptr to, std::string input);

    void disconnect(cell_ptr from, std::string output, cell_ptr to, std::string input);

    //the cell to vertex mapping
    //unordered_map so that cell ptr works as a key...
    typedef boost::unordered_map<cell_ptr, graph::graph_t::vertex_descriptor> ModuleVertexMap;
    ModuleVertexMap mv_map;
    graph::graph_t graph;

  };
}

接着,单独编译ecto:

cd ~/catkin_guyue1
catkin_make -DCATKIN_WHITELIST_PACKAGES="ecto"

(4)我自己的环境是以上步骤即可成功安装ecto,但部分博客提到还有其他错误,可以参考这个博客。

错误2:缺少 manipulation-msgs
解决方法:见招拆招

cd ~/catkin_guyue1/src
git clone https://github.com/ros-interactive-manipulation/manipulation_msgs.git
cd ~/catkin_guyue1
catkin_make -DCATKIN_WHITELIST_PACKAGES="manipulation_msgs"

可能报错:
ROS入门——胡春旭老师《机器人开发实践》在ROS-Melodic下的编译_第2张图片
解决办法:

cd ~/catkin_guyue1/src
git clone https://github.com/ros-interactive-manipulation/household_objects_database
cd ~/catkin_guyue1
wz@ubuntu:~/catkin_guyue1$ catkin_make -DCATKIN_WHITELIST_PACKAGES="household_objects_database_msgs"

可能继续报错:
ROS入门——胡春旭老师《机器人开发实践》在ROS-Melodic下的编译_第3张图片
解决办法:

cd ~/catkin_guyue1/src
git clone https://github.com/wg-perception/object_recognition_msgs.git 
cd ~/catkin_guyue1
catkin_make -DCATKIN_WHITELIST_PACKAGES="object_recognition_msgs"

成功编译,接着分别执行上述失败的编译语句:

catkin_make -DCATKIN_WHITELIST_PACKAGES="household_objects_database_msgs"
catkin_make -DCATKIN_WHITELIST_PACKAGES="manipulation_msgs"
catkin_make

至此,胡春旭老师《机器人开发实践》的源码在ROS-Melodic系统下编译完成。有问题,欢迎私信。

你可能感兴趣的:(机器视觉,ubuntu,自动驾驶)