Ros2
hello world c++
mkdir -p {
your workspace name}/src
cd {
your workspace name} #进入工作空间
colcon build #编译
create package
in {your workspace name}/src
ros2 pkg create {
your package name} --build-type ament-cmake --dependencies rclcpp --node-name helloworld
helloworld.cpp
#include "rclcpp/rclcpp.hpp"
int main(int argc,char ** argv)
{
rclcpp::init(argc,argv);
auto node = rclcpp::Node::make_shared("helloworld_node");
RCLCPP_INFO(node->get_logger(),"hello world!");
rclcpp::shutdown();
return 0;
}
if you want to add some dependencies you can like this
this is CMakeLists
's explain
# 引入外部依赖包
find_package(rclcpp REQUIRED)
# 映射源文件与可执行文件
add_executable(helloworld src/helloworld.cpp)
# 设置目标依赖库
ament_target_dependencies(
helloworld
"rclcpp"