插曲一(ros1)
cpp节点编写(ros1) ROS1中,cpp对应的接口叫—roscpp与ROS2一样,创建一个功能包之后,在该包的src(source)文件下新建cpp文件,先在工作空间下的 src/ 下创建一个功能包12roscd ros_workspace/src/catkin_create_pkg test_pkg roscpp rospy std_msgs 进入 test_pkg/src/ ,创建一个cpp文件,12cd test_pkg/srctouch test.cpp 然后开始编写第一个cpp节点12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#include "ros/ros.h" // 包含ROS的核心头文件#include "std_msgs/String.h" // 包含标准消息类型String的头文件#include <sstream> ...
第十弹
话题通信实践案例自定义通信接口 在 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...