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

2021-10-08 20:45:57 字數 1331 閱讀 1000

1.ros::publisher turtle_vel_pub = n.advertise("/turtle_vel_pub",10);

advertise( ) 返回乙個 publisher 物件。 通過呼叫物件的 publish( )函式, 你可以在這個topic上發布 message。猜測publisher 物件應該是從屬於節點的。

10是佇列長度,當publisher發布頻率太快,底層乙太網不能迅速響應,所以先將資料放在佇列中,相當於乙個快取。如果仍然發不出去,最先進隊的資料會被拋掉,就會出現掉資料的情況。

2.ros_info("publish turtle velocity command[%0.2f m/s, %0.2f rad/s]", vel_msg.linear.x, vel_msg.angular.z);

ros_info類似於c語言中的printf函式,輸出日誌資訊。

3.loop_rate.sleep();

按照迴圈頻率延時,實現每秒發布訊息的頻率。

4.cmakelists檔案的修改

add_executable

(velocity_publisher src/velocity_publisher.cpp)

將src中的velocity_publisher.cpp編譯成可執行檔案velocity_publisher。

target_link_libraries

(velocity_publisher $

)

1.#!/usr/bin/env python

指定執行指令碼的直譯器

直譯器

2.import rospyfrom geometry_msgs.msg import twist

使用 import 語句來引入模組

python模組

3.if __name__ == '__main__':

__name__是當前模組名,當模組被直接執行時模組名為__main__。這句話的意思就是,當模組被直接執行時,以下**塊將被執行,當模組是被匯入時,**塊不被執行。(ifname== 『main』 如何正確理解? - 曠修的回答 - 知乎

更詳細的解釋

4.try/except語句

python使用try/except語句處理異常。

python異常處理

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

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

win10發布者不受信任處理方法

方法1 關閉使用者賬戶控制 1 win x 進入控制面板,選擇安全性與維護,在左側更改windows smartscreen篩選器設定,選擇 不執行任何操作 單擊確定即可。2 win x 進入控制面板,選擇使用者賬戶,選擇最下面的 更改使用者賬戶控制設定 把滑條拉到最下面 從不通知 3 win r ...

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

在之前的功能包的基礎上,移動到功能包中的src資料夾下編輯發布者檔案 vim thetalker.cpp include include ros ros.h include std msgs string.h int main int argc char ar return 0 編輯訂閱者檔案 vi...