1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
| from launch.actions import ExecuteProcess from launch.actions import Shutdown from launch.conditions import IfCondition, UnlessCondition from launch.substitutions import LaunchConfiguration from launch.substitutions import PythonExpression
from scripts import GazeboRosPaths
def generate_launch_description(): cmd = [ 'gzserver', LaunchConfiguration('world'), ' ', _boolean_command('version'), ' ', _boolean_command('verbose'), ' ', _boolean_command('lockstep'), ' ', _boolean_command('help'), ' ', _boolean_command('pause'), ' ', _arg_command('physics'), ' ', LaunchConfiguration('physics'), ' ', _arg_command('play'), ' ', LaunchConfiguration('play'), ' ', _boolean_command('record'), ' ', _arg_command('record_encoding'), ' ', LaunchConfiguration('record_encoding'), ' ', _arg_command('record_path'), ' ', LaunchConfiguration('record_path'), ' ', _arg_command('record_period'), ' ', LaunchConfiguration('record_period'), ' ', _arg_command('record_filter'), ' ', LaunchConfiguration('record_filter'), ' ', _arg_command('seed'), ' ', LaunchConfiguration('seed'), ' ', _arg_command('iters'), ' ', LaunchConfiguration('iters'), ' ', _boolean_command('minimal_comms'), _plugin_command('init'), ' ', _plugin_command('factory'), ' ', _plugin_command('force_system'), ' ', _arg_command('profile'), ' ', LaunchConfiguration('profile'), LaunchConfiguration('extra_gazebo_args'), ] model, plugin, media = GazeboRosPaths.get_paths() if 'GAZEBO_MODEL_PATH' in environ: model += pathsep+environ['GAZEBO_MODEL_PATH'] if 'GAZEBO_PLUGIN_PATH' in environ: plugin += pathsep+environ['GAZEBO_PLUGIN_PATH'] if 'GAZEBO_RESOURCE_PATH' in environ: media += pathsep+environ['GAZEBO_RESOURCE_PATH']
env = { 'GAZEBO_MODEL_PATH': model, 'GAZEBO_PLUGIN_PATH': plugin, 'GAZEBO_RESOURCE_PATH': media }
prefix = PythonExpression([ '"gdb -ex run --args" if "true" == "', LaunchConfiguration('gdb'), '" else "valgrind" if "true" == "', LaunchConfiguration('valgrind'), '" else ""' ])
return LaunchDescription([ DeclareLaunchArgument( 'world', default_value='', description='Specify world file name' ), DeclareLaunchArgument( 'version', default_value='false', description='Set "true" to output version information.' ), DeclareLaunchArgument( 'verbose', default_value='false', description='Set "true" to increase messages written to terminal.' ), DeclareLaunchArgument( 'lockstep', default_value='false', description='Set "true" to respect update rates' ), DeclareLaunchArgument( 'help', default_value='false', description='Set "true" to produce gzserver help message.' ), DeclareLaunchArgument( 'pause', default_value='false', description='Set "true" to start the server in a paused state.' ), DeclareLaunchArgument( 'physics', default_value='', description='Specify a physics engine (ode|bullet|dart|simbody).' ), DeclareLaunchArgument( 'play', default_value='', description='Play the specified log file.' ), DeclareLaunchArgument( 'record', default_value='false', description='Set "true" to record state data.' ), DeclareLaunchArgument( 'record_encoding', default_value='', description='Specify compression encoding format for log data (zlib|bz2|txt).' ), DeclareLaunchArgument( 'record_path', default_value='', description='Absolute path in which to store state data.' ), DeclareLaunchArgument( 'record_period', default_value='', description='Specify recording period (seconds).' ), DeclareLaunchArgument( 'record_filter', default_value='', description='Specify recording filter (supports wildcard and regular expression).' ), DeclareLaunchArgument( 'seed', default_value='', description='Start with a given a random number seed.' ), DeclareLaunchArgument( 'iters', default_value='', description='Specify number of iterations to simulate.' ), DeclareLaunchArgument( 'minimal_comms', default_value='false', description='Set "true" to reduce TCP/IP traffic output.' ), DeclareLaunchArgument( 'profile', default_value='', description='Specify physics preset profile name from the options in the world file.' ), DeclareLaunchArgument( 'extra_gazebo_args', default_value='', description='Extra arguments to be passed to Gazebo' ),
DeclareLaunchArgument( 'gdb', default_value='false', description='Set "true" to run gzserver with gdb' ), DeclareLaunchArgument( 'valgrind', default_value='false', description='Set "true" to run gzserver with valgrind' ), DeclareLaunchArgument( 'init', default_value='true', description='Set "false" not to load "libgazebo_ros_init.so"' ), DeclareLaunchArgument( 'factory', default_value='true', description='Set "false" not to load "libgazebo_ros_factory.so"' ), DeclareLaunchArgument( 'force_system', default_value='true', description='Set "false" not to load "libgazebo_ros_force_system.so"' ), DeclareLaunchArgument( 'server_required', default_value='false', description='Set "true" to shut down launch script when server is terminated' ), ExecuteProcess( cmd=cmd, output='screen', additional_env=env, shell=True, prefix=prefix, on_exit=Shutdown(), condition=IfCondition(LaunchConfiguration('server_required')), ),
ExecuteProcess( cmd=cmd, output='screen', additional_env=env, shell=True, prefix=prefix, condition=UnlessCondition(LaunchConfiguration('server_required')), ), ]) def _boolean_command(arg): cmd = ['"--', arg, '" if "true" == "', LaunchConfiguration(arg), '" else ""'] py_cmd = PythonExpression(cmd) return py_cmd
def _arg_command(arg): cmd = ['"--', arg, '" if "" != "', LaunchConfiguration(arg), '" else ""'] py_cmd = PythonExpression(cmd) return py_cmd
def _plugin_command(arg): cmd = ['"-s libgazebo_ros_', arg, '.so" if "true" == "', LaunchConfiguration(arg), '" else ""'] py_cmd = PythonExpression(cmd) return py_cmd
|