系统ubuntu20.04-ROS2源码安装humble

翻译参考:https://docs.ros.org/en/humble/Installation/Alternatives/Ubuntu-Development-Setup.html

系统要求

Humble Hawksbill目前基于Debian的目标平台是

  • Tier 1: Ubuntu Linux - Jammy (22.04) 64-bit

  • Tier 3: Ubuntu Linux - Focal (20.04) 64-bit
  • Debian Linux - Bullseye (11) 64-bit

其他具有不同支持级别的Linux平台包括:

Arch Linux, see alternate instructions
Fedora Linux, see alternate instructions
OpenEmbedded / webOS OSE, see alternate instructions

As defined in REP 2000.

一. 系统设置

1.1区域设置

请确保您的区域设置支持UTF-8,如果您处于一个最小的环境(例如docker容器)中,那么区域设置可能是像POSIX这样的最小环境。我们使用以下设置进行测试。但是,如果您使用的是不同的UTF-8支持的区域设置,则应该可以。

locale  # check for UTF-8

sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

locale  # verify settings

添加ROS 2 apt仓库

您需要将ROS2 apt存储库添加到您的系统中

首先确保Ubuntu Universe存储库已启用。

sudo apt install software-properties-common
sudo add-apt-repository universe

现在添加带有apt的ROS 2 GPG密钥

sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

然后将存储库添加到源列表中。

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

安装开发工具和ROS工具

sudo apt update && sudo apt install -y \
  python3-flake8-docstrings \
  python3-pip \
  python3-pytest-cov \
  ros-dev-tools

根据你的Ubuntu版本安装软件包。

ubuntu20.04 LTS

python3 -m pip install -U \
   flake8-blind-except \
   flake8-builtins \
   flake8-class-newline \
   flake8-comprehensions \
   flake8-deprecated \
   flake8-import-order \
   flake8-quotes \
   "pytest>=5.3" \
   pytest-repeat \
   pytest-rerunfailures

ubuntu22.04 LTS and later

sudo apt install -y \
   python3-flake8-blind-except \
   python3-flake8-builtins \
   python3-flake8-class-newline \
   python3-flake8-comprehensions \
   python3-flake8-deprecated \
   python3-flake8-import-order \
   python3-flake8-quotes \
   python3-pytest-repeat \
   python3-pytest-rerunfailures

获取ROS2的源码

创建一个工作区并克隆所有源码:

mkdir -p ~/ros2_humble/src
cd ~/ros2_humble
vcs import --input https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos src

 使用rosdep安装依赖

ROS2软件包建立在频繁更新的Ubuntu系统上。始终建议您在安装新软件包之前确保系统是最新的。

sudo apt upgrade
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src -y --skip-keys "fastcdr rti-connext-dds-6.0.1 urdfdom_headers"

如果你使用的发行版是基于Ubuntu的(比如Linux Mint),但没有将自己标识为Ubuntu,你会收到一条错误消息,比如Unsupported OS[Mint]。在这种情况下,将--os=ubuntu:jammy附加到上面的命令中。

安装其他DDS实现(可选)

如果您想使用默认之外的其他DDS或RTPS供应商,您可以在此处找到说明。here.

在工作区中编译代码

如果您已经以另一种方式(通过Debians或二进制发行版)安装了ROS 2,请确保您在没有其他安装来源的新环境中运行以下命令。还要确保你的.bashrc中没有source/opt/ros/${ros_DISTRO}/setup.bash。你可以确保ros 2不是用命令printenv|grep-i ros来源的。输出应该为空.

关于使用ROS工作区的更多信息可以在本教程中找到。this tutorial.

cd ~/ros2_humble/
colcon build --symlink-install

注意:如果您在编译所有示例时遇到问题,并且这使您无法成功完成构建,则可以使用COLCON_IGNORE,方法与CATKIN_IGNORE相同,以忽略子树或从工作区中删除文件夹。举个例子:您希望避免安装大型OpenCV库。那么,只需在cam2image演示目录中运行touch COLCON_IGNORE,就可以将其排除在构建过程之外。

环境设置

source setup script

通过获取以下文件来设置您的环境。

# Replace ".bash" with your shell if you're not using bash
# Possible values are: setup.bash, setup.sh, setup.zsh
. ~/ros2_humble/install/local_setup.bash

尝试一些例子

在一个终端中,获取设置文件,然后运行C++讲话器:

. ~/ros2_humble/install/local_setup.bash
ros2 run demo_nodes_cpp talker

在另一个终端源中,安装文件,然后运行Python侦听器:

. ~/ros2_humble/install/local_setup.bash
ros2 run demo_nodes_py listener

你应该看到talker说这是发布消息,而listener说我听到了这些消息。这将验证C++和Python API是否正常工作.

安装之后

教程Continue with the tutorials and demos to configure your environment, create your own workspace and packages, and learn ROS 2 core concepts.

使用ROS1桥

ROS 1桥可以连接从ROS 1到ROS 2的话题,反之亦然。

See the dedicated documentation on how to build and use the ROS 1 bridge.

其他RMW实现(可选)

ROS2使用的默认中间件是Fast DDS,但中间件(RMW)可以在运行时替换。请参阅有关如何使用多个RMW的指南。 guide 

可替换的编译器

除了gcc之外,使用不同的编译器来编译ROS2是很容易的。如果将环境变量CC和CXX分别设置为工作的C和C++编译器的可执行文件,并重新触发CMake配置(通过使用-force-CMake-config或删除要受影响的包),CMake将重新配置并使用不同的编译器。

Clang

配置CMake来检测和使用Clang:

sudo apt install clang
export CC=clang
export CXX=clang++
colcon build --cmake-force-configure

卸载

1、如果您按照上面的说明使用colcon安装了工作区,那么“卸载”可能只是打开一个新的终端,而不是获取工作区的设置文件。这样,您的环境将表现得好像您的系统上没有Humble安装一样。

2、如果您还试图释放空间,可以使用以下命令删除整个工作区目录:

rm -rf ~/ros2_humble

 

 

 

1.安装cartographer

下载源码

git clone https://ghproxy.com/https://github.com/ros2/cartographer.git -b ros2
git clone https://ghproxy.com/https://github.com/ros2/cartographer_ros.git -b ros2

source一下humble的目录source ~/ros2_humble/humble/local_setup.zsh

会出现如下问题

pcl_conversions", but CMake did not find one.
以及下面
Could not find a package configuration file provided by "pcl_msgs" with any of the following names: pcl_msgsConfig.cmake pcl_msgs-config.cmake

然后需要源码下载

git clone https://github.com/ros-perception/perception_pcl  选择ros2版本的
git clone https://github.com/ros-perception/pcl_msgs -b ros2 

编译的时候需要source ~/ros2_humble/humble/local_setup.zsh

然后按照cmake的方式编译即可。之后再编译cartographer即可colcon build

使用单线激光雷达运行cartographer在 ros2下的humble版本

 配置好urdf

<!--
  Copyright 2016 The Cartographer Authors

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<robot name="cartographer_backpack_2d">
  <material name="orange">
    <color rgba="1.0 0.5 0.2 1" />
  </material>
  <material name="gray">
    <color rgba="0.2 0.2 0.2 1" />
  </material>

  <link name="imu_link">
    <visual>
      <origin xyz="0 0 0" />
      <geometry>
        <box size="0.06 0.04 0.02" />
      </geometry>
      <material name="orange" />
    </visual>
  </link>

  <link name="base_scan">
    <visual>
      <origin xyz="0 0 0" />
      <geometry>
        <cylinder length="0.05" radius="0.03" />
      </geometry>
      <material name="gray" />
    </visual>
  </link>

  <link name="vertical_laser_link">
    <visual>
      <origin xyz="0 0 0" />
      <geometry>
        <cylinder length="0.05" radius="0.03" />
      </geometry>
      <material name="gray" />
    </visual>
  </link>

  <link name="base_footprint" />

  <joint name="imu_link_joint" type="fixed">
    <parent link="base_footprint" />
    <child link="imu_link" />
    <origin xyz="0 0 0" />
  </joint>

  <joint name="base_scan_joint" type="fixed">
    <parent link="base_footprint" />
    <child link="base_scan" />
    <origin rpy="0 0.0 0.0" xyz="0.0 0 0.0" />
  </joint>

  <joint name="vertical_laser_link_joint" type="fixed">
    <parent link="base_footprint" />
    <child link="vertical_laser_link" />
    <origin rpy="0 -1.570796 3.141593" xyz="0.1007 0 0.1814" />
  </joint>
</robot>

新建配置文件

 

-- Copyright 2016 The Cartographer Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

include "map_builder.lua"
include "trajectory_builder.lua"

options = {
  map_builder = MAP_BUILDER,
  trajectory_builder = TRAJECTORY_BUILDER,
  map_frame = "map",
  tracking_frame = "base_footprint",
  published_frame = "base_footprint",
  odom_frame = "odom",
  provide_odom_frame = true,
  publish_frame_projected_to_2d = false,
  use_pose_extrapolator = true,
  use_odometry = false,
  use_nav_sat = false,
  use_landmarks = false,
  num_laser_scans = 1,
  num_multi_echo_laser_scans = 0,
  num_subdivisions_per_laser_scan = 1,
  num_point_clouds = 0,
  lookup_transform_timeout_sec = 0.2,
  submap_publish_period_sec = 0.3,
  pose_publish_period_sec = 5e-3,
  trajectory_publish_period_sec = 30e-3,
  rangefinder_sampling_ratio = 1.,
  odometry_sampling_ratio = 1.,
  fixed_frame_pose_sampling_ratio = 1.,
  imu_sampling_ratio = 1.,
  landmarks_sampling_ratio = 1.,
}

MAP_BUILDER.use_trajectory_builder_2d = true

TRAJECTORY_BUILDER_2D.submaps.num_range_data = 35
TRAJECTORY_BUILDER_2D.min_range = 0.3
TRAJECTORY_BUILDER_2D.max_range = 8.
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 1.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.linear_search_window = 0.1
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.translation_delta_cost_weight = 10.
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.rotation_delta_cost_weight = 1e-1

POSE_GRAPH.optimization_problem.huber_scale = 1e2
POSE_GRAPH.optimize_every_n_nodes = 35
POSE_GRAPH.constraint_builder.min_score = 0.65

return options

新建launch文件

"""
  Copyright 2018 The Cartographer Authors
  Copyright 2022 Wyca Robotics (for the ros2 conversion)

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
"""

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, ExecuteProcess
from launch.conditions import IfCondition, UnlessCondition
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node, SetRemap
from launch_ros.substitutions import FindPackageShare
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.actions import Shutdown
import os

def generate_launch_description():
    ## ***** Launch arguments *****
    bag_filename_arg = DeclareLaunchArgument('bag_filename')

  ## ***** File paths ******
    pkg_share = FindPackageShare('cartographer_ros').find('cartographer_ros')
    urdf_dir = os.path.join(pkg_share, 'urdf')
    urdf_file = os.path.join(urdf_dir, 'backpack_2d.urdf')
    with open(urdf_file, 'r') as infp:
        robot_desc = infp.read()

    ## ***** Nodes *****
    robot_state_publisher_node = Node(
        package = 'robot_state_publisher',
        executable = 'robot_state_publisher',
        parameters=[
            {'robot_description': robot_desc},
            {'use_sim_time': False}],
        output = 'screen'
        )

    cartographer_node = Node(
        package = 'cartographer_ros',
        executable = 'cartographer_node',
        parameters = [{'use_sim_time': False}],
        arguments = [
            '-configuration_directory', FindPackageShare('cartographer_ros').find('cartographer_ros') + '/configuration_files',
            '-configuration_basename', 'my_revo_lds.lua'],
        remappings = [
            ('scan', 'scan')],#节点映射,修改为scan
        output = 'screen'
        )

    cartographer_occupancy_grid_node = Node(
        package = 'cartographer_ros',
        executable = 'cartographer_occupancy_grid_node',
        parameters = [
            {'use_sim_time': False},
            {'resolution': 0.05}],
        )

    rviz_node = Node(
        package = 'rviz2',
        executable = 'rviz2',
        on_exit = Shutdown(),
        arguments = ['-d', FindPackageShare('cartographer_ros').find('cartographer_ros') + '/configuration_files/demo_2d.rviz'],
        parameters = [{'use_sim_time': False}],
    )

    ros2_bag_play_cmd = ExecuteProcess(
        cmd = ['ros2', 'bag', 'play', LaunchConfiguration('bag_filename'), '--clock'],
        name = 'rosbag_play',
    )

    return LaunchDescription([
        # Launch arguments
        #bag_filename_arg, 注释
        # Nodes
        robot_state_publisher_node,
        cartographer_node,
        cartographer_occupancy_grid_node,
        rviz_node,
        #ros2_bag_play_cmd 注释
    ])

 https://docs.ros.org/en/humble/Tutorials.html#

 

posted on 2023-05-29 21:24  gary_123  阅读(3222)  评论(0编辑  收藏  举报

导航