学习
hello word
ROS2系统学习3—第一个“Hello World”程序—即工作空间创建与包创建
创建工作目录
mkdir ros2Workspace
cd ros2Workspace
mkdir src
colcon build
打印输出:
Summary: 0 packages finished [0.61s]
创建一个功能包,方法和ros1是类似的,这里创建一个名为my_node的
ROS2学习笔记之创建自己的功能包
ros2 pkg create --build-type ament_cmake --node-name my_node my_package
返回数据:
xiaohua@ubuntu:~/code/ros2/ros2Workspace/src$ ros2 pkg create
–build-type ament_cmake --node-name my_node my_package going to create a new package package name: my_package destination directory:
/home/xiaohua/code/ros2/ros2Workspace/src package format: 3 version:
0.0.0 description: TODO: Package description maintainer: [‘xiaohua 2960229652@qq.com’] licenses: [‘TODO: License declaration’] build
type: ament_cmake dependencies: [] node_name: my_node creating folder
./my_package creating ./my_package/package.xml creating source and
include folder creating folder ./my_package/src creating folder
./my_package/include/my_package creating ./my_package/CMakeLists.txt
creating ./my_package/src/my_node.cpp
xiaohua@ubuntu:~/code/ros2/ros2Workspace/src$ ls my_package
回到工作目录的根目录,进行编译,编译指令:
colcon build
Starting >>> my_package
Finished <<< my_package [2.27s]
Summary: 1 package finished [2.89s]
最后source一下setuo文件:
source ./install/setup.bash
运行代码
ros2 run my_package my_node
另外,也可以把node放在package外面,直接放在src目录下:
ROS2创建如何创建节点(C++)
ros2 pkg create <<name_of_pack>> --build-type ament_cmake --dependencies rclcpp
.创建cpp文件
touch name_of_pack/src/main.cpp