ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

四.开发记录之ubuntu系统安装ROS和开发环境

2022-01-11 13:04:16  阅读:216  来源: 互联网

标签:ROS list yaml 开发 rosdep file ubuntu rosdistro ros


   专栏系列文章如下:

一.开发记录之AHRS、惯导传感器SBG-Ellipse-N传感器配置和使用_goldqiu的博客-CSDN博客_sbg传感器数据格式

二.开发记录之派勤工控机远程使用和ubuntu和ROS环境配置_goldqiu的博客-CSDN博客

​​​​​三.开发记录之移动硬盘装ubuntu系统的配置、环境、各类软件安装和备份等_goldqiu的博客-CSDN博客

这篇主要是讲在ubuntu18.04安装ros-melodic

安装ROS

选择清华源

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
sudo apt install ros-melodic-desktop-full
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo rosdep init
rosdep update

sudo rosdep init 出现

ERROR: cannot download default sources list from:

第一步:

首先进入

https://github.com/ros/rosdistro​github.com/ros/rosdistro

去把这个包下载下来。

第二步:

修改这个包中rosdep/source.list.d/下的文件20-default.list,将这个文件中指向http://raw.githubusercontent.com的url地址全部修改为指向本地文件的地址,也就是该下载好的包的地址,以下是改好的样例:

# os-specific listings first

yaml file:///home/xxx/rosdistro/rosdep/osx-homebrew.yaml osx

# generic

yaml file:///home/xxx/rosdistro/rosdep/base.yaml

yaml file:///home/xxx/rosdistro/rosdep/python.yaml

yaml file:///home/xxx/rosdistro/rosdep/ruby.yaml

gbpdistro file:///home/xxx/rosdistro/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

注意:在py语言中:url本地文件地址格式是:file://+文件地址,后面更改其他文件中地址的时候也一样。

第三步:

修改/usr/lib/python2.7/dist-packages/rosdep2该文件夹下面的sources_list.py文件,如下:

# default file to download with 'init' command in order to bootstrap

# rosdep

DEFAULT_SOURCES_LIST_URL = 'file:///home/xxx/rosdistro/rosdep/sources.list.d/20-default.list'


# seconds to wait before aborting download of rosdep data

第四步

修改以下两个文件里面的代码:

/usr/lib/python2.7/dist-packages/rosdep2/rep3.py

/usr/lib/python2.7/dist-packages/rosdistro/init.py

下面是分别修改后的样例:

/usr/lib/python2.7/dist-packages/rosdep2/rep3.py文件:

# location of targets file for processing gbpdistro files

REP3_TARGETS_URL = 'file:///home/xxx/rosdistro/releases/targets.yaml'


# seconds to wait before aborting download of gbpdistro data

/usr/lib/python2.7/dist-packages/rosdistro/init.py的文件:

# index information


DEFAULT_INDEX_URL = 'file:///home/xxx/rosdistro/index-v4.yaml'
 

def get_index_url():

然后进行sudo rosdep init :

安装ros开发环境

官网下载deb

https://code.visualstudio.com/docs/?dv=linux64_deb

sudo dpkg -i xxxx.deb

安装这些插件

创建工作空间:

mkdir -p test_ws/src
cd test_ws/
catkin_make
code .

vscode 中编译 ros:

快捷键 ctrl + shift + B 调用编译,选择:catkin_make:build

或修改.vscode/tasks.json 文件

{
// 有关 tasks.json 格式的文档,请参见
    // https://go.microsoft.com/fwlink/?LinkId=733558
    "version": "2.0.0",
    "tasks": [
        {
            "label": "catkin_make:debug", //代表提示的描述性信息
            "type": "shell",  //可以选择shell或者process,如果是shell代码是在shell里面运行一个命令,如果是process代表作为一个进程来运行
            "command": "catkin_make",//这个是我们需要运行的命令
            "args": [],//如果需要在命令后面加一些后缀,可以写在这里,比如-DCATKIN_WHITELIST_PACKAGES=“pac1;pac2”
            "group": {"kind":"build","isDefault":true},
            "presentation": {
                "reveal": "always"//可选always或者silence,代表是否输出信息
            },
            "problemMatcher": "$msCompile"
        }
    ]
}

创建 ROS 功能包

选定 src 右击 ---> create catkin package

设置包名 添加依赖

添加cpp

/*
    控制台输出 HelloVSCode !!!
​
*/
#include "ros/ros.h"
​
int main(int argc, char *argv[])
{
    setlocale(LC_ALL,"");
    //执行节点初始化
    ros::init(argc,argv,"HelloVSCode");
​
    //输出日志
    ROS_INFO("Hello VSCode!!!");
    return 0;
}

如果没有代码提示:

修改 .vscode/c_cpp_properties.json

设置 "cppStandard": "c++17"

配置 CMakeLists.txt:

add_executable(节点名称
  src/C++源文件名.cpp
)
target_link_libraries(节点名称
  ${catkin_LIBRARIES}
)

目前这里好像会出节点tab不到的情况,执行这一句后可以了

rospack list

后面单独出一个ROS或者cmake项目调试的,用QT、Vscode或clion。

QT更常用来qmake做UI,clion则是cmake,Vscode则是cmake和ros比较方便

 

标签:ROS,list,yaml,开发,rosdep,file,ubuntu,rosdistro,ros
来源: https://blog.csdn.net/weixin_36773706/article/details/122429795

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有