Workspace and Function Packages
Workspace Overview

The workspace contains 4 subspaces.
All future code and scripts must be manually placed into the src directory.
The intermediate files generated by compilation will be stored in the build space.
The executable files will be stored in the install space.
Compilation process and various warnings, error messages after running, etc., will be stored in the log space.
Using the pip tool, you can easily install various Python packages.


A tool specifically designed for handling ROS2 dependencies, developed by Chinese developer @FishROS.



It essentially scans the depend entries in the package.xml files of each package, checks whether the local machine has those dependencies, and then decides whether to install them.
sudo rosdepc init
rosdepc update
cd ..
rosdepc install -i --from-path src --rosdistro humble -y #在src文件里看功能包所需依赖并查找安装

Several more directories need to be created next, most of which are related to interface files.


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 allows only one node per process.
Inheritance can organize multiple nodes.




What is the purpose of initialization and resource release?
You can put data into the context object and also retrieve data from it. It is somewhat similar to a message queue in FreeRTOS, but not entirely — it can also store previously saved data.

Initialization is not just about creating a context object; that is only one of its functions. It also has other important functions.


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

If you've forgotten about smart pointers, check out the Vinci Robotics Team C/C++ Resources.
Smart pointers are a type of pointer that automatically manage memory, releasing it when the object is no longer needed. Using smart pointers helps prevent issues such as memory leaks and dangling pointers.
The safest way to allocate and use dynamic memory is to call a standard library function called make_shared. This function allocates an object in dynamic memory, initializes it, and returns a shared_ptr pointing to that 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 follows the same pattern as a template class, with the type given in angle brackets after the function name:
// 指向一个值为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>();

Using make_shared can allocate memory on the heap.
Configuration file

C++

Python



name is the package name
version is the package version
The description provides information about the package—that is, what the package does.
email is the maintainer's email address
license is the software license used by our function package.









It is not recommended to directly rename a package. When the folder name is changed, many configuration files inside also need to be updated. It is better to create a new one.
Commonly used operation commands


ament_cmake is an enhanced version of cmake.



-h displays help information.

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


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

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

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


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

Core Module_Communication Related


The communication module has been encapsulated into the feature package.


For example


You'll find a huge amount of content; you can use grep to search further.





Use -b to download a branch


There's a warning because two function packages are both named humble.
If overriding is allowed, add the parameter --allow-overriding.




Like a "Hello World" example.

Core Modules_Tools Related






The command line is more convenient than graphical tools in some situations, and when logging in remotely, only the command line is available.


Launch files are now Python files in ROS2.

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




Feature package








Python is an interpreted language, so it doesn't require compilation. However, it does need a setup.py file, whose main function is to move executable files to the install directory.
ROS2 technical support
ROS2_Wiki official website
ROS2_Wiki Chinese Official Site (ROS2 Wikipedia now supports Simplified Chinese)
ROS2 Simplified Chinese Community
http://wiki.ros.org/cn/community
ROS2 plugin index URL:
https://index.ros.org/packages/










ROS2 application directions
Many ROS teams have grown alongside ROS to this day, and their scale has developed to the point where they can be considered independent organizations. They have excelled in numerous fields such as navigation, robotic arms, autonomous driving, and drones. Below are some of these team projects, which also provide guidance for our future advanced development.
ROS2 Community:
https://www.ros.org/blog/community/

NAV2
The Nav2 project is inherited from the ROS Navigation Stack. It is designed to enable a mobile robot to safely navigate from point A to point B. It can also be applied to other robot navigation tasks, such as following a dynamic point. Nav2 is used to implement a range of functions including path planning, motion control, dynamic obstacle avoidance, and recovery behaviors.
NAV2 official website:

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

MoveIt
MoveIt is a set of ROS packages that primarily includes motion planning, collision detection, kinematics, 3D perception, manipulation control, and other features. It can be used to build high-level behaviors for robotic arms. MoveIt is now compatible with most robotic arms on the market and is used by many large companies.

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

F1 Tenth
F1 Tenth is a racing competition that converts model cars into autonomous vehicles, and it is an international community of researchers, engineers, and autonomous systems enthusiasts. It was originally founded in 2016 at the University of Pennsylvania but has since expanded to many other institutions around the world.
F1 Tenth official website:

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

Open Robotics
Open Robotics collaborates with the global ROS community to create open software and hardware platforms for robotics, including ROS1, ROS2, the Gazebo simulator, and the Ignition simulator. Open Robotics uses these platforms to address key challenges and helps others do the same by providing software and hardware development services to a variety of client organizations.
Open Robotics official website:

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 for sharing technology and creating tailored solutions for drone applications.
PX4 official website:

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