超详细Ubuntu16.04 ROS Cartographer Qt开发环境搭建

时间:2024-03-21 06:59:53

Ubuntu16.04 ROS

 

https://blog.csdn.net/CGJustDoIT/article/details/100055755#25_rosdep_57

 

http://community.bwbot.org/topic/878/%E8%A7%A3%E5%86%B3rosdep-init-error-cannot-download-default-sources-list-%E9%97%AE%E9%A2%98

 

1. 添加ROS源

ROS官方的软件源镜像
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

 

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

 

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

 

中国科学技术大学(USTC)镜像源

sudo sh -c 'echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

 

中山大学(Sun Yat-Sen Univercity)镜像源

sudo sh -c '. /etc/lsb-release && echo "deb http://mirror.sysu.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

 

易科机器人实验室镜像源

sudo sh -c '. /etc/lsb-release && echo "deb http://ros.exbot.net/rospackage/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

 

2. 设置Key

sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

 

sudo apt-get update

 

sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key F42ED6FBAB17C654

 

sudo apt-get update

 

3. 安装kinetic

sudo apt-get install ros-kinetic-desktop-full

 

4. 初始化rosdep

a.sudo rosdep init

i).sudo gedit /etc/hosts

ii).域名污染,添加以下内容到hosts

                   192.30.253.118 gist.github.com

185.199.110.153 github.io

 

151.101.113.194 github.global.ssl.fastly.net

52.216.227.168 github-cloud.s3.amazonaws.com

52.74.223.119 github.com

 

199.232.28.133 avatars1.githubusercontent.com

199.232.28.133 avatars2.githubusercontent.com

199.232.28.133 avatars0.githubusercontent.com

199.232.28.133 avatars3.githubusercontent.com

199.232.28.133 raw.githubusercontent.com

199.232.28.133 user-images.githubusercontent.com

199.232.28.133 avatars.githubusercontent.com

199.232.28.133 github.map.fastly.net

199.232.28.133 avatars7.githubusercontent.com

 

# Amazon AWS Start

54.239.31.69 aws.amazon.com

54.239.30.25 console.aws.amazon.com

54.239.96.90 ap-northeast-1.console.aws.amazon.com

54.240.226.81 ap-southeast-1.console.aws.amazon.com

54.240.193.125 ap-southeast-2.console.aws.amazon.com

54.239.54.102 eu-central-1.console.aws.amazon.com

177.72.244.194 sa-east-1.console.aws.amazon.com

176.32.114.59 eu-west-1.console.aws.amazon.com

54.239.31.128 us-west-1.console.aws.amazon.com

54.240.254.230 us-west-2.console.aws.amazon.com

54.239.38.102 s3-console-us-standard.console.aws.amazon.com

54.231.49.3 s3.amazonaws.com

52.219.0.4 s3-ap-northeast-1.amazonaws.com

54.231.242.170 s3-ap-southeast-1.amazonaws.com

54.231.251.21 s3-ap-southeast-2.amazonaws.com

54.231.193.37 s3-eu-central-1.amazonaws.com

52.218.16.140 s3-eu-west-1.amazonaws.com

52.92.72.2 s3-sa-east-1.amazonaws.com

54.231.236.6 s3-us-west-1.amazonaws.com

54.231.168.160 s3-us-west-2.amazonaws.com

52.216.80.48 github-cloud.s3.amazonaws.com

54.231.40.3 github-com.s3.amazonaws.com

52.216.20.171 github-production-release-asset-2e65be.s3.amazonaws.com

52.216.228.168 github-production-user-asset-6210df.s3.amazonaws.com

 

b.rosdep update

 

 

5. 配置环境变量

echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc

source ~/.bashrc #在终端内重新加载 .bashrc文件

6. 测试  

a.roscore

b.rosrun turtlesim turtlesim_node

c.rosrun turtlesim turtle_teleop_key

d.rosrun rqt_graph rqt_graph

 

 

cartographer

 

1. 安装依赖项

sudo apt-get install -y google-mock libboost-all-dev  libeigen3-dev libgflags-dev libgoogle-glog-dev liblua5.2-dev libprotobuf-dev  libsuitesparse-dev libwebp-dev ninja-build protobuf-compiler python-sphinx  ros-kinetic-tf2-eigen libatlas-base-dev libsuitesparse-dev liblapack-dev

 

2. 安装ceres-solver-1.11.0

git clone https://github.com/hitcm/ceres-solver-1.11.0.git

cd ceres-solver-1.11.0

mkdir build

cd build

cmake ..

make -j4

sudo make install

3. cartographer

git clone https://github.com/hitcm/cartographer.git

cd cartographer

mkdir build

cd build

cmake .. -G Ninja

ninja

ninja test

sudo ninja install

 

4. bianyi cartographer_ros

#初始化工作空间,我之前有一个工作空间为cartographer_ws

mkdir -p ~/cartographer_ws/src

cd ~/cartographer_ws/src

catkin_init_workspace

 

#安装cartographer_ros

cd ~/cartographer_ws/src

git clone https://github.com/hitcm/cartographer_ros.git

cd ~/cartographer_ws

catkin_make

 

echo "source ~/cartographer_ws/devel/setup.bash" >> ~/.bashrc

source ~/.bashrc

 

5.

2D数据:
https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag

 

3D数据:
https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/b3-2016-04-05-14-14-00.bag

 

roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/data/cartographer_paper_deutsches_museum.bag

 

roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag

 

 

6. Qt开发环境搭建

 

  • qt安装
  • qros_qtc_plugin

sudo add-apt-repository ppa:levi-armstrong/qt-libraries-xenial  

sudo add-apt-repository ppa:levi-armstrong/ppa  

sudo apt-get update && sudo apt-get install qt57creator-plugin-ros

  • 修改系统配置文件

sudo gedit /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf

 将:

/usr/lib/x86_64-linux-gnu/qt4/bin

  /usr/lib/x86_64-linux-gnu

修改为:

/home/rc/qt5.9.7/5.9.7/gcc_64/bin

/home/rc/qt5.9.7/5.9.7/gcc_64/lib

  • qtcreator-ros

 

  • ROS代码自动补全

 sudo apt-get install bash-completion rosbash

 

7. 测试

  • 建立工作空间

mkdir -p ~/qt_ws/src

  • 初始化工作空间

cd ~/qt_ws/src

catkin_init_workspace

  • 编译工作空间

cd ~/qt_ws

catkin_make

  • qtcreator-ros
  • qtcreator→ New File or Project → other project→ROS Workspace
  • 设置工程name,Distribution,Build system,workspace,next,finish。

 

超详细Ubuntu16.04 ROS Cartographer Qt开发环境搭建

  • 选中src文件夹右键点击Add New...,在弹出的框中选择ROS->Package,点击choose

 

超详细Ubuntu16.04 ROS Cartographer Qt开发环境搭建

  • Package Details中填写包名Name,如beginner_tutorials,在Catkin一栏填写需要用到的依赖,如roscpp;其他的选项可以不填,保持默认不动,完成ROS包的创建。

    超详细Ubuntu16.04 ROS Cartographer Qt开发环境搭建

 

  • Basic 节点添加

选中beginner_tutorials包下面的src文件,右键点击点击Add New...,在弹出的框中选择ROS->Basic Node,点击choose,设置添加文件的文件名。

    超详细Ubuntu16.04 ROS Cartographer Qt开发环境搭建

 

#include <ros/ros.h>

#include <std_msgs/String.h>

#include <sstream>

int main(int argcchar *argv[])

{

    ros::init(argc, argv, "talker");

    ros::NodeHandle nh;

    ros::Publisher pub_ = nh.advertise<std_msgs::String>("chatter"1000);

    ros::Rate loop_rate(10);

    int count = 0;

    while (ros::ok())

    {

        std_msgs::String msg;

        std::stringstream ss;

        ss << "Hello ros, glad to learn." << count;

        msg.data = ss.str();

        ROS_INFO("%s", msg.data.c_str());

        pub_.publish(msg);

        ros::spinOnce();

        loop_rate.sleep();

        ++count;

    }

    return 0;

}

 

 

  • 订阅节点

类似的方法添加订阅节点,选择Basic Subscriber Node,listener.cpp。

 #include "ros/ros.h"

#include "std_msgs/String.h"

void chatterCallback(const std_msgs::String::ConstPtr& msg)

{

  ROS_INFO("I heard: [%s]", msg->data.c_str());

}

int main(int argcchar **argv)

{

  ros::init(argc, argv, "listener");

  ros::NodeHandle nh;

  ros::Subscriber sub = nh.subscribe("chatter"1000, chatterCallback);

  ros::spin();

  return 0;

}

 

  • CmakeLIst.txt修改,部分代码如下;

cmake_minimum_required(VERSION 2.8.3)

project(beginner_tutorials)

 

find_package(catkin REQUIRED COMPONENTS

 roscpp

)

 

include_directories(

# include

    •  ${catkin_INCLUDE_DIRS}

)

 

include_directories(include ${catkin_INCLUDE_DIRS})

 

add_executable(talker src/talker.cpp)

target_link_libraries(talker ${catkin_LIBRARIES})

add_dependencies(talker beginner_tutorials_generate_messages_cpp)

 

add_executable(listener src/listener.cpp)

target_link_libraries(listener ${catkin_LIBRARIES})

add_dependencies(listener beginner_tutorials_generate_messages_cpp)

 

  • 编译,运行

1、build

2、Project→Build & Run→Run

3、Run→Add→ROS Run Configuration

超详细Ubuntu16.04 ROS Cartographer Qt开发环境搭建

 

4、配置package和target

选择Add Run Step下面的ROS Run Step,在Arguments一栏填写beginner_tutorials talker,前面为包名,后面为节点名;或者直接在Package和Target下分别找到包名和节点。

超详细Ubuntu16.04 ROS Cartographer Qt开发环境搭建

 

  • 开启roscore
  • 选中项目,右键点击Run运行,便可以在ROS Terminals下看到两个节点运行的结果。