設(shè)置消息信息
ROS 消息是結(jié)構(gòu)??梢灾苯訌椭扑鼈円陨尚碌南?。副本和原始消息都有自己的數(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ā)布者、訂閱者和服務。
參見“與ROS發(fā)布者和訂閱者交換數(shù)據(jù)”和“調(diào)用和提供ROS服務”示例。然后就可以通過publish發(fā)布我們設(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)注
189文章
3001瀏覽量
234149 -
數(shù)據(jù)
+關(guān)注
關(guān)注
8文章
7256瀏覽量
91891 -
ROS
+關(guān)注
關(guān)注
1文章
288瀏覽量
17752
發(fā)布評論請先 登錄
系統(tǒng)鏡像Ubuntu_ROS2中ROS2是什么意思,帶有ROS2開發(fā)環(huán)境嗎?
ROS與RPLIDAR結(jié)合使用說明及問題匯總
在Android中使用ROS
ROS與STM32之間的聯(lián)系
如何在ROS2中運行小烏龜呢
ROS簡介
基于FreeRTOS的micro(微型)ROS

ROS中的序列化實現(xiàn)
ROS中XMLRPC是什么
如何初始化ROS并創(chuàng)立鏈接

ROS中的TF該如何使用

ros的基本概念是什么
ROS2中自帶例程測試

在TogetherROS中如何安裝ROS2功能包

評論