Why substitutions in launch files?
Hi!
Let’s take for example the following launch file to which we pass the argument “counter” from the command line.
from launch import LaunchDescription
from launch.actions import LogInfo
from launch.substitutions import LaunchConfiguration
def generate_launch_description():
counter = LaunchConfiguration(‘counter’, default=0)
counter = counter + 1
return LaunchDescription([
LogInfo(
msg=counter,
)
])
When trying to run it, an error occurs due to the line
counter=counter+1
because obviously the counter variable is of type LaunchConfiguration and cannot be converted to an integer. The only way to directly access the value of an argument to be able to perform some operation on it is by using an OpaqueFunction action and within the function that it calls, access the value through an instructions like the following:
value = LaunchConfiguration(‘counter’).perform(context)
value = value + 1
My question is why the launch framework forces to do this. That is, I would like to know what it does internally that makes it necessary to use substitutions. Why couldn’t something similar to .perform(context)
be used outside of an OpaqueFunction
action?
Regards.