国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

香港外貿(mào)網(wǎng)站建設(shè)谷歌搜索引擎網(wǎng)址

香港外貿(mào)網(wǎng)站建設(shè),谷歌搜索引擎網(wǎng)址,網(wǎng)站做新聞外鏈有作用嗎,復(fù)制手機網(wǎng)站模板文章目錄 一、話題通信機制解析1、話題通信機制簡介2、消息隊列分析3、使用技巧 二、實驗驗證(一)subscriber隊列長度對數(shù)據(jù)傳輸影響(二)數(shù)據(jù)傳輸時間延遲 三、總結(jié) 一、話題通信機制解析 1、話題通信機制簡介 (1&…

文章目錄

    • 一、話題通信機制解析
      • 1、話題通信機制簡介
      • 2、消息隊列分析
      • 3、使用技巧
    • 二、實驗驗證
      • (一)subscriber隊列長度對數(shù)據(jù)傳輸影響
      • (二)數(shù)據(jù)傳輸時間延遲
    • 三、總結(jié)

一、話題通信機制解析

在這里插入圖片描述

1、話題通信機制簡介

(1)首先,發(fā)布節(jié)點把消息發(fā)布,消息進入Publisher的消息隊列,同時通知訂閱了該話題消息的Subscriber來取消息。
(2)其次,Subscriber來Publisher的消息隊列里取消息,但取走的也是最老的消息,因為畢竟這是先入先出的隊列。
(3)最后,被取走的消息存放入了Subscriber的消息隊列中,等待被Callback執(zhí)行。如果Callback執(zhí)行很慢,消息越堆越多,最老的消息會逐漸被頂替。

2、消息隊列分析

Publisher和Subscriber設(shè)置消息隊列,都可以從兩點進行分析:

  • 話題通信屬于異步通信,隊列可以存儲一定量的歷史數(shù)據(jù)
  • 網(wǎng)絡(luò)傳輸異常的時候,隊列可以預(yù)先進行緩存

(1)為什么需要設(shè)置Publisher的消息隊列?

  • 話題通信屬于異步通信,publisher節(jié)點發(fā)布消息,有多個Subscriber節(jié)點進行訂閱,因此需要有一個地方對消息進行緩存。
  • 網(wǎng)絡(luò)傳輸差、延時突然高的時候,可以把消息放在Publisher的隊列中進行暫存。

(2)為什么要設(shè)置Subscriber消息隊列?

  • Subscriber消息隊列提供一邊處理數(shù)據(jù)一邊緩存新消息的機制。Publisher和Subscriber不一定在同一臺主機上,但是網(wǎng)絡(luò)的性能時好時壞,如果Subscriber沒有消息隊列。如果沒有Subscriber消息隊列,那么程序每次運行Callback函數(shù)前都要先通過網(wǎng)絡(luò)取回消息,然后才能處理,當(dāng)網(wǎng)絡(luò)很差的時候就會造成系統(tǒng)的阻塞。

3、使用技巧

(1)隊列長度queue_size參數(shù)選擇

參考:http://wiki.ros.org/rospy/Overview/Publishers%20and%20Subscribers#Choosing_a_good_queue_size

  • 當(dāng)queue_size=0,即ROS消息隊列為0時,表示為無限隊列長度,內(nèi)存使用量可以無限增長,因此不推薦使用。
  • 當(dāng)兩個queue_size=1時,那么系統(tǒng)不會緩存數(shù)據(jù),自然處理的就是最新的消息。
  • 當(dāng)queue_size設(shè)置為10或者更多時候,用戶更不容易錯過發(fā)布的消息,適用于與人交互的用戶界面的數(shù)據(jù)展示。

(2)ros::spinOnce機制

  • 一次 ros::spinOnce()會獲取完所有Subscriber隊列中的消息

二、實驗驗證

實驗過程比較繁雜,可以直接看第三部分:總結(jié)

(一)subscriber隊列長度對數(shù)據(jù)傳輸影響

1、實驗?zāi)康?/p>

測試什么狀態(tài)下隊列會溢出

2、實驗結(jié)論

結(jié)論一:
當(dāng)回調(diào)函數(shù)處理時長小于數(shù)據(jù)發(fā)布的時間間隔,數(shù)據(jù)可以完整地傳輸。
結(jié)論二:
subscriber隊列可以對接收數(shù)據(jù)進行緩存,spinonce每次進入回調(diào)函數(shù),會取出Subscriber隊列中最新的數(shù)據(jù)

3、詳細(xì)實驗過程
測試一:
1)條件設(shè)置

  • 數(shù)據(jù)發(fā)布為5Hz
  • 回調(diào)函數(shù)執(zhí)行時間為0.19s

2)測試代碼:

#include<ros/ros.h>
#include<ros/time.h>
#include"std_msgs/Int8.h"int main(int argc,char **argv)
{ros::init(argc,argv,"test_publisher");ros::NodeHandle node;//控制隊列長度ros::Publisher num_pub = node.advertise<std_msgs::Int8>("num",1);//控制Publisher發(fā)送頻率ros::Rate loop_rate(5);int count=0;while(ros::ok()){std_msgs::Int8 msg;msg.data=count;num_pub.publish(msg);std::cout<<"I send:"<<count<<"   "<<"Time:"<<ros::Time::now()<<std::endl;count++;ros::spinOnce();loop_rate.sleep();}}
#include"ros/ros.h"
#include<ros/time.h>
#include <ros/duration.h>
#include"std_msgs/Int8.h"void numcallback(const std_msgs::Int8::ConstPtr& msg)
{ROS_INFO("I heard:[%d]",msg->data);std::cout<<"Time:"<<ros::Time::now()<<std::endl;ros::Duration(0.19).sleep();}int main(int argc,char **argv)
{ros::init(argc,argv,"test_subscriber");ros::NodeHandle node;ros::Subscriber sub=node.subscribe("num", 5, numcallback);//subscriber節(jié)點數(shù)據(jù)訂閱頻率while(ros::ok()){ros::spinOnce();}
}

3)測試結(jié)果:

I send:0   Time:1651218272.909345283
I send:1   Time:1651218273.109455274
I send:2   Time:1651218273.309404860
I send:3   Time:1651218273.509534306
I send:4   Time:1651218273.709532966
I send:5   Time:1651218273.909548481
I send:6   Time:1651218274.109474975
I send:7   Time:1651218274.309555626
I send:8   Time:1651218274.509553033
I send:9   Time:1651218274.709557666
I send:10   Time:1651218274.909548771
I send:11   Time:1651218275.109466288
I send:12   Time:1651218275.309543458
I send:13   Time:1651218275.509558336
I send:14   Time:1651218275.709546293
[ INFO] [1651218273.309568749]: I heard:[2]
Time:1651218273.310396018
[ INFO] [1651218273.509881431]: I heard:[3]
Time:1651218273.509977833
[ INFO] [1651218273.709862283]: I heard:[4]
Time:1651218273.709933310
[ INFO] [1651218273.909996336]: I heard:[5]
Time:1651218273.910075954
[ INFO] [1651218274.109691506]: I heard:[6]
Time:1651218274.109723500
[ INFO] [1651218274.309999529]: I heard:[7]
Time:1651218274.310088643
[ INFO] [1651218274.509997999]: I heard:[8]
Time:1651218274.510090090
[ INFO] [1651218274.709979046]: I heard:[9]
Time:1651218274.710068361
[ INFO] [1651218274.909994015]: I heard:[10]
Time:1651218274.910081014
[ INFO] [1651218275.109661000]: I heard:[11]
Time:1651218275.109693420
[ INFO] [1651218275.309972661]: I heard:[12]
Time:1651218275.310058529
[ INFO] [1651218275.509988978]: I heard:[13]
Time:1651218275.510075436
[ INFO] [1651218275.709965890]: I heard:[14]
Time:1651218275.710054172

測試二:
1)測試條件

  • 數(shù)據(jù)發(fā)布為5Hz
  • 回調(diào)函數(shù)執(zhí)行時間為1s

2)測試代碼:
同測試一代碼,ros::Duration(0.19).sleep();修改為ros::Duration(1).sleep();
3)測試結(jié)果:

I send:0   Time:1651218738.926879714
I send:1   Time:1651218739.126986022
I send:2   Time:1651218739.326976590
I send:3   Time:1651218739.527334121
I send:4   Time:1651218739.727314856
I send:5   Time:1651218739.927253191
I send:6   Time:1651218740.127338630
I send:7   Time:1651218740.327119437
I send:8   Time:1651218740.527310282
I send:9   Time:1651218740.727320096
I send:10   Time:1651218740.927319061
I send:11   Time:1651218741.127077520
I send:12   Time:1651218741.327314284
I send:13   Time:1651218741.527084625
I send:14   Time:1651218741.727320603
I send:15   Time:1651218741.927310977
I send:16   Time:1651218742.127316121
I send:17   Time:1651218742.327314879
I send:18   Time:1651218742.527084705
I send:19   Time:1651218742.727317344
I send:20   Time:1651218742.927309793
I send:21   Time:1651218743.127181334
I send:22   Time:1651218743.327346438
I send:23   Time:1651218743.526975577
I send:24   Time:1651218743.727310035
I send:25   Time:1651218743.926981510
I send:26   Time:1651218744.127081416
I send:27   Time:1651218744.327057619
[ INFO] [1651218739.327222543]: I heard:[2]
Time:1651218739.328122020
[ INFO] [1651218740.328379711]: I heard:[3]
Time:1651218740.328493901
[ INFO] [1651218741.328750504]: I heard:[8]
Time:1651218741.328841823
[ INFO] [1651218742.329083810]: I heard:[13]
Time:1651218742.329179718
[ INFO] [1651218743.329413185]: I heard:[18]
Time:1651218743.329527079
[ INFO] [1651218744.329811444]: I heard:[23]
Time:1651218744.329907939
[ INFO] [1651218745.330186229]: I heard:[24]
Time:1651218745.330278204
[ INFO] [1651218746.330738718]: I heard:[25]
Time:1651218746.330852786
[ INFO] [1651218747.331349463]: I heard:[26]
Time:1651218747.331466039
[ INFO] [1651218748.331944456]: I heard:[27]
Time:1651218748.332064212

(二)數(shù)據(jù)傳輸時間延遲

1、實驗?zāi)康?/p>

測試同一平臺下,節(jié)點發(fā)布訂閱之間的延遲

2、實驗結(jié)論

1)同一平臺上,發(fā)布與訂閱節(jié)點之間存在延遲時間:大概為0.2ms
2)先運行訂閱者節(jié)點,后運行發(fā)布者節(jié)點也會存在數(shù)據(jù)丟失,說明:訂閱者與發(fā)布者剛建立連接時需要大致0.5s的時間

3、詳細(xì)實驗過程

//測試
publisher節(jié)點:5HZ發(fā)送數(shù)據(jù)
subscriber節(jié)點:循環(huán)無延遲接收
publisher隊列長度:1
subscriber隊列長度:1

訂閱者節(jié)點程序:

#include"ros/ros.h"
#include<ros/time.h>
#include"std_msgs/Int8.h"void numcallback(const std_msgs::Int8::ConstPtr& msg)
{ROS_INFO("I heard:[%d]",msg->data);std::cout<<"Time:"<<ros::Time::now()<<std::endl;	
}int main(int argc,char **argv)
{ros::init(argc,argv,"test_subscriber");ros::NodeHandle node;ros::Subscriber sub=node.subscribe("num", 1 , numcallback);//subscriber節(jié)點數(shù)據(jù)訂閱頻率//ros::Rate loop_rate(1);while(ros::ok()){ros::spinOnce();//	loop_rate.sleep();	}
}
I send:0   Time:1651205837.321564955
I send:1   Time:1651205837.521682618
I send:2   Time:1651205837.721703296
I send:3   Time:1651205837.921677835
I send:4   Time:1651205838.121677621
I send:5   Time:1651205838.321678661
I send:6   Time:1651205838.521629560
I send:7   Time:1651205838.721682315
I send:8   Time:1651205838.921686516
I send:9   Time:1651205839.121680353
I send:10   Time:1651205839.321681521
I send:11   Time:1651205839.521680580
I send:12   Time:1651205839.721678035
I send:13   Time:1651205839.921678646
I send:14   Time:1651205840.121678181
I send:15   Time:1651205840.321680872
I send:16   Time:1651205840.521679562
I send:17   Time:1651205840.721690948
I send:18   Time:1651205840.921680647
I send:19   Time:1651205841.121677714
I send:20   Time:1651205841.321677517
I send:21   Time:1651205841.521679494
I send:22   Time:1651205841.721680698
I send:23   Time:1651205841.921687221
[ INFO] [1651205837.721951989]: I heard:[2]
Time:1651205837.722832444
[ INFO] [1651205837.921802016]: I heard:[3]
Time:1651205837.921839834
[ INFO] [1651205838.121838956]: I heard:[4]
Time:1651205838.121857432
[ INFO] [1651205838.321856591]: I heard:[5]
Time:1651205838.321874992
[ INFO] [1651205838.521779574]: I heard:[6]
Time:1651205838.521797385
[ INFO] [1651205838.721839387]: I heard:[7]
Time:1651205838.721876415
[ INFO] [1651205838.921855876]: I heard:[8]
Time:1651205838.921891244
[ INFO] [1651205839.121832170]: I heard:[9]
Time:1651205839.121883353
[ INFO] [1651205839.321850889]: I heard:[10]
Time:1651205839.321871226
[ INFO] [1651205839.521831303]: I heard:[11]
Time:1651205839.521865618
[ INFO] [1651205839.721848060]: I heard:[12]
Time:1651205839.721867795
[ INFO] [1651205839.921843985]: I heard:[13]
Time:1651205839.921864013
[ INFO] [1651205840.121845232]: I heard:[14]
Time:1651205840.121864557
[ INFO] [1651205840.321851113]: I heard:[15]
Time:1651205840.321871289
[ INFO] [1651205840.521843675]: I heard:[16]
Time:1651205840.521862573
[ INFO] [1651205840.721814996]: I heard:[17]
Time:1651205840.721868193
[ INFO] [1651205840.921852729]: I heard:[18]
Time:1651205840.921871924
[ INFO] [1651205841.121849661]: I heard:[19]
Time:1651205841.121867539
[ INFO] [1651205841.321848846]: I heard:[20]
Time:1651205841.321866561
[ INFO] [1651205841.521847632]: I heard:[21]
Time:1651205841.521864884
[ INFO] [1651205841.721849989]: I heard:[22]
Time:1651205841.721867769
[ INFO] [1651205841.921830872]: I heard:[23]
Time:1651205841.921847805

三、總結(jié)

1、數(shù)據(jù)發(fā)布到緩存到訂閱者隊列的時間是很短的,大約為0.5ms,如果對數(shù)據(jù)實時性要求比較高,發(fā)布者和訂閱者的隊列長度均需要設(shè)置為1;
2、回調(diào)函數(shù)處理數(shù)據(jù)時間過長,subscriber隊列數(shù)據(jù)堆積,并可能導(dǎo)致數(shù)據(jù)丟失。每次執(zhí)行回調(diào)函數(shù)時,會從subscriber隊列選取最老的數(shù)據(jù)。

http://aloenet.com.cn/news/39299.html

相關(guān)文章:

  • 網(wǎng)站子頁怎么做如何能查到百度搜索排名
  • 北京大學(xué)學(xué)術(shù)學(xué)風(fēng)建設(shè)網(wǎng)站網(wǎng)站運營優(yōu)化培訓(xùn)
  • 做物流網(wǎng)站的圖片素材關(guān)鍵詞seo是什么意思
  • 縉云做網(wǎng)站廈門seo代理商
  • wordpress企業(yè)網(wǎng)站模板下載seo如何提升排名收錄
  • 網(wǎng)站建設(shè)與網(wǎng)頁設(shè)計今天高清視頻免費播放
  • 鄭州網(wǎng)站推廣¥做下拉去118cr餐飲營銷案例100例
  • 網(wǎng)站建設(shè)維護管理辦法外貿(mào)營銷型網(wǎng)站制作公司
  • 北京網(wǎng)站建設(shè)企業(yè)網(wǎng)站制作蘇州網(wǎng)站關(guān)鍵字優(yōu)化
  • 茂名網(wǎng)站制作百度推廣后臺登錄頁面
  • 做振動盤的企業(yè)網(wǎng)站中國軍事新聞最新消息
  • 網(wǎng)站建設(shè)程序源碼青島網(wǎng)站優(yōu)化公司
  • flash做ppt的模板下載網(wǎng)站有哪些西安網(wǎng)站開發(fā)制作公司
  • 北京網(wǎng)站制作公司建站體驗營銷理論
  • 怎樣做網(wǎng)站-百度邯鄲今日頭條最新消息
  • 百度不收錄網(wǎng)站首頁女教師網(wǎng)課入侵錄屏冫
  • 企業(yè)做網(wǎng)站的申請報告廣州seo網(wǎng)絡(luò)推廣員
  • 離婚協(xié)議書模板 完整版海南seo代理加盟供應(yīng)商
  • 網(wǎng)站交互圖片怎么做的免費搭建網(wǎng)站的軟件
  • 網(wǎng)站開發(fā)維護求職信全球十大搜索引擎排名
  • 網(wǎng)站建設(shè)的最新技術(shù)寧波seo優(yōu)化公司
  • 網(wǎng)絡(luò)代理是干嘛的重慶seo扣費
  • 廣州站桂平網(wǎng)絡(luò)推廣
  • 宿遷建設(shè)局網(wǎng)站win7系統(tǒng)優(yōu)化
  • 禪城網(wǎng)站建設(shè)多少錢網(wǎng)絡(luò)營銷推廣策劃的步驟是什么
  • 高端營銷網(wǎng)站泰州百度公司代理商
  • 代做ppt網(wǎng)站百度知道在線問答
  • 網(wǎng)站靜態(tài)頁面網(wǎng)絡(luò)營銷案例ppt
  • 鹽亭做網(wǎng)站采集站seo提高收錄
  • 研發(fā)一個app費用seo百度發(fā)包工具