๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

4. roscore, rosmaster, rosnode

๐ŸŽ–๏ธ

4. roscore, rosmaster, rosnode

 

์ด์ „ ์‹œ๊ฐ„์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์„ ์‹คํ–‰์‹œ์ผฐ๋˜ ๊ฒƒ์ด ๊ธฐ์–ต๋‚˜์‹œ๋‚˜์š”??

 

$ roslaunch gcamp_gazebo gazebo_world.launch

 

์ด ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋‹ˆ

  • ๋กœ๋ด‡์ด ํฌํ•จ๋œ gazebo๊ฐ€ ์‹คํ–‰๋˜๊ณ 
  • ์—ฌ๋Ÿฌ ์„ผ์„œ์™€ ๋กœ๋ด‡์˜ ์ƒํƒœ๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ๋ณผ ์ˆ˜ ์žˆ๋Š” rviz๋„ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
  • ๊ทธ๋ฆฌ๊ณ  teleop์„ ์‹คํ–‰์‹œ์ผฐ๋”๋‹ˆ, ์ด ๋กœ๋ด‡์„ ์กฐ์ข…ํ•  ์ˆ˜๋„ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

์ด ์ผ๋ จ์˜ ๊ณผ์ •๋“ค์ด ์–ด๋–ป๊ฒŒ ์ด๋ฃจ์–ด์กŒ๋Š”์ง€ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

 

ROS Basic Process


  • ํ„ฐ๋ฏธ๋„์„ ๋‹ค์‹œ ๋ณผ๊นŒ์š”?
$ cd ~/gcamp_ws
$ sds

$ roslaunch gcamp_gazebo gazebo_world.launch 

... logging to /home/kimsooyoung/.ros/log/7f9651be-4e53-11eb-b4c9-9cb6d08bf543/roslaunch-kimsooyoung-XPS-13-9370-32277.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

xacro: in-order processing became default in ROS Melodic. You can drop the option.
started roslaunch server http://localhost:35661/

SUMMARY
========

PARAMETERS
 * /gazebo/enable_ros_network: True
 * /joint_state_publisher/use_gui: False
 * /robot_description: <?xml version="1....
 * /rosdistro: melodic
 * /rosversion: 1.14.10
 * /use_sim_time: True

NODES
  /
    gazebo (gazebo_ros/gzserver)
    gazebo_gui (gazebo_ros/gzclient)
    joint_state_publisher (joint_state_publisher/joint_state_publisher)
    robot_state_publisher (robot_state_publisher/robot_state_publisher)
    rviz (rviz/rviz)
    urdf_spawner (gazebo_ros/spawn_model)

auto-starting new master
process[master]: started with pid [32301]
ROS_MASTER_URI=http://localhost:11311
...

๋ญ”๊ฐ€ ๋งŽ์ด ์‹คํ–‰ ๋œ ๊ฒƒ์ด ๋ณด์ด๋Š”๋ฐ์š”, NODES ๋ถ€๋ถ„์— ์ง‘์ค‘ํ•ด๋ด…์‹œ๋‹ค.

 

์‹คํ–‰๋  ๋ชจ๋“  NODES๋“ค์ด ํ‘œ์‹œ๋˜๊ณ , ROS_MASTER๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

 

 

ROS๋Š” ๊ฐ ํ”„๋กœ์„ธ์Šค๋“ค์„ Node์˜ ๋‹จ์œ„๋กœ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

 

๋…ธ๋“œ๋“ค๋ผ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ ๋ฐ›๊ธฐ ์œ„ํ•ด์„œ๋Š”, ์–ด๋–ค ๋…ธ๋“œ๊ฐ€ ์ƒ๊ฒผ๊ณ , id๋Š” ๋ช‡๋ฒˆ์ด๊ณ  ๋“ฑ์˜ ์ •๋ณด๊ฐ€ ๊ณต์œ ๋˜์–ด์•ผ ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ๊ฒƒ์ด ROS Master๋ผ๊ณ  ์ดํ•ดํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

image from : clearpathrobotics

๐Ÿ’ก
๋” ์ž์„ธํžˆ ๊ณต๋ถ€ํ•ด๋ณด๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹ค์Œ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”!!

roscore command


์ฒ˜์Œ ROS๋ฅผ ์„ค์น˜ํ•œ ๋’ค ์‹คํ–‰์‹œ์ผฐ๋˜ roscore๋Š” ๋ญ˜๊นŒ์š”??

  • ํ„ฐ๋ฏธ๋„์„ ๋‹ค์‹œ ๋ณผ๊นŒ์š”?
started roslaunch server http://localhost:41409/
ros_comm version 1.14.10


SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.10

NODES

auto-starting new master
process[master]: started with pid [3554]
ROS_MASTER_URI=http://localhost:11311/

setting /run_id to 6f20f9e2-4e58-11eb-b4c9-9cb6d08bf543
process[rosout-1]: started with pid [3576]
started core service [/rosout]

roscore๋Š” ROS Master๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ๋ช…๋ น์ž…๋‹ˆ๋‹ค! ROS Master API์— ๋Œ€ํ•ด ๋” ๊ณต๋ถ€ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹ค์Œ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

ROS/Master_API
import os import xmlrpclib caller_id = '/script' m = xmlrpclib.ServerProxy(os.environ['ROS_MASTER_URI']) code, msg, val = m.getSystemState(caller_id) if code == 1: pubs, subs, srvs = val else: print "call failed", code, msg
http://library.isr.ist.utl.pt/docs/roswiki/ROS(2f)Master_API.html

 

  • ROS Master๋Š” ํ•˜๋‚˜๋งŒ ์กด์žฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. roscore๋ฅผ ์—ฌ๋Ÿฌ๋ฒˆ ์‹คํ–‰์‹œํ‚ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
RLException: roscore cannot run as another roscore/master is already running. 
Please kill other roscore/master processes before relaunching.
The ROS_MASTER_URI is http://localhost:11311/
The traceback for the exception was written to the log file

 

  • roslaunch๋ฅผ ํ†ตํ•ด ์‹คํ–‰์‹œํ‚ค๋ฉด, ์ž๋™์œผ๋กœ ROS Master๋„ ํ•จ๊ป˜ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.
$ roslaunch gcamp_gazebo gazebo_world.launch 

(...)
auto-starting new master
process[master]: started with pid [32301]
ROS_MASTER_URI=http://localhost:11311

 

rosnode command


ํ˜„์žฌ ์–ด๋–ค ๋…ธ๋“œ๊ฐ€ ์ž‘๋™์ค‘์ธ์ง€, ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณด๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹ค์Œ ์ปค๋งจ๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

$ roslaunch gcamp_gazebo gazebo_world.launch

# ์ƒˆ ํ„ฐ๋ฏธ๋„์„ ์—ด๊ณ  ๋‹ค์Œ ์ปค๋งจ๋“œ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
$ rosnode list
/gazebo
/gazebo_gui
/joint_state_publisher
/robot_state_publisher
/rosout

gazebo_world.launch๋Š” launch ํŒŒ์ผ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์„ ์‹คํ–‰์‹œํ‚ค๋ฉด ์ž๋™์œผ๋กœ ROS Master๊ฐ€ ์‹คํ–‰๋œ๋‹ค๊ณ  ํ–ˆ์ฃ ? ROS Master์™€ ๊ด€๋ จ์žˆ๋Š” Node๋Š” /rosout ์ž…๋‹ˆ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  ๋‚˜๋จธ์ง€ 4๊ฐœ์˜ Node๋“ค์ด ์‹คํ–‰์ค‘์ธ๋ฐ์š”. gazebo๊ด€๋ จ Node๊ฐ€ 2๊ฐœ, gazebo์ƒ์—์„œ ์šฐ๋ฆฌ์˜ ๋กœ๋ด‡์„ spawn ์‹œํ‚ค๊ณ , ๋กœ๋ด‡์˜ ์—ฌ๋Ÿฌ ์ƒํƒœ๋ฅผ ์ง€์†์ ์œผ๋กœ ์†ก์‹ ํ•˜๋Š” Node๊ฐ€ 2๊ฐœ ์‹คํ–‰์ค‘์ธ ๋ชจ์Šต์ด ๋ณด์ž…๋‹ˆ๋‹ค.

 

  • ํŠน์ • Node์— ๋Œ€ํ•ด์„œ ๋” ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ์–ป๊ณ  ์‹ถ๋‹ค๋ฉด, ๋‹ค์Œ ์ปค๋งจ๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

$ rosnode info /joint_state_publisher
Node [/joint_state_publisher]
Publications: 
 * /joint_states [sensor_msgs/JointState]
 * /rosout [rosgraph_msgs/Log]

Subscriptions: 
 * /clock [rosgraph_msgs/Clock]

Services: 
 * /joint_state_publisher/get_loggers
 * /joint_state_publisher/set_logger_level


contacting node http://localhost:42569/ ...
Pid: 4086
Connections:
 * topic: /joint_states
    * to: /robot_state_publisher
    * direction: outbound (40207 - 127.0.0.1:33150) [14]
    * transport: TCPROS
 * topic: /rosout
    * to: /rosout
    * direction: outbound (40207 - 127.0.0.1:33148) [10]
    * transport: TCPROS
 * topic: /clock
    * to: /gazebo (http://localhost:42511/)
    * direction: inbound
    * transport: TCPROS
(...)

 

๐Ÿ’ก
์œ„ ๋‚ด์šฉ๊ณผ ์™„์ „ ๋™์ผํ•˜๊ฒŒ ๋‚˜์˜ค์ง€ ์•Š์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค!

 

  • ํ•ด๋‹น Node์™€ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ๋‹ค๋ฅธ Node๋“ค์€ ์–ด๋– ํ•œ ๊ฒƒ์ด ์žˆ๋Š”์ง€, ๊ทธ๋ฆฌ๊ณ  ์–ด๋– ํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ์˜ค๊ณ  ๊ฐ€๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋”๋ถˆ์–ด, ์•„์ง ๋ฐฐ์šฐ์ง€ ์•Š์•˜์ง€๋งŒ ์ด Node์—์„œ ํŒŒ์ƒ๋˜๋Š” ๊ทธ ๋ฐ–์˜ ์—ฌ๋Ÿฌ ํ†ต์‹ ๋“ค์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์‚ฌ์‹ค ํ…์ŠคํŠธ๋กœ ๋ณด๊ธฐ๊ฐ€ ๋ถˆํŽธํ•œ ๊ฒƒ์ด ์‚ฌ์‹ค์ž…๋‹ˆ๋‹ค. ์ €์˜ ๊ฒฝ์šฐ, ๊ทธ๋ฆฌ๊ณ  ์•„๋งˆ ๋Œ€๋ถ€๋ถ„ ROS ์‚ฌ์šฉ์ž๋ถ„๋“ค๊ป˜์„œ๋„ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ตฌ์กฐ๋ฅผ ํŒŒ์•…ํ•˜์‹œ์ง€ ์•Š์„๊นŒ ์‹ถ์Šต๋‹ˆ๋‹ค.

 

rqt ๋ง›๋ณด๊ธฐ


$ rqt_graph

QT window๊ฐ€ ํ•˜๋‚˜ ๋“ฑ์žฅํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

์ƒ๋‹จ์— ์—ฌ๋Ÿฌ ์˜ต์…˜๋“ค์ด ๋ณด์ด๋Š”๋ฐ์š”, ๊ฐ ์˜ต์…˜๋“ค์— ๋Œ€ํ•œ ์„ค๋ช…์€ ์šฐ์„  ์ƒ๋žตํ•˜๊ณ , ์ฒดํฌ๋ฐ•์Šค๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์ •ํ•ด๋ด…์‹œ๋‹ค.

 

  • ์ตœ์ข… ํ™”๋ฉด์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

(๊ทธ๋ž˜ํ”„ ๋ฐฐ์น˜ ๊ตฌ์กฐ๋Š” ์ €์™€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์‹ฌ์ง€์–ด ๊ฐ™์€ ํ™˜๊ฒฝ์—์„œ๋„ ๋งค๋ฒˆ ๋ฐ”๋€Œ๊ณค ํ•ฉ๋‹ˆ๋‹ค. ๐Ÿ™‚)

์•ž์„œ ์‚ดํŽด๋ณด์•˜๋˜ Node๋“ค์ด ์–ด๋– ํ•œ ๊ตฌ์กฐ๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ๋Š”์ง€ ์‚ดํŽด๋ณผ ์ˆ˜ ์žˆ์ฃ ?

์ด๋ ‡๊ฒŒ ์ „์ฒด์ ์ธ ๊ตฌ์กฐ๋ฅผ ํŒŒ์•…ํ•˜๊ณ , ๋” ์ž์„ธํ•œ ๋‚ด์šฉ์„ rosnode ์ปค๋งจ๋“œ๋กœ ๋‹ค์‹œ ๊ฒ€์ƒ‰ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

๐Ÿ’ก
ํ™”์‚ดํ‘œ๊ฐ€ ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์€ ๋ฌด์—‡์ผ๊นŒ์š”? ⇒ Node๋“ค ์‚ฌ์ด์— ํ†ต์‹ ์ด ์ด๋ฃจ์–ด์ง€๊ณ  ์žˆ์Œ์„, ํ˜น์€ ์ด๋ฃจ์–ด์กŒ์Œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค! ๋””๋ฒ„๊น…์‹œ ์œ ์šฉํ•˜๊ฒ ์ง€์š”!!

 

  • ์ด์ „ ๊ฐ•์˜์—์„œ, ํ‚ค๋ณด๋“œ๋กœ ๋กœ๋ด‡์„ ์กฐ์ข…ํ•ด๋ดค๋˜ ๊ฒƒ์„ ๊ธฐ์–ตํ•˜์‹œ๋‚˜์š”? ๋‹ค์Œ์˜ ์ปค๋งจ๋“œ๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.
$ rosrun teleop_twist_keyboard teleop_twist_keyboard.py

 

rqt_graph๋ฅผ ๋‹ค์‹œ ์‹คํ–‰์‹œ์ผœ ์–ด๋– ํ•œ ๋ณ€ํ™”๊ฐ€ ์ƒ๊ฒผ๋Š”์ง€ ์‚ดํŽด๋ด…์‹œ๋‹ค.

 

teleop_twist_keyboard ๋ผ๋Š” Node๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค!! ๊ทธ๋ฆฌ๊ณ  /cmd_vel์„ ํ†ตํ•ด /gazebo์™€ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค!!

 

  • ๋‹ค์‹œ, rosnode info๋กœ ๊ตฌ์ฒด์ ์ธ ์ •๋ณด๋ฅผ ์•Œ์•„๋‚ด๋ณผ๊นŒ์š”?
$ rosnode info /teleop_twist_keyboard
--------------------------------------------------------------------------------
Node [/teleop_twist_keyboard]
Publications: 
 * /cmd_vel [geometry_msgs/Twist]
 * /rosout [rosgraph_msgs/Log]

Subscriptions: 
 * /clock [rosgraph_msgs/Clock]

Services: 
 * /teleop_twist_keyboard/get_loggers
 * /teleop_twist_keyboard/set_logger_level


contacting node http://localhost:42905/ ...
Pid: 6480
Connections:
 * topic: /rosout
    * to: /rosout
    * direction: outbound (34171 - 127.0.0.1:45192) [9]
    * transport: TCPROS
 * topic: /cmd_vel
    * to: /gazebo
    * direction: outbound (34171 - 127.0.0.1:45194) [13]
    * transport: TCPROS
 * topic: /clock
    * to: /gazebo (http://localhost:42511/)
    * direction: inbound
    * transport: TCPROS

 

/cmd_vel์ด ์™œ ๋“ฑ์žฅํ–ˆ๊ณ , rosrun์€ ๋˜ ๋ญ๊ณ , ์ด๋“ค์€ ์–ด๋–ป๊ฒŒ ๋งŒ๋“ค๊ณ , ์–ด๋–ป๊ฒŒ ์—ฐ๊ฒฐ์‹œํ‚ค๋Š”์ง€ ๋“ฑ๋“ฑ ์—ฌ๋Ÿฌ ๊ถ๊ธˆ์ฆ๋“ค์ด ์ƒ๊ธฐ์…จ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

๋‹ค์Œ ๊ฐ•์˜๋“ค์—์„œ ๊ณ„์†ํ•ด์„œ ์งš๊ณ  ๋„˜์–ด๊ฐ€๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿ‘๐Ÿ‘๐Ÿ‘