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

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

5. rosrun, roslaunch, launch ํŒŒ์ผ

๐Ÿƒโ€โ™‚๏ธ

5. rosrun, roslaunch, launch ํŒŒ์ผ

rosrun & roslaunch


Node๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ๋ฐฉ์‹์—๋Š” ํฌ๊ฒŒ ๋‘๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. roslaunch <package-name> <lauch-file-name.launch>
$ roslaunch gcamp_gazebo gazebo_world.launch 
.xml

2. rosrun <package-name> <executable-file-name>

$ rosrun teleop_twist_keyboard teleop_twist_keyboard.py

์ด ๋‘˜์˜ ์ฐจ์ด์ ์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐํ•ด๋ณด์ž๋ฉด,

rosrun์€ ๋‹จ ํ•˜๋‚˜์˜ Node๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ๊ฒƒ์ด๋ฉฐ,

roslaunch๋Š” launch ํŒŒ์ผ์„ ํ†ตํ•ด ํ•œ๋ฒˆ์— ์—ฌ๋Ÿฌ๊ฐœ์˜ Node๋ฅผ ๋™์‹œ์— ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค.

๐Ÿ’ก
์ด์™€ ๋”๋ถˆ์–ด, ์ด์ „ ์‹œ๊ฐ„์—์„œ ๋ณด์•˜๋“ฏ roslaunch๋Š” roscore๋ฅผ ๋”ฐ๋กœ ์‹คํ–‰์‹œํ‚ค์ง€ ์•Š์•„๋„ rosmaster๋ฅผ ๊ตฌ๋™์‹œ์ผœ์ฃผ์—ˆ์ฃ !

launch file


์ด๋ฒˆ์—๋Š” roslaunch๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ launch file์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ์—์„œ ์ด๋Š” ๋‹ค์Œ ์œ„์น˜์— ์กด์žฌํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

$ cd ~/gcamp_ws/src/gcamp_ros_basic/gcamp_gazebo
$ l
CMakeLists.txt  launch/  meshes/  package.xml  rviz/  urdf/  worlds/

๋‹ค์Œ์˜ ํŒŒ์ผ์ด ๋ฐ”๋กœ launch ํŒŒ์ผ์ธ๋ฐ์š”. ํ•œ๋ฒˆ ๋‚ด์šฉ์„ ์‚ดํŽด๋ด…์‹œ๋‹ค.

  • gazebo_world.launch
<?xml version="1.0" encoding="UTF-8"?>

<launch>

  <!-- Robot pose -->
  <arg name="x" default="0"/>
  <arg name="y" default="0"/>
  <arg name="z" default="0"/>
  <arg name="roll" default="0"/>
  <arg name="pitch" default="0"/>
  <arg name="yaw" default="0"/>

  <arg name="world_name"   default="gcamp_world.world"/>
  <arg name="world_file" default="$(find gcamp_gazebo)/worlds/$(arg world_name)"/>
  <arg name="model_name"   default="tinybot"/>

  <arg name="package_name"  default="gcamp_gazebo" />
  <arg name="path"   value="(find $(arg package_name))" />
  <arg name="dollar" value="$" />
  
  <!-- Launch other relevant files-->
  <include file="$(arg dollar)$(arg path)/launch/robot_description.launch"/>

  <!-- Launch Gazebo World -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="use_sim_time" value="true"/>
    <arg name="debug" value="false"/>
    <arg name="gui" value="true" />
    <arg name="world_name" value="$(arg world_file)"/>
  </include>

  <!-- Spawn My Robot -->
  <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" 
        args="-urdf -param robot_description -model $(arg model_name) 
              -x $(arg x) -y $(arg y) -z $(arg z)
              -R $(arg roll) -P $(arg pitch) -Y $(arg yaw)"/>

  <!--launch rviz-->
  <node pkg="rviz" type="rviz" name="rviz" args="-d $(arg dollar)$(arg path)/rviz/tinybot.rviz"/>

</launch>

์ฒ˜์Œ ๋ณด์…จ๋‹ค๋ฉด ๋†€๋ผ์‹ค ์ˆ˜๋„ ์žˆ๊ฒ ์ง€๋งŒ, ์ฐจ๊ทผ์ฐจ๊ทผ ์‚ดํŽด๋ณด์ฃ .

์ตœ์†Œํ•œ์˜ xml


launchํŒŒ์ผ์€ xml์ด๋ผ๋Š” ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. html์„ ์‚ฌ์šฉํ•ด๋ณด์…จ๋‹ค๋ฉด ์‰ฝ๊ฒŒ ์ตํžˆ์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ๋ฌธ๋ฒ•์— ๋Œ€ํ•ด ๊ฐ„๋žตํ•˜๊ฒŒ ์งš๊ณ  ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๋‹ค.

  1. line์˜ ์‹œ์ž‘๊ณผ ๋, ํƒœ๊ทธ
<tag />

or 

<tag (value)> 
...
</tag>

ํ•œ line์€ /๋กœ ์ข…๋ฃŒ๋จ์„ ์•Œ๋ ค์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์—๋Š” ์œ„์˜ ๋‘๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

2. tag ์ข…๋ฅ˜

  • launch : launch ํŒŒ์ผ์ž„์„ ์•Œ๋ ค์ฃผ๋Š” tag์ž…๋‹ˆ๋‹ค. html์˜ body์™€ ๋น„์Šทํ•˜๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • include : launch ํŒŒ์ผ์—์„œ ๋‹ค๋ฅธ launchํŒŒ์ผ์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž˜ ๋ชจ๋“ˆํ™” ํ•ด๋‘์—ˆ๋‹ค๋ฉด ๋‘๊ณ ๋‘๊ณ  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒ ์ฃ ?
<include file="$(arg dollar)$(arg path)/launch/robot_description.launch"/>
<include file="$(find gazebo_ros)/launch/empty_world.launch">

  • node : ๋‹จ์ผ node๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฒฝ์šฐ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ง์ ‘ ๋งŒ๋“  node๋ฅผ launchํŒŒ์ผ๋กœ ๋งŒ๋“ค๊ณ ์ž ํ•˜๋Š” ๊ฒฝ์šฐ ๋งŽ์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
<node pkg="rviz" type="rviz" name="rviz" args="-d $(arg dollar)$(arg path)/rviz/tinybot.rviz"/>

pkg, type, name์€ ์šฐ์„  ๋„˜์–ด๊ฐ€๊ณ  ๋’ท๋ถ€๋ถ„ ๊ฐ•์ขŒ์—์„œ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

  • arg : ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•˜๋“ฏ์ด, ์ด ํŒŒ์ผ ์•ˆ์—์„œ ์‚ฌ์šฉ๋  argument๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
# argument ์„ค์ •
<arg name="test_arg" value="Hello"/>
<arg name="test_arg2" default="0"/>

# argument ์‚ฌ์šฉ
<arg name="package_name"  default="gcamp_gazebo" />
<arg name="path"   value="(find $(arg package_name))" />

  • includeํ•˜๋Š” launch ํŒŒ์ผ์—๋„ arg๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ด๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
<include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="use_sim_time" value="true"/>
    <arg name="debug" value="false"/>
    <arg name="gui" value="true" />
    <arg name="world_name" value="$(arg world_file)"/>
</include>

์•„๋งˆ empty_world.launch์—๋Š” use_sim_time, debug, gui, world_name๋ผ๋Š” arg๋“ค์ด ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ง์ ‘ ์‚ดํŽด๋ณผ๊นŒ์š”?

$ roscd gazebo_ros
$ cd launch
$ gedit empty_world.launch
๐Ÿ’ก
ํŠน์ • ros ํŒจํ‚ค์ง€๋กœ ์ง„์ž…ํ•˜๊ณ ์ž ํ•  ๋•Œ roscd๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

<?xml version="1.0"?>
<launch>

  <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  <arg name="paused" default="false"/>
  <arg name="use_sim_time" default="true"/>
  <arg name="extra_gazebo_args" default=""/>
  <arg name="gui" default="true"/>
  <arg name="recording" default="false"/>
  <!-- Note that 'headless' is currently non-functional.  See gazebo_ros_pkgs issue #491 (-r arg does not disable
       rendering, but instead enables recording). The arg definition has been left here to prevent breaking downstream
       launch files, but it does nothing. -->
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>
  <arg name="physics" default="ode"/>
  <arg name="verbose" default="false"/>
  <arg name="output" default="screen"/>
  <arg name="world_name" default="worlds/empty.world"/> <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->
  <arg name="respawn_gazebo" default="false"/>
  <arg name="use_clock_frequency" default="false"/>
  <arg name="pub_clock_frequency" default="100"/>
  <arg name="enable_ros_network" default="true" />
  <arg name="server_required" default="false"/>
  <arg name="gui_required" default="false"/>

(...)

$(find pkg)

<include file="$(find gazebo_ros)/launch/empty_world.launch">
<include file="$(find gazebo_ros)/launch/empty_world.launch">

find <package-name>์„ ํ†ตํ•ด ๋‹ค๋ฅธ ํŒจํ‚ค์ง€์— ์žˆ๋Š” ํŒŒ์ผ์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค!!

๐Ÿ’ก
๋‹จ, launch file ์•ˆ์— ์ด๋ ‡๊ฒŒ ๋„ฃ๊ธฐ ์ „์— rosrun์„ ํ†ตํ•ด ์ž‘๋™์— ์ด์ƒ์ด ์—†๋Š”์ง€ ๋จผ์ € ํ™•์ธํ•ด ๋ด์•ผํ•ฉ๋‹ˆ๋‹ค.

3. ์ฃผ์„

์ฃผ์„์€ html๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ <!-- --> ์‚ฌ์ด์— ์˜ค๋Š” ์ฝ”๋“œ๋Š” ๋ฌด์‹œ๋ฉ๋‹ˆ๋‹ค.

๋‹จ, ์ฃผ์˜์‚ฌํ•ญ ํ•˜๋‚˜ ์žˆ์Šต๋‹ˆ๋‹ค. launch ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋ฉด --๊ฐ€ ์ข…์ข… ์“ฐ์ด๊ณค ํ•˜๋Š”๋ฐ์š”. ์ด ๊ฒฝ์šฐ ์ฃผ์„์— ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋‹ˆ ์ฃผ์˜ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

์˜คํ”ˆ์†Œ์Šค ํŒจํ‚ค์ง€๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด launch ํŒŒ์ผ์˜ ๋ถ„์„์„ ํ†ตํ•ด ๋งŽ์€ ๊ฒƒ๋“ค์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋ฐ˜๋Œ€๋กœ ๋งํ•˜๋ฉด, ์—ฌ๋Ÿฌ๋ถ„์ด ๋งŒ๋“ค๊ฒŒ ๋  ํŒจํ‚ค์ง€๋„ launch ํŒŒ์ผ์„ ์ž˜ ์ •๋ฆฌํ•ด๋‘์–ด์•ผ ๊ฐ™์ด ํ˜‘๋ ฅํ•˜๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ๋ณด๋‹ค ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šธ ๊ฒƒ์ž…๋‹ˆ๋‹ค.