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的报错
关于ECTO的报错
解决方法:
(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 <vector>
#include <iostream>
#include <boost/unordered_map.hpp>
#include <ecto/util.hpp>
#include <ecto/except.hpp>
#if !defined(_WIN32)
#include <cxxabi.h>
#endif
#include <string>
#include <stdlib.h>
#include <cstring>
#include <map>
#include <boost/tuple/tuple.hpp>
#include <boost/algorithm/string/replace.hpp>

#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 <ecto/plasm.hpp>
#include <boost/unordered_map.hpp>

#include <ecto/graph/types.hpp>

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"

可能报错:
在这里插入图片描述
解决办法:

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"

可能继续报错:
在这里插入图片描述
解决办法:

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系统下编译完成。有问题,欢迎私信。

  • 9
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
古月居ROS入门21课笔记主要涵盖了ROS的安装和基本使用方法,以下是我的总结: 1. 安装ROS:首先要安装ROS操作系统,根据教程可以选择安装适合自己系统的版本,如ROS Kinetic或ROS Melodic等。 2. 创建工作空间:使用catkin工具创建ROS工作空间,可以将所有的ROS相关文件放在这个空间中。 3. 创建包:在工作空间内创建一个ROS包,这个包是ROS项目的基本单元。可以使用catkin_create_pkg命令来创建包,并指定包的依赖项。 4. 编写节点代码:节点是ROS中最基本的执行单元,可以通过编写节点来实现各种功能。可以使用C++或Python编写节点代码。 5. 编译代码:使用catkin_make命令编译ROS代码,编译后会生成可执行文件。编译成功后,可以在工作空间中的bin目录下找到生成的可执行文件。 6. 运行节点:使用rosrun命令来运行编译好的节点。节点运行后会执行相应的功能。 7. 使用消息通信:ROS中的节点通过发布和订阅消息来进行通信。可以编写发布节点和订阅节点代码,通过话题的方式进行消息传递。 8. 使用服务通信:除了消息通信,ROS还提供了服务通信的机制。可以编写服务端和客户端代码,进行服务调用和响应。 9. 使用参数服务器:ROS提供了参数服务器来存储和共享参数。可以将特定的参数存储在参数服务器上,并在节点中进行访问和修改。 10. 使用RViz可视化:RViz是ROS环境下的可视化工具,可以将机器人模型和传感器数据等进行可视化展示,方便调试和分析。 通过学习古月居ROS入门21课,我对ROS的基本使用方法和常用功能有了初步了解。在实践中,我将进一步深入学习和应用ROS,提高自己在机器人开发和控制方面的能力。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值