ROS基礎學習筆記(四) 發布者訂閱者簡單練習

2021-10-06 14:31:15 字數 819 閱讀 1701

在之前的功能包的基礎上,移動到功能包中的src資料夾下編輯發布者檔案

vim thetalker.cpp
#include #include "ros/ros.h"

#include "std_msgs/string.h"

int main(int argc , char ** ar**)

return 0;

}

編輯訂閱者檔案

vim thelistener.cpp
#include "ros/ros.h"

#include "std_msgs/string.h"

void sendercallback( const std_msgs::string::constptr& msg )

int main( int argc , char ** ar** )

~

之後使用  cd ~/catkin_ws 和 catkin_make 進行編譯或者使用之前定義的cm命令。

再新開乙個終端視窗執行roscore命令

吶,你看,這就搞定啦

(十三)ROS發布者和訂閱者

參考 本文實現發布者和訂閱者,發布者發布資訊,資訊的內容是編號,訂閱者訂閱發布者訊息,並將解析出來的編號儲存為檔案 直接上 新建發布者節點 include ros ros.h include std msgs string.h include int main int argc,char argv ...

10發布者Publisher的程式設計實現

1 建立功能包 1.1 一定要把功能包放在工作空間的src資料夾裡面 建立功能包命令 catkin create pkg 功能包名 learning topic 依賴 roscpp rospy std msgs geometry msgs turtlesim chen ubuntu catkin w...

10 發布者publisher的程式設計實現

1.ros publisher turtle vel pub n.advertise turtle vel pub 10 advertise 返回乙個 publisher 物件。通過呼叫物件的 publish 函式,你可以在這個topic上發布 message。猜測publisher 物件應該是從屬...