網站首頁 編程語言 正文
通過終端是這樣發送得
rostopic pub -1 /swivel/swiveljoint1_position_controller/command std_msgs/Float64 "data: 1.5"
發布得消息類型是? std_msgs/Float64
這個應該發布得topic得名稱? /swivel/swiveljoint1_position_controller/command
實驗一下
通過啟動后查看活躍得topic 發現了此topic 但是現在有發布得地方,應該是有訂閱的地方所以此時該topic 活躍
是對應得
創建功能包
$ catkin_create_pkg swivel_controller_cmd_publisher roscpp std_msgs
依賴 std_msgs 因為需要發布std_msgs/Float64 類型得數據
寫發布功能得cpp
#include <ros/ros.h>
#include "std_msgs/Float64.h" //要發布該類型得數據 需要包含該類型文件
int main(int argc, char **argv)
{
ros::init(argc,argv,"swivel_gimbal_controller_cmd_publisher");
ros::NodeHandle nh ; //實例化句柄,初始化node
std_msgs::Float64 msg; //創建該類型消息
msg.data = 0.1; // 初始化消息
// 聲明發布句柄 <std_msgs::Float64> 消息類型
// "/swivel/swiveljoint1_position_controller/command" 模板名稱
// 數據緩存大小
ros::Publisher pub = nh.advertise<std_msgs::Float64>( "/swivel/swiveljoint1_position_controller/command", 1);
ros::Rate loop_rate(10);//定義發布的頻率,1HZ
while (ros::ok())
{
msg.data = (msg.data)+0.1;
pub.publish(msg); //發布消息
loop_rate.sleep();//根據前面的定義的loop_rate
}
return 0;
}
修改CMakeLists.txt
其中 swivel_gimbal_controller_cmd_publisher 是節點名字
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add_executable(swivel_gimbal_controller_cmd_publisher src/swivel_controller_cmd_publisher.cpp ) #生成可執行文件 swivel_gimbal_controller_cmd_publisher 節點的名字
add_dependencies(swivel_gimbal_controller_cmd_publisher mastering_ros_demo_pkg_generate_messages_cpp) #必須添加add_dependencies,否則找不到自定義的msg產生的頭文件
target_link_libraries(swivel_gimbal_controller_cmd_publisher ${catkin_LIBRARIES})
執行
roscore
rosrun swivel_controller_cmd_publisher swivel_gimbal_controller_cmd_publisher
查看
rostopic echo /swivel/swiveljoint1_position_controller/command
數值按代碼進行自增0.1變化
與系統聯調
結果: 按之前方式啟動整個系統
在啟動發布消息得節點
云臺轉動了
但是會在敲下回車后延時1-2秒,延時 rostopic echo 也沒有信息打印說明還沒發布 可能是節點啟動得延時 ,并不是執行器延時
實驗成功!
原文鏈接:https://juejin.cn/post/7178652307184156732
相關推薦
- 2022-07-13 deepin 桌面版設置華為、阿里倉庫源
- 2021-10-28 C++文件流讀寫操作詳解_C 語言
- 2022-11-25 PostgreSQL自增主鍵用法及在mybatis中的使用教程_PostgreSQL
- 2022-10-17 Qt線程池QThreadPool的使用詳解_C 語言
- 2023-01-15 PyQt5+QtChart實現柱狀圖的繪制_python
- 2024-03-03 ElementUi中el-cascader表單驗證問題
- 2022-07-12 C++重載運算符時函數類型的選擇與類的類型轉換
- 2022-10-07 Android?drawFunctor?原理及應用詳情_Android
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支