(2) Work space

Features

1. The main function of the workspace is to store project files and file codes (a folder where the workspace and code are stored)
2. The development of ROS depends on the workspace
3. Writing source code and compiling are all done in the workspace
4. , There are three folders (src, build, devel) under the directory of the general workspace

  • The src folder contains the original user code, which is the function package
  • The bulid folder contains intermediate files generated during the compilation process
  • The devel folder is the target file generated by the compilation, that is, some executable files
    5, build and devel folders can be ignored in the process of using ros

Create a workspace

There are three steps
1. Create a folder

mkdir -p ~/new_wheeltec/src 

Explanation:
① mkdir: create a folder instruction
② -p: check whether there is that folder
in the path ③ create a new_wheeltec folder in the home file
④ There is a src folder in the new_wheeltec folder

2. Enter the folder

cd ~/new_wheeltec/src /src

3. Initialize the workspace

catkin_init_workspace

Requirements: Initialize in sec

Compile

(Requirement: It must be compiled in the workspace environment)

  • Entire workspace

      catkin_make
    
  • Compile a single function package

    catkin_make -DCATKIN_WHITELIST_PACKAGES="package_name"
    
  • After compiling a single function package, I want to recompile the entire workspace

    catkin_make -DCATKIN_WHITELIST_PACKAGES=""
    
  • Custom compilation thread (compilation speed)

    catkin_make -j-l
    catkin_make -j2-l2
    

Explanation:

  • ① -j means a task that -job can perform synchronously
  • ② -l is --load-average represents the number of tasks loaded by the system
  • ③ The larger the number of tasks, the faster the compilation, and the higher the CPU requirements

Add environment variables

Understanding
1. After compiling the workspace, we need to add an environment variable in the workspace.
2. The function is to tell the system that this is a path to our workspace, so that we can be correctly indexed when we run the programs in the workspace

If we don’t add environment variables and
run a function package to try, the result is as shown in the figure

roslaunch turn_on_wheeltec_robot turn_on_wheeltec_robot.launch

Insert picture description here
After adding environment variables
① Add environment variables

source devel/setup.bash

② Check whether the addition is successful

echo $ROS_PACKAGE_PATH

Insert picture description here
This is the path
/home/passoni/catkin_ws/src where we just added an environment variable

③ Re-run a .launch file just now

roslaunch turn_on_wheeltec_robot turn_on_wheeltec_robot.launch

Insert picture description here

  • It can be seen that it has been successfully indexed, but opening this function package needs to open the content of another function package, so it is terminated in the middle of the operation
  • This method of adding environment variables is actually limited to the current terminal.

Add global environment variables①
Edit a .bashrc file

nano .bashrc
  • Slide to the bottom

  • source is our environment variable
    ② We add another line, and then enter the path of the workspace we just have.
    ③ The path of the workspace is followed by a devdel/setup.bash
    ④ Do this again

    source .bashrc
    

    ⑤ Run a .launch file just now

    roslaunch turn_on_wheeltec_robot turn_on_wheeltec_robot.launch
    

Guess you like

Origin blog.csdn.net/m0_46278925/article/details/114803013