marker主题 ros_(五)ROS主题理解
參考網(wǎng)址:
1,小海龜例子
(1) 在新的終端打開roscore
$ roscore
---如果出錯(cuò),請確定關(guān)閉所有ROS命令或者路徑,重試。
(2) 在新的終端打開運(yùn)行小海龜界面
$ rosrun turtlesim
turtlesim_node
得到結(jié)果:
[ INFO] [1294665184.346950426]: Starting turtlesim with node
name /turtlesim
[ INFO] [1294665184.358498715]: Spawning turtle [turtle1] at
x=[5.555555], y=[5.555555], theta=[0.000000]
此后小海龜運(yùn)行的路徑都記錄在此終端
(3) 在新的終端打開鼠標(biāo)控制終端
$?rosrun turtle_teleop
turtle_teleop_key
將鼠標(biāo)放在此終端界面,然后用鍵盤上的“上,下,左,右”控制小海龜移動,以下是我運(yùn)行的界面,是不是有點(diǎn)像SIAT?
2,ROS 主題
就像小海龜這個(gè)例子,turtlesim_node和turtle_teleop_key 節(jié)點(diǎn)在ROS
主題上進(jìn)行通信,turtle_teleop_key在該主題上發(fā)送key strokes, turtlesim在相同主題上,預(yù)定該key
strokes。我們可以用rxgraph來顯示該節(jié)點(diǎn)和主題間的交流。
(1) 主題顯示
$ rxgraph --在新終端輸入該命令
得到結(jié)果如圖:
下面的圖詮釋了,節(jié)點(diǎn),主題:
(2) rostopic 介紹
I,rostopic -h
$ rostopic -h
得到結(jié)果:
rostopic is a command-line tool for printing information about
ROS Topics.
Commands:
rostopic bw display bandwidth used by topic
rostopic echo print messages to screen
rostopic find find topics by type
rostopic hz display publishing rate of topic
rostopic info print information about active topic
rostopic list list active topics
rostopic pub publish data to topic
rostopic type print topic type
Type rostopic -h for
more detailed usage, e.g. 'rostopic echo -h'
II,rostopic echo [topic]
我們查看/turtel/command_velocity
主題通過turtle_teleop_key節(jié)點(diǎn)發(fā)布的數(shù)據(jù),在新終端輸入:
$ rostopic echo
/turtle1/command_velocity
當(dāng)我們把鼠標(biāo)放在turtle_teleop_key 終端頁面,運(yùn)行小海龜時(shí),得到結(jié)果:
---
linear: 2.0
angular: 0.0
---
linear: 0.0
angular: -2.0
---
linear: 0.0
angular: 2.0
---
linear: -2.0
angular: 0.0
---
linear: 2.0
angular: 0.0
---
linear: 2.0
angular: 0.0
這樣我們再看rxgraph顯示的終端,如下,在INFO欄,顯示了信息
III, rostopic list -h
返回所有主題當(dāng)前預(yù)定和發(fā)布的數(shù)據(jù),子命令如下:
Usage: rostopic list [/namespace]
Options:
-h, --help
show this
help message and exit
-b BAGFILE,
--bag=BAGFILE
list topics in .bag file
-v, --verbose
list full details about each topic
-p ?list only
publishers
-s ?list only
subscribers
例如,查詢當(dāng)前主題的預(yù)定和發(fā)布數(shù)據(jù):
$ rostopic ?list
-v
得到結(jié)果:
Published topics:
* /turtle1/color_sensor [turtlesim/Color] 1
publisher
* /turtle1/command_velocity
[turtlesim/Velocity] 1 publisher
* /rosout [roslib/Log] 3 publishers
* /rosout_agg [roslib/Log] 1 publisher
* /turtle1/pose [turtlesim/Pose] 1
publisher
Subscribed topics:
* /turtle1/command_velocity
[turtlesim/Velocity] 2 subscribers
* /rosout [roslib/Log] 1 subscriber
3,ROS消息
在ROS主題上,是通過消息進(jìn)行通信的。發(fā)布者(turtle_teleop_key)和預(yù)定者(turtlesim_node)之間的通信,發(fā)布者和預(yù)定者發(fā)送和接受的同一類型的消息,這就決定了發(fā)布者決定主題類型。
I, rostopic type [topic]
返回當(dāng)前運(yùn)行主題的消息類型,例如小海龜例子:
$ rostopic type
/turtle1/command_velocity
得到結(jié)果:
turtlesim/Velocity
$rosmsg
show turtlesim/Velocity --查詢消息類型細(xì)節(jié)
得到結(jié)果:
float32
linear float32 angular
4,將消息應(yīng)用到主題上
I,rostopic pub [topic] [msg_type] [args]
將數(shù)據(jù)發(fā)布到當(dāng)前主題上,例如小海龜例子:
$rostopic pub -1 /turtle1/command_velocity turtlesim/Velocity --
2.0 1.8
命令詮釋:
rostopic
pub ---在給定主題上發(fā)布消息
-1
---此選項(xiàng)表示rostopic只發(fā)布一個(gè)消息,然后退出
/turtle1/command_velocity
---給定的主題名
turtlesim/Velocity
---在給定主題上發(fā)布的消息類型
--
---雙負(fù)號,表示詞法選擇器在此后的參數(shù)都不可用。這種情況發(fā)生在錯(cuò)誤參數(shù)比如負(fù)數(shù)
2.0
1.8 ---當(dāng)前主題消息的類型的數(shù)據(jù)值
得到的結(jié)果:
終端顯示:
publishing
and latching message for 3.0 seconds
圖運(yùn)行的結(jié)果是:
另外,如果要保持小海龜一直移動,可以采用-r,例如:
$ rostopic pub /turtle1/command_velocity turtlesim/Velocity -r 1 --
2.0 -1.8
運(yùn)行結(jié)果:
我們查看下rxgraph圖顯示:
我們可以看到小海龜運(yùn)行一個(gè)圈的軌跡。
II,rostopic hz [topic]
是用來報(bào)告哪個(gè)數(shù)據(jù)發(fā)布率,比如小海龜?shù)睦?#xff1a;
$ rostopic hz /turtle1/pose
得到結(jié)果:
subscribed to [/turtle1/pose]
average rate: 44.767
min: 0.000s max: 0.053s std dev: 0.02014s window: 43
average rate: 44.994
min: 0.000s max: 0.054s std dev: 0.02016s window: 87
average rate: 45.382
min: 0.000s max: 0.054s std dev: 0.01993s window: 134
average rate: 45.032
min: 0.000s max: 0.063s std dev: 0.02003s window: 177
average rate: 45.165
min: 0.000s max: 0.063s std dev: 0.01999s window: 224
III,rxplot
是展示畫出該主題上發(fā)布的數(shù)據(jù),比如我們對小海龜轉(zhuǎn)圈,這個(gè)例子
$rxplot
/turtle1/pose/x,/turtle1/pose/y /turtle1/pose/theta
---針對上面圖得到:
總結(jié)
以上是生活随笔為你收集整理的marker主题 ros_(五)ROS主题理解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三国墙头草孟达武艺与结局(孟达是三国里面
- 下一篇: 最大化快捷键是什么(最大最小化快捷键)