ros integrated development environment construction (3) c++, python

Because notepad is too cumbersome to write code, and ros needs to run on multiple nodes, so IDE is required

sudo apt install terminator

After installation is complete

After ctrl+alt+t

Can split horizontally and vertically in one window

alt+arrow keys move between windows

content

The next step is to install vscode

Create a workspace

 C++ compilation

Python compilation

 launch file




The next step is to install vscode

Download directly from vscode official website

 After downloading, install it

 Then wait for the installation

The installation process will jump, from 0 to 100, so click install and wait

 Then add it to your favorites and open it

Double-click to open the installation plugin

install these plugins

 Then configure and run in vscode

Create a workspace

 Create a ros workspace first

命令的主要功能为创建一个或多个空目录,其几种使用方法为:
① mkdir 目录名
作用:创建一个空目录文件
如:mkdir test 创建一个目录名为test的空目录文件

② mkdir –m 权限值 已有目录绝对路径/目录名
作用:在一个已有目录中创建一个拥有相应权限值的空目录文件
如:mkdir -m 755 /home/stu/Desktop/new/Test 在已有目录new目录中去创建一个名字为Test的空目录,该空目录的权限值为755即 rwxr-xr-x

权限值的计算:r为4 ,w为2,x为1,每三位得到一个值,rwx的值为4+2+1=7,r-x的值为4+1=5, rwxr-xr-x 的总值就是755了


————————————————
链接:https://blog.csdn.net/qq_43407589/article/details/90316046
mkdir –p 绝对路径/目录名
作用:在绝对路径中去创建一个空目录文件,如果该绝对路径下目录存在则直接在这个已存在的目录中去创建一个为目录名的空目录文件,如果该绝对路径下目录不存在,则直接在该绝对路径下去创建这个目录然后在这个目录下直接创建目录名的空目录文件
如:mkdir –p /home/stu/Desktop/New/test 在/home/stu/Desktop这个绝对路径下的New目录, New目录在这个绝对路径下创建test目录,但这个New可以是存在的目录也可以是不存在的目录
————————————————

To facilitate this merged build process, the workspace will contain a boilerplate top-level cmakelt .txt under src, which will automatically add all Catkin CMake projects below it into a single large CMake project.

The user will then build this collection of projects as a single unified CMake project using a workflow similar to the standard CMake out-of-source build workflow. They will both be configured with one cmake invocation and then build the target with one or more make invocations
 

$ mkdir build
$ cd build
$ cmake ../src
$ make

To help automate the merged build process, Catkin is distributed using the command line tool catkin_make. This command automates the above CMake workflow 

after initialization

 Then

code .

start vscode

Then ctrl+shift+b

Click on the small gear on the right

copy this code in

{
// 有关 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"
        }
    ]
}

 C++ compilation

Then right click on src and select the bottom option

 

then enter

Enter again

After the creation is completed, if you are afraid of problems, you can compile it with ctrl+shift+b and see if it can pass

 After creating the following files, you can start writing code

Change the standard description in this file

 

Modify the configuration file after writing

 

Make changes to those two places , after the changes, ctrl shift b compile it

Note that the order is important! ! Otherwise it will report an error

If an error is reported, turn off vscode and start over in sequence

No problem, click the + sign on the right to create a new terminal

 Then create a new terminal

Then it compiles successfully

'''
命令用法:

source FileName

作用:在当前bash环境下读取并执行FileName中的命令。

注:该命令通常用命令“.”来替代。

如:source /etc/profile 与 .  /etc/profile 是等效的。

注意:source命令与shell scripts的区别是:

source在当前bash环境下执行命令,而scripts是启动一个子shell来执行命令。这样如果把设置环境变量(或alias等等)的命令写进scripts中,就只会影响子shell,无法改变当前的BASH,所以通过文件(命令列)设置环境变量时,要用source 命令。
'''

 If there are Chinese garbled characters

Note: If the virtual machine is stuck, just wait

Python compilation

Next run python

The previous process has been completed

Create a new folder directly

 Grant permission after writing code

 Open input in integrated terminal

chmod +x *.py
#为所有python文件添加执行权限

 Modify the configuration file

Then compile and execute ctrl shift b

then add a new terminal

roscore

Then open a terminal and go back to the workspace

 

 then run successfully


 

'''
如果不配置CMakeLists,txt 执行 python时抛出异常

/usr/bin/env: "python": 没有那个文件或者目录

原因:当前ros版本 使用的是python3

解决:

  1.直接配置CMakeLists,txt声明解释器为 python

  2.通过软链接将 python 链接到 python3
'''

Soft link operation:

sudo ln -s /usr/bin/python3 /usr/bin/python

With the above step, you can omit configuring CMakeLists

 launch file

A program may require multiple nodes, and it is too troublesome to start one by one each time

Launch multiple nodes at once

Create a new folder

 

 This completes the turtle output operation and outputs the text output by the code

 Complete multi-node operation

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324332089&siteId=291194637