IfCondition(PythonExpression()) - am I doing it right?
I'm trying to write a launch script to allow me to say ros2 launch foo.launch.py bag_full_path:=/v1_bags/foo.bag bag_version:=v1
and ros2 launch foo.launch.py bag_full_path:=/v2_bags/bar.bag bag_version:=v2
, but the code I am getting is quite long-winded, so I suspect I am missing a trick or two. This code works, but is ugly:
Ros1BagPlayNode = launch.actions.ExecuteProcess(
cmd=['ros2', 'bag', 'play', '-s', 'rosbag_v2', LaunchConfiguration('bag_full_path')],
name='rosbag_play',
output='log',
condition=IfCondition(PythonExpression(["'", LaunchConfiguration('bag_version'), "' == 'v1'"]))
)
Ros2BagPlayNode = launch.actions.ExecuteProcess(
cmd=['ros2', 'bag', 'play', LaunchConfiguration('bag_full_path')],
name='rosbag_play',
output='log',
condition=IfCondition(PythonExpression(["'", LaunchConfiguration('bag_version'), "' == 'v2'"]))
)
DelayedRosBagPlayNode = launch.actions.TimerAction(
actions = [Ros1BagPlayNode, Ros2BagPlayNode],
period = 5.0 # Delay 5 seconds before launching
)
I know I could instead use is_v1_bag:=T/F
and is_v2_bag:=T/F
, but is there a neater way of testing strings?
BTW, the only other example of this I could find is this Japanese page so perhaps the official repo needs an extra example or two?