設(shè)置消息信息
ROS 消息是結(jié)構(gòu)??梢灾苯訌?fù)制它們以生成新的消息。副本和原始消息都有自己的數(shù)據(jù)。創(chuàng)建一條類型為geometry_msgs/Twist的消息。
twist = rosmessage("geometry_msgs/Twist","DataFormat","struct")
twist = struct with fields:
MessageType: ‘geometry_msgs/Twist’
Linear: [1x1 struct]
Angular: [1x1 struct]
缺省情況下,此消息的數(shù)字字段初始化為0。您可以修改此消息的任何屬性。例如Y等于5。
twist.Linear.Y = 5;
查看消息數(shù)據(jù)以確保您的更改生效
twist.Linear
ans = struct with fields:
MessageType: ‘geometry_msgs/Vector3’
X: 0
Y: 5
Z: 0
一旦用您的數(shù)據(jù)填充了消息,您就可以將其用于發(fā)布者、訂閱者和服務(wù)。
參見“與ROS發(fā)布者和訂閱者交換數(shù)據(jù)”和“調(diào)用和提供ROS服務(wù)”示例。然后就可以通過publish發(fā)布我們?cè)O(shè)置的消息信息了
thermometerNode = ros2node("/thermometer");
tempPub = ros2publisher(thermometerNode,"/twist","sensor_msgs/geometry_msgs/Twist");
tempMsgs(10) = twist; % Pre-allocate message structure array
for iMeasure = 1:10
% Copy blank message fields
tempMsgs(iMeasure) = twist;
% Record sample message
tempMsgs(iMeasure).Linear.Y = 20+randn*3;
% Only calculate the variation once sufficient data observed
if iMeasure >= 5
tempMsgs(iMeasure).Linear.X= var([tempMsgs(1:iMeasure).Linear.Y]);
end
% Pass the data to subscribers
send(tempPub,tempMsgs(iMeasure))
end
errorbar([tempMsgs.Linear.Y],[tempMsgs.Linear.X])
-
matlab
+關(guān)注
關(guān)注
186文章
2981瀏覽量
231090 -
數(shù)據(jù)
+關(guān)注
關(guān)注
8文章
7167瀏覽量
89691 -
ROS
+關(guān)注
關(guān)注
1文章
280瀏覽量
17126
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
系統(tǒng)鏡像Ubuntu_ROS2中ROS2是什么意思,帶有ROS2開發(fā)環(huán)境嗎?
ROS與RPLIDAR結(jié)合使用說明及問題匯總
在Android中使用ROS
超詳細(xì) ROS安裝教程
ROS與STM32之間的聯(lián)系
如何在ROS2中運(yùn)行小烏龜呢
ROS簡(jiǎn)介
ROS中的序列化實(shí)現(xiàn)
ROS中XMLRPC是什么
如何初始化ROS并創(chuàng)立鏈接
![如何初始化<b class='flag-5'>ROS</b>并創(chuàng)立鏈接](https://file1.elecfans.com/web2/M00/B0/31/wKgZomVUjN6AFUPCAAFTi0fVlH4539.jpg)
ROS中的TF該如何使用
![<b class='flag-5'>ROS</b><b class='flag-5'>中</b>的TF該如何使用](https://file1.elecfans.com/web2/M00/B2/0D/wKgZomVdyAiANzofAADxPMylMsU065.jpg)
ros的基本概念是什么
ROS2中自帶例程測(cè)試
![<b class='flag-5'>ROS</b>2<b class='flag-5'>中</b>自帶例程測(cè)試](https://file1.elecfans.com/web2/M00/B3/53/wKgZomVlo_CAd--WAABWL4F62os161.jpg)
在TogetherROS中如何安裝ROS2功能包
![在TogetherROS<b class='flag-5'>中</b>如何安裝<b class='flag-5'>ROS</b>2功能包](https://file1.elecfans.com/web2/M00/B3/F9/wKgZomVpj5WACHnRAAY288PAUoU611.jpg)
評(píng)論