第十弹
话题通信实践案例自定义通信接口 在 chapter_3 下创建一个新的文件层,接着在 src/ 下创建功能包,并进入功能包,在其目录下创建文件 msg,再进入 msg/,创建文件SystemStatus.msg12345678cd ~/learn_ros2/chapter_3/mkdir -p topic_practice_ws/srccd src/ros2 pkg create status_interfaces --dependencies builtin_interfaces rosidl_default_generators --license Apache-2.0cd status_interfaces/mkdir msgcd msgtouch SystemStatus.msg 编辑 .msg 文件内容1234567builtin_interfaces/Time stamp #记录时间戳string host_name # 主机名字float32 cpu_percent # cpu使用率float32 memory_percent #...
第九弹
cpp话题订阅与发布发布速度控制小海龟画圆 查看小海龟节点的话题列表1ros2 topic list -t 在 chapter_3/topic_ws/src/ 下创建包 demo_cpp_topic1ros2 pkg create demo_cpp_topic --build-type ament_cmake --dependencies rclcpp geometry_msgs turtlesim --license Apache-2.0 进入 demo_cpp_topic/src 创建 turtlesim_circle.cpp,其内容如下1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#include "rclcpp/rclcpp.hpp"#include "geometry_msgs/msg/twist.hpp" //...
第八弹
话题一个话题包含了发布节点、订阅节点、话题名称和话题类型四个方面 小海龟示例启动小海龟模拟器1ros2 run turtlesim turtlesim_node 然后在同一路径下打开一个新的终端查看当前运行的节点列表1ros2 node list 查看当前运行节点的信息1ros2 node info /turtlesim 其中,订阅者里的 /turtle1/cmd_vel 话题是负责控制小海龟的,发布者里的 /turtle1/pose 是小海龟的实时位置信息输出小海龟位置信息1ros2 topic echo /turtle1/pose 小海龟的位置信息包含五个参数,坐标(x, y),头的朝向的角度 theta,线速度 linear_velocity,角速度 angular_velocity获取某个话题的消息接口1ros2 topic info /turtle1/cmd_vel 查看接口的详细定义1ros2 interface show...
Ubuntu使用
Ubuntu 换源在使用 sudo apt-get update 和 sudo apt-get upgrade 进行更新时,可能下载会很慢,这个时候使用国内的镜像资源可能会明显提升下载速度。 先是要备份原来的源文件1sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak 再编辑 sources.list 文件1sudo nano /etc/apt/sources.list 这里使用阿里云的镜像1http://mirrors.aliyun.com/ubuntu/ 替换后,再进行更新12sudo apt-get updatesudo apt-get upgrade
第七弹
多线程与回调函数需要下载一个 cpp-httplib ,下载到 workspace/src/demo_one_pkg/include/ 1git clone https://gitee.com/ohhuo/cpp-httplib.git 下载后得到如下文件 下载好之后,修改 demo_one_pkg 的 CMakeLists 文件 12# 包含 cpp-httplib 的 includeinclude_directories(include) 接着,在 demo_one_pkg/src 下创建 learn_thread.cpp,内容如下 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566#include <iostream>#include <thread> // 多线程#include...
第六弹
ROS2 中,cpp新特性的应用auto 12// auto 自动推导类型auto a = 1; // int a = 1 智能指针 智能指针分为三种 shared_ptr 共享的智能指针 weak_ptr 弱引用的智能指针 unique_ptr 独占的智能指针 std::shared_ptr 是一个类模板,它的对象的行为类似于指针,它可以记录共享它所管理的内存对象的对象个数。多个共享指针可以共享同一个对象,当最后一个共享指针被销毁时,会自动释放其所指向的对象。一个共享指针通常使用 make_shared<> 来创建,也可以通过拷贝或者赋值其他共享指针的方式创建。代码示例,在 demo_one_pkg/src/ 下创建 learn_shared_ptr.cpp1234567891011121314151617181920212223#include <iostream>#include <memory>int main(){ // 创建共享智能指针 <数据类型/类>(参数)...