The article directories
-
- preface
- (1) background
- (2) the premise
- (3) task
-
- ⅰ Ros 2 installation environment
- ⅱ Creating a Folder
- Clone tutorial code
- ⅳ Resolving dependencies
- ⅴ build with colcon
- Vi Install a custom workspace
- ⅶ modified to cover
- (4) summarize
preface
Mainly learn how to use the client library to achieve their own functions, mainly introduced C++ and python, the other I do not know. Over the open sledding system, there are a number of eloquent ros2 libraries that don’t work, too
- Rosidl_generator_java – Generates Java’s ROS interface.
- Rosidl_generator_objc – Generates Objective C’s ROS interface.
- Rosidl_generator_cpp – generates the ros interface for c++.
- Rosidl_generator_c – Ros interface that generates C
- Rosidl – provides ROS IDL (.msg) definitions and code generation packages.
- Rosidl_dds – DDS interface that generates ROS interfaces.
Based on ros_tutorials, you can learn from the following sites
- Github.com/ros/ros_tut…
- Github.com/ros2/exampl…
- github.com/ros2/demos
Creating a workspace
(1) background
The workspace is a directory containing the ROS 2 package. Before ROS 2 can be used, the installation workspace for ROS 2 must be installed on the terminal you want to use (via source your_ws/install/setup.bash). This allows you to use the package that comes with ROS2. You can create your own custom workspace, which is officially recommended, you can create a low-level workspace, and a business workspace, which contains all business dependencies, namely modularity
(2) the premise
Existing ones do not need to be re-installed
- Install ros2
- Install colcon
sudo apt install python3-colcon-common-extensions
- Install git
sudo apt install git
- Install the turtle
sudo apt install ros-<distro>-turtlesim
- Install rosdep
sudo apt-get install python-rosdep
- Basic Linux commands, not here to check www.ee.surrey.ac.uk/Teaching/Un…
- Text editor, on my side
C++
Use of theClion
.python
Use of thepycharm
(3) task
ⅰ Ros 2 installation environment
To install the ros2 environment, run the following command on the terminal via source:
source /opt/ros/<distro>/setup.bash
Copy the code
Example:
source /opt/ros/eloquent/setup.bash
Copy the code
It is recommended to write to the boot file.bashrc, so that you do not need to type, and will not forget
echo "source /opt/ros/eloquent/setup.bash" >> ~/.bashrc
Copy the code
ⅱ Creating a Folder
Create a folder for each workspace, preferably one named dev_ws for development workspace
mkdir dev_ws
mkdir dev_ws/src
cd dev_ws/src
Copy the code
Just put your own package under SRC
Clone tutorial code
Execute the command under dev_ws/SRC path: git clone https://github.com/ros/ros_tutorials.git – b eloquent – devel
This is a download
ⅳ Resolving dependencies
In the future, when using other people’s packages, this is also the solution to the dependency problem
in~/dev_ws
Path executionsudo rosdep install -i --from-path src --rosdistro eloquent -y
In the event of an error, just follow the instructions
sudo rosdep init
rosdep update
Copy the code
If init keeps failing, do something about it. Bad network
ⅴ build with colcon
in~/dev_ws
Path to compile, and the command is thiscolcon build
Other useful parameters for colcon Build:
--packages-up-to
Generate the required packages and all their dependencies, but not the entire workspace (to save time)--symlink-install
Avoids having to rebuild every time you adjust a Python script--event-handlers
Console_direct + displays console output at build time
Vi Install a custom workspace
Setup.bash in the default installation path is automatic, so we only need to execute setup.bash under dev_ws in two ways
. install/local_setup.bash
source install/local_setup.bash
Custom workspaces with the same name will overwrite the installation path, check this outsetup.bash
You know the
ⅶ modified to cover
Modify the~/dev_ws/src/ros_tutorials/turtlesim/src/turtle_frame.cpp
Line 52, change tosetWindowTitle("MyTurtleSim")
And then compile and run it
So depending on the environment, the result of the execution will be different, the left side is not installed overlay, the right side is installed
(4) summarize
In this tutorial, you use the main ROS 2 release installation as the base and create an overlay (custom) by cloning and building the package in a new workspace. As you can see in the modified Turtlesim, overlays precede the path and take precedence over the bottom layer (/opt/ ROS).
It is recommended to use an overlay to handle a small number of packages, so you don’t have to put everything in the same workspace and don’t have to spend a lot of time compiling every time.