Skip to content

ROS1 launch

Francesco Ganci edited this page Jun 25, 2022 · 6 revisions

ros launch — cheatsheet

⚠️ Italian version, not yet reviewed ⚠️

🔗 original on Notion (not up to date)

🔗 vedi pagina wiki sul package roslaunchroslaunch - ROS Wiki

In generale

  • un launch file è un file con formato .launch e sintassi XML
  • i launch file sono contenuti nella cartella launch del package (crea se non esiste)
  • i launch file possono fare riferimento a tutti gli altri nodi esistenti di ROS

Interpretazione di un launch file

  • il launch file viene eseguito blocco per blocco in sequenza
  • per dichiarazioni multiple dello stesso parametro in un launch file, l’ultima dichiarazione fatta vince (verride delle dichiarazioni, evita di usarlo)

🖥️ ROSlaunch command line

In generale vedi → roslaunch/Commandline Tools - ROS Wiki

Lanciare un .launch file

# lancia un launch file (sintassi come rosrun)
roslaunch <package-name> <launch-filename> [args]

# lancia un launch file dato il suo path
roslaunch <launch-file-paths...> [args]

Passare argomenti ad un launch file

per la parte XML vedi → roslaunch/XML/arg - ROS Wiki

per il remapping vedi anche → Nodes - ROS Wiki

# REMAPPING ARGUMENTS -- SOLO SE IL LAUNC FILE NE SPECIFICA
arg:=value

# example: remap the 'chatter' topic/service with '/wg/chatter'
rosrun rospy_tutorials talker chatter:=/wg/chatter

Opzioni del comando roslaunch

# attendi fin quando un 'roscore' non viene rilevato
--wait

# connettiti al roscore tramite una porta specifica
-p <portno>

# forza tutti gli output a schermo
--screen
# forza tutti gli output su log
--log
# forza verbose princing
-v 

# forza tutti i nodi come required
--required

Query sui file .launch

# stampa tutti i launch file richiamati da quello indicato
roslaunch --files <launchfile>

# lista dei nodi richiamati da un launch file
roslaunch --nodes <launchfile>

# lista dei parametri accettati dal launch file
roslaunch --ros-args <launchfile>

# lista delle dipendenze indicate da un launch file
roslaunch-deps -v <launchfile>
# output semplificato (solo warning per le dept mancanti)
roslaunch-deps -w <launchfile>

# cartella col log riferito all'ultimo roslaunch effettuato
roslaunch-logs

Tutte le opzioni di roslaunch

Options:
  -h, --help            show this help message and exit
  --files               Print list files loaded by launch file, including launch file itself
  --args=NODE_NAME      Print command-line arguments for node
  --nodes               Print list of node names in launch file
  --find-node=NODE_NAME
                        Find launch file that node is defined in
  -c NAME, --child=NAME
                        Run as child service 'NAME'. Required with -u
  --local               Do not launch remote nodes
  --screen              Force output of all local nodes to screen
  --required            Force all nodes to be required
  --log                 Force output of all local nodes to log
  -u URI, --server_uri=URI
                        URI of server. Required with -c
  --run_id=RUN_ID       run_id of session. Required with -c
  --wait                wait for master to start before launching
  -p PORT, --port=PORT  master port. Only valid if master is launched
  --core                Launch core services only
  --pid=PID_FN          write the roslaunch pid to filename
  -v                    verbose printing
  --no-summary          hide summary printing
  --dump-params         Dump parameters of all roslaunch files to stdout
  --skip-log-check      skip check size of log folder
  --ros-args            Display command-line arguments for this launch file
  --disable-title       Disable setting of terminal title
  -w NUM_WORKERS, --numworkers=NUM_WORKERS
                        override number of worker threads. Only valid for core services.
  -t TIMEOUT, --timeout=TIMEOUT
                        override the socket connection timeout (in seconds). Only valid for core services.
  --master-logger-level=MASTER_LOGGER_LEVEL
                        set rosmaster.master logger level ('debug', 'info', 'warn', 'error', 'fatal')
  --sigint-timeout=SIGINT_TIMEOUT
                        the SIGINT timeout used when killing nodes (in seconds).
  --sigterm-timeout=SIGTERM_TIMEOUT
                        the SIGTERM timeout used when killing nodes if SIGINT does not stop the node (in seconds).

📄 XML .launch files

Impostazione generale di un launch file

<?xml version="1.0"?>
<launch>
	<!-- nodi e altri launch files... -->
</launch>

Substitution args

vedi questa wiki per i substitution args → roslaunch/XML - ROS Wiki

<!--  -->

<!-- ritorna una variabile d'ambiente -->
<!-- ERRORE se la variabile non è stata settata -->
$(env ENVIRONMENT_VARIABLE)

<!-- ritorna una variabile d'ambiente se settata -->
<!-- RITORNA STRINGA VUOTA se la variabile non è stata settata -->
$(optenv ENVIRONMENT_VARIABLE) 
<!-- la stessa cosa, ma ritorna un valore di default in caso la env non fosse stata definita -->
$(optenv ENVIRONMENT_VARIABLE default_value)
<!-- ad esempio -->
<param name="foo" value="$(optenv NUM_CPUS 1)" />

<!-- trova il percorso completo di un certo package ROS -->
$(find pkg)

<!-- usa un parametro specificato in un precedente 'arg' -->
<!-- <param name="my_foo" value="value_of_my_foo" /> -->
<!-- <arg name="my_foo" default="value_of_my_foo" />
<param name="foo" value="$(arg my_foo)" />

Remapping di topic e service da launch file

vedi pagina in merito → ROS Topic Remap [Example] - The Robotics Back-End (roboticsbackend.com)

usa il tag <env> :

<launch>
    <remap from="topic1" to="topic2" />
    <node name="publisher_node" pkg="my_robot_tutorials" type="publisher.py" />
</launch>

Tags

Launch

Il tag launch è il primissimo tag che apre e chiude un Launch file.

<!-- launch normale -->
<launch>
	<!-- ... -->
</launch>

<!-- launch con deprecated notice -->
<launch deprecated="deprecation message">
	<!-- ... -->
</launch>

Node

Il tag node serve per lanciare singoli nodi ROS.

<!-- forma semplice -->
<node 
	name="nodename" 
	pkg="rospackage" 
	type="..." />

Opzioni principali:

  • name : il nome del nodo da lanciare
  • pkg : il package che contiene il node
  • type : per i nodi roscpp il type corrisponde al filename, mentre per i nodi py il nome corrisponde al filename con estensione .py

Altre opzioni:

  • required="true" : interrompi il ROS launch se non è possibile lanciare il nodo indicato

  • output="log|screen" : forza l’output sul log | a schermo nella console che esegue il launch file

  • args="arg1 arg2 arg3" : argomenti da linea di comando

    <node 
    	name="add_two_ints_client" 
    	pkg="beginner_tutorials" 
    	type="add_two_ints_client" 
    	args="$(arg a) $(arg b)" />
  • respawn="true" : riapri il nodo quando si chiude (default: false)

    • respawn_delay="30" : per impostare dopo quanti secondi lanciare nuovamente il nodo

Param e Arg

vedi tag <param> nella wiki → roslaunch/XML/param - ROS Wiki

vedi tag <arg> nella wiki → roslaunch/XML/arg - ROS Wiki

<!-- definizione di param pubblico -->
<launch>
	<!-- ... -->
	<param ... />
	<!-- ... -->
</launch>

<!-- definizione di param privato (dentro il tag node) -->
<launch>
	<!-- ... -->
	<node ... >
		<!-- ... -->
		<param ... />
		<!-- ... -->
	</node>
	<!-- ... -->
</launch>

<!-- esempio tipico -->
<param name="publish_frequency" type="double" value="10.0" />
<!-- caricamento parametri da un file YAML -->
<rosparam command="load" file="FILENAME" />

<!-- dichiarazione di argomento (errore se non definita) -->
<arg name="foo" />
<!-- dichiarazione di argomento (imposta il valore default se non definita) -->
<arg name="foo" default="1" />
<!-- dichiarazione di CONST argomento (errore in caso di override) -->
<arg name="foo" value="bar" />
<!-- per documentare un argomento, usa questo -->
<arg ... doc="description for this arg" />

<!-- un esempio di propagazione di un argomento a parametro -->
<launch>
  <!-- declare arg to be passed in -->
  <arg name="hoge" /> 

  <!-- read value of arg -->
  <param name="param" value="$(arg hoge)"/>
</launch>

Include

📎 to know more, see this page

<include file="$(pkg your_pkg)/launch/mylaunchfile.launch" />

a more interesting example of include statement.

  <include file="your/launch/file.launch">
    <!-- you can define here your args to pass to the launch file -->
    <!-- <arg name="..." value="..."/> -->
   
    <!-- also environment vars can be given here -->
    <!-- <env name="..." value="..."/> -->
  </include>

Other options for this tag:

  • ns="your_group_namespace" : group the nodes inside a given namespace

📚 Parameter server da launch file

vedi wiki → roslaunch/XML - ROS Wiki

<?xml version="1.0"?>
<launch>
  <param name="somestring1" value="bar" />
  <!-- force to string instead of integer -->
  <param name="somestring2" value="10" type="str" />

  <param name="someinteger1" value="1" type="int" />
  <param name="someinteger2" value="2" />

  <param name="somefloat1" value="3.14159" type="double" />
  <param name="somefloat2" value="3.0" />

  <!-- you can set parameters in child namespaces -->
  <param name="wg/childparam" value="a child namespace parameter" />

  <!-- upload the contents of a file to the server -->
  <param name="configfile" textfile="$(find roslaunch)/example.xml" />
  <!-- upload the contents of a file as base64 binary to the server -->
  <param name="binaryfile" binfile="$(find roslaunch)/example.xml" />

</launch>

Namespaces

📎for further info about namespaces, see the official ROS1 Wiki

Groups and Namespaces give you the possibility of launching multiple instances of the same node working with different topics.

nodes under a given namespace

<arg name="nsp" default="my_namespace" />

<group ns="$(arg nsp)" >
    <!-- launch a bunch of nodes as usual (or, better, include a launch file) -->
</group>