当前位置:网站首页>Ros2 - workspace (V)

Ros2 - workspace (V)

2022-07-05 06:50:00 Me and nano

ROS2 Robot operating system


Preface

I've got a general idea ROS2 What is it? , Also ready to learn ,ROS2 The core concept of is roughly divided into the following points
 Insert picture description here

One 、 working space

stay ROS Robot development , When we start the code for some functions of the robot , Various written codes 、 Parameters 、 Scripts and other files , It also needs to be placed in a folder for management , This folder is in ROS In the system, it is called workspace .

So the workspace is a folder for storing files related to project development , It is also the base camp for storing all materials in the development process .
 Insert picture description here
ROS A typical workspace structure in the system is shown in the figure , This dev_ws Is the root directory of the workspace , There will be four subdirectories , Or four subspaces .
src, Code space , Future code 、 Script , All need to be artificially placed here ;
build, Compilation space , Save intermediate files generated during compilation ;
install, Installation space , Place the compiled executable and script ;
log, Log space , During compilation and operation , Save various warnings 、 error 、 Information log .
In general , These four space folders , Most of our operations are in src In the , After successful compilation , Will execute install The results inside ,build and log Two folders are rarely used .

We can define the name of the workspace by ourselves , Quantity is not unique , such as :

 working space 1:dev_w_a, be used for A Robot development ;

 working space 2:dev_ws_b, be used for B Some functions of robots ;

 working space 3:dev_ws_b2, Used to develop B Other functions of robots .

Two 、 Specific operation of workspace

1. Create a workspace

Next, we can create a workspace with the following commands , And download the code :

mkdir -p ~/dev_ws/src
cd ~/dev_ws/src
git clone https://gitee.com/guyuehome/ros2_21_tutorials.git

 Insert picture description here

2. Auto install dependency

Various codes we download from the community , There will be some dependence , We can install one by one manually , You can also use rosdep Tools are automatically installed :

sudo apt install -y python3-pip
sudo pip3 install rosdepc
sudo rosdepc init
rosdepc update
cd ..
rosdepc install -i --from-path src --rosdistro humble -y

Here if Pip Installation failed , You can use scripts to install

wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py

 Insert picture description here

These operations are in src In the , That is initialization , And then update , Finally, install the dependency src The previous level , Remember cd …

3. Compile workspace

After the dependency installation , You can compile the workspace with the following commands , If there is a lack of dependency , Or there is an error in the code , Errors will be reported during compilation , Otherwise, there should be no errors in the compilation process :

sudo apt install python3-colcon-ros
cd ~/dev_ws/
colcon build

 Insert picture description here
 Insert picture description here
After the compilation is successful, you will see all four files come out
 Insert picture description here

4. Set the environment variable

After successful compilation , In order for the system to find our function packs and executable files , You also need to set environment variables :

source install/local_setup.sh #  Only effective on the current terminal 
echo " source ~/dev_ws/install/local_setup.sh" >> ~/.bashrc #  All terminals are valid 

summary

thus , We have completed the creation of the workspace 、 Compile and configure .

原网站

版权声明
本文为[Me and nano]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050635158127.html