Wiki
Workspaces and Function Packages
Existing English translations were reused. 3 current source blocks remain in Simplified Chinese, without triggering paid translation.
1.Workspace Introduction

The workspace has 4 subspaces
Code and scripts written in the future will all need to be manually placed into the src space,
The intermediate files generated by compilation will be stored in the build space,
The executable file will be stored in the install space,
During the compilation process and after running, various warnings, error messages, etc. will be stored in the log space.
The pip tool makes it very convenient to install various Python packages.


A tool developed by domestic developer @鱼香ROS specifically for handling ROS2 dependencies.



Actually, it scans the depends in package.xml within each function package, then checks whether the local machine has that dependency, and only then decides whether to install it.
sudo rosdepc init
rosdepc update
cd ..
rosdepc install -i --from-path src --rosdistro humble -y #在src文件里看功能包所需依赖并查找安装

Several more directories still need to be created later, and most of these directories are related to interface files.


2.Source file compilation




#include "rclcpp/rclcpp.hpp"
class MyNode: public rclcpp::Node
{
public:
MyNode():Node("node_name")
{
RCLCPP_INFO(this->get_logger(),"hello world!");
}
};
int main(int argc,char *argv[])
{
rclcpp::init(argc,argv);
auto node = std::make_shared<MyNode>();
rclcpp::shutdown();
return 0;
}


Instantiation can only have one process organize one node,
Inheritance, however, can organize multiple nodes.




What is the purpose of initialization and resource release?
Data can be placed into the context object and also retrieved from it, similar to a message queue in FreeRTOS, but not entirely the same, as it can store previous data.

Initialization does not merely create the context object; that is only one of its functions, and it also has other more important functions.


First initialize the parent class constructor and pass in a node name.

If you've forgotten about smart pointers, you can checkVinci Robot Team C/C++ materials
A smart pointer is a type of pointer that automatically manages memory, releasing memory when the object is no longer needed. Using smart pointers can avoid issues such as memory leaks and dangling pointers.
The safest way to allocate and use dynamic memory is to call a standard library function named make_shared. This function allocates an object in dynamic memory and initializes it, returning a shared_ptr pointing to this object. Like smart pointers, make_shared is also defined in the header file memory.
When using make_shared, you must specify the type of object you want to create. The definition is the same as for a template class: follow the function name with a pair of angle brackets, in which the type is given:
// 指向一个值为42的int的shared_ptr
shared_ptr<int> p3 = make_shared<int>(42);
// p4 指向一个值为"9999999999"的string
shared_ptr<string> p4 = make_shared<string>(10,'9');
// p5指向一个未初始化的int
shared_ptr<int> p5 = make_shared<int>();
//当然,我们通常用 auto 定义一个对象来保存 make_shared 的结果,这种方式较为简单:
// p6指向一个动态分配的空vector<string>
auto p6 = make_shared<vector>();

make_shared can be used to allocate heap memory.
3.Configuration file

C++

Python



name is the package name
version is the package version
description describes package information, that is, what the package is for.
email is the maintainer's email address
The license is the software agreement used by our feature package.









It is not recommended to directly rename a feature package. When the folder name is changed, the configuration content in many of the files inside will also need to be modified. It is recommended to create a new one.
4.Common operation commands


ament_cmake is an enhanced version of CMake



\-h is to view help information

ros2 pkg executables #输出当前系统可执行的功能包和节点


ros2 pkg executables 功能包名 #是输出当前包下可执行的功能包和节点

ros2 pkg list #是输出当前系统可执行的功能包

ros2 pkg prefix + 功能包名 #是输出该功能包的路径(重要,后面经常要用)


ros2 pkg xml + 功能包名 #是输出该功能包里的packages.xml的内容

5.核心模块_通信相关


The communication module is encapsulated into the function package.


for example (example)


It will find a huge amount of content, and you can use grep to search further.





Use -b to download a branch


There is a warning because two feature packages are both named humble
If overwriting is allowed, add the parameter --allow-overriding




That is, something like helloworld.

6.核心模块_工具相关






The command line is more useful than graphical tools in some ways; during remote login, only the command line can be used.


The launch file is now a Python file in ROS2.

Camera is the camera position, Base_Link is the vehicle body position, and Laser is the LiDAR position.
The distance information detected by the radar will be converted into the position information of the vehicle body.




7.feature package








Python is an interpreted language and does not require compilation, but it needs setup.py files. setup.py's main function is to move the executable files to the install.
8.ROS2Technical Support
ROS2_Wiki Official website:
ROS2_Wiki中文官网(ROS2维基百科现已支持简体中文):
ROS2 Simplified Chinese community:
http://wiki.ros.org/cn/community
ROS2Plugin index URL:
https://index.ros.org/packages/










9.ROS2Application direction
Many ROS teams have grown alongside ROS to this day, and their scale has developed to the point where they can be regarded as independent organizations. They have shone brightly in many fields such as navigation, robotic arms, autonomous driving, and drones. Some of these team projects are listed below, and these projects also provide guidance for our future advanced development.
ROS2 Community:
https://www.ros.org/blog/community/

9.1.NAV2
The Nav2 project inherits from the ROS Navigation Stack. The project aims to enable a mobile robot to safely move from point A to point B. It can also be applied to other applications involving robot navigation, such as following dynamic points. Nav2 will be used to implement a series of functions including path planning, motion control, dynamic obstacle avoidance, and recovery behaviors.
NAV2 official website:

9.2.OpenCV
OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. OpenCV is designed to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in commercial products. OpenCV allows businesses to easily use and modify the code.
OpenCV official website:
Tutorial:OpenCV Tutorial

9.3.MoveIt
MoveIt is a set of ROS packages that mainly includes functions such as motion planning, collision detection, kinematics, 3D perception, and manipulation control. It can be used to build advanced behaviors for robotic arms. MoveIt can now be used for most robotic arms on the market and is used by many large companies.

9.4.The Autoware Foundation
The Autoware Foundation is a non-profit organization under ROS that supports open-source projects for implementing autonomous driving. The Autoware Foundation creates synergies between corporate development and academic research, providing autonomous driving technology for everyone.
TAF official website:

9.5.F1 Tenth
F1 Tenth is a racing competition that converts model cars into unmanned vehicles, and is an international community composed of researchers, engineers, and autonomous systems enthusiasts. It was originally founded in 2016 at the University of Pennsylvania, but later expanded to many other institutions around the world.
F1 Tenth Official Website:

9.6.microROS
In ROS-based robotics applications, micro-ROS is bridging the gap between microcontrollers with limited performance and general-purpose processors. micro-ROS runs on various embedded hardware, enabling ROS to be applied directly to robot hardware.
MicroROS official website:

9.7.Open Robotics
Open Robotics collaborates with the global ROS community to create open software and hardware platforms for robots, including ROS1, ROS2, the Gazebo simulator, and the Ignition simulator. Open Robotics uses these platforms to solve some important problems and helps others do the same by providing software and hardware development services to various client organizations.
Open Robotics official website:

9.8.PX4
PX4 is an open-source flight control software for drones and other unmanned vehicles. The project provides drone developers with a flexible set of tools to share technologies and create tailored solutions for drone applications.
PX4 Official Website:

9.9.ROS-Industrial
ROS-Industrial is an open-source project that extends the advanced capabilities of ROS software to industrially relevant hardware and applications.
