def generate_launch_description(): pkg_share = FindPackageShare('crane_plus_description').find('crane_plus_description') urdf_dir = os.path.join(pkg_share, 'urdf') xacro_file = os.path.join(urdf_dir, 'crane_plus.urdf.xacro') doc = xacro.process_file(xacro_file) robot_desc = doc.toprettyxml(indent=' ') params = {'robot_description': robot_desc} rsp = Node(package='robot_state_publisher', executable='robot_state_publisher', output='both', parameters=[params]) jsp = Node( package='joint_state_publisher_gui', executable='joint_state_publisher_gui', output='screen', ) rviz_config_file = get_package_share_directory( 'crane_plus_description') + '/launch/display.rviz' rviz_node = Node(package='rviz2', executable='rviz2', name='rviz2', output='log', arguments=['-d', rviz_config_file]) return LaunchDescription([rsp, jsp, rviz_node])
def generate_launch_description(): xacro_file_name = 'turtlebot3_waffle_base.urdf.xacro' urdf_file_name = 'turtlebot3_waffle_base.urdf' urdf_file = os.path.join(get_package_share_directory('tb3_description'), 'urdf', urdf_file_name) xacro_file = os.path.join(get_package_share_directory('tb3_description'), 'urdf', xacro_file_name) doc = xacro.process_file(xacro_file) robot_desc = doc.toprettyxml(indent=' ') f = open(urdf_file, 'w+') f.write(robot_desc) f.close() return LaunchDescription([ Node( package='robot_state_publisher', node_executable='robot_state_publisher', node_name='robot_state_publisher', output='screen', arguments=[urdf_file], ), Node( package='joint_state_publisher', node_executable='joint_state_publisher', node_name='joint_state_publisher', output='screen', ), ])
def generate_launch_description(): # Get URDF via xacro robot_description_path = os.path.join( get_package_share_directory('ros2_control_kuka_driver'), 'description', 'kr6.urdf.xacro') robot_description_config = xacro.process_file(robot_description_path) robot_description = {'robot_description': robot_description_config.toxml()} rrbot_forward_controller = os.path.join( get_package_share_directory('ros2_control_kuka_driver'), 'controllers', 'kuka_6dof_controller_position.yaml') return LaunchDescription([ Node( package='controller_manager', executable='ros2_control_node', parameters=[robot_description, rrbot_forward_controller], output={ 'stdout': 'screen', 'stderr': 'screen', }, ), Node(package='robot_state_publisher', executable='robot_state_publisher', output='both', parameters=[robot_description]) ])
def generate_launch_description(): robot_description_path = os.path.join( get_package_share_directory('mz25_robot_description'), 'description', 'mz25_arm_vacuum_gripper.urdf.xacro') rviz2_config_path = os.path.join( get_package_share_directory('mz25_robot_description'), 'rviz', 'show.rviz') robot_description_config = xacro.process_file(robot_description_path) robot_description = {'robot_description': robot_description_config.toxml()} return LaunchDescription([ Node(package='robot_state_publisher', executable='robot_state_publisher', name='robot_state_publisher', output='screen', parameters=[{ 'use_sim_time': False }, robot_description]), Node(package='rviz2', executable='rviz2', name='rviz2', output='screen', parameters=[robot_description], arguments=['-d', rviz2_config_path]), Node( package='joint_state_publisher', executable='joint_state_publisher', name='joint_state_publisher', parameters=[{ 'use_gui': True }], output='screen', ), ])
def spawn_ball(self): self.timer.cancel() self.ball_id += 1 ball = Ball(self.ball_id) self.balls[ball.id] = ball xacro_mappings = { "vel_x": str(ball.initial_velocity.linear.x), "vel_y": str(ball.initial_velocity.linear.y), "vel_z": str(ball.initial_velocity.linear.z) } urdf_description = xacro.process_file(self.ball_description_file, mappings=xacro_mappings).toxml() with open("/tmp/test.urdf", "w") as s: s.write(urdf_description) self.spawn_entity_client.call_async( SpawnEntity.Request(name=ball.name, xml=urdf_description, initial_pose=ball.initial_pose)) self.get_logger().info(f"Ball {ball.id} spawned") ball.set_spawned(self.get_clock().now()) self.publish_stats() if len(self.balls) < self.TOTAL_BALL_COUNT: self.timer = self.create_timer(self.SPAWN_BALL_DURATION, self.spawn_ball)
def generate_launch_description(): # Get URDF via xacro robot_description_path = os.path.join( get_package_share_directory('mz25_robot_description'), 'description', 'mz25_arm_vacuum_gripper.urdf.xacro') rviz2_config_path = os.path.join( get_package_share_directory('mz25_robot_description'), 'rviz', 'show.rviz') robot_description_config = xacro.process_file(robot_description_path) robot_description = {'robot_description': robot_description_config.toxml()} forward_controller = os.path.join( get_package_share_directory('mz25_robot_description'), 'controllers', 'mz25_controller_position.yaml') return LaunchDescription([ Node(package='controller_manager', executable='ros2_control_node', parameters=[robot_description, forward_controller], output={ 'stdout': 'screen', 'stderr': 'screen', }, arguments=['--ros-args', '--log-level', 'info']), ExecuteProcess( cmd=['ros2 control load_start_controller mz25_arm_controller'], shell=True, output='screen'), ExecuteProcess( cmd=['ros2 control load_start_controller joint_state_controller'], shell=True, output='screen'), ])
def generate_launch_description(): # Get URDF via xacro robot_description_path = os.path.join( get_package_share_directory('ros2_control_demo_robot'), 'description', 'rrbot_system_position_only.urdf.xacro') robot_description_config = xacro.process_file(robot_description_path) robot_description = {'robot_description': robot_description_config.toxml()} rviz_config_file = os.path.join( get_package_share_directory('ros2_control_demo_robot'), 'rviz', 'rrbot.rviz') joint_state_publisher_node = Node( package='joint_state_publisher_gui', executable='joint_state_publisher_gui', ) robot_state_publisher_node = Node(package='robot_state_publisher', executable='robot_state_publisher', output='both', parameters=[robot_description]) rviz_node = Node( package='rviz2', executable='rviz2', name='rviz2', output='log', arguments=['-d', rviz_config_file], ) return LaunchDescription([ joint_state_publisher_node, robot_state_publisher_node, rviz_node, ])
def generate_launch_description(): pkg_description = FindPackageShare("scaraball_description").find( "scaraball_description") model_file = os.path.join(pkg_description, "urdf", "scaraball.urdf.xacro") pkg_gazebo = FindPackageShare("scaraball_gazebo").find("scaraball_gazebo") gazebo_path = os.path.join( FindPackageShare("gazebo_ros").find("gazebo_ros"), "launch") with open("/tmp/scaraball.urdf", "w") as stream: stream.write(xacro.process_file(model_file).toxml()) robot_state_publisher_node = Node( package='robot_state_publisher', node_executable='robot_state_publisher', arguments=["/tmp/scaraball.urdf"], output='screen', ) gazebo = IncludeLaunchDescription( PythonLaunchDescriptionSource([gazebo_path, '/gazebo.launch.py'])) # GAZEBO_MODEL_PATH has to be correctly set for Gazebo to be able to find the model spawn_entity = Node( package='gazebo_ros', node_executable='spawn_entity.py', arguments=['-entity', 'scaraball', '-topic', "/robot_description"], # arguments = ['-entity', 'my_robot', '-file', "/tmp/my_robot.urdf"], output='screen', ) return LaunchDescription( [gazebo, spawn_entity, robot_state_publisher_node])
def generate_launch_description(): nodes = [ Node( package='swiftpro', node_executable='swiftpro_write_node', node_name='swiftpro_write_node' ), Node( package='swiftpro', node_executable='swiftpro_moveit_node', node_name='swiftpro_moveit_node' ), Node( package='swiftpro', node_executable='swiftpro_rviz_node', node_name='swiftpro_rviz_node' ), ] pkg_share = FindPackageShare('swiftpro').find('swiftpro') urdf_dir = os.path.join(pkg_share, 'urdf') xacro_file = os.path.join(urdf_dir, 'pro_model.xacro') doc = xacro.process_file(xacro_file) robot_desc = doc.toprettyxml(indent=' ') params = {'robot_description': robot_desc} rsp = Node(package='robot_state_publisher', node_executable='robot_state_publisher', output='both', parameters=[params]) nodes.append(rsp) return launch.LaunchDescription(nodes)
def generate_launch_description(): # Get URDF via xacro robot_description_path = os.path.join( get_package_share_directory("ros2_control_demo_robot"), "description", "rrbot_system_multi_interface.urdf.xacro", ) robot_description_config = xacro.process_file(robot_description_path) robot_description = {"robot_description": robot_description_config.toxml()} rrbot_forward_controller = os.path.join( get_package_share_directory("ros2_control_demo_robot"), "config", "rrbot_multi_interface_forward_controllers.yaml", ) return LaunchDescription([ Node( package="controller_manager", executable="ros2_control_node", parameters=[robot_description, rrbot_forward_controller], output={ "stdout": "screen", "stderr": "screen" }, ) ])
def generate_launch_description(): # Check if we're told to use sim time use_sim_time = LaunchConfiguration('use_sim_time') # Process the URDF file pkg_path = os.path.join( get_package_share_directory('articubot_description')) xacro_file = os.path.join(pkg_path, 'robot.urdf.xacro') robot_description_config = xacro.process_file(xacro_file) # Create a robot_state_publisher node params = { 'robot_description': robot_description_config.toxml(), 'use_sim_time': use_sim_time } node_robot_state_publisher = Node( package='robot_state_publisher', executable='robot_state_publisher', # output='screen', parameters=[params]) # Launch! return LaunchDescription([ DeclareLaunchArgument('use_sim_time', default_value='false', description='Use sim time if true'), node_robot_state_publisher ])
def build_single_xacro_file(input_path, output_path): try: # open and process file doc = process_file(input_path) # open the output file out = open_output(output_path) except xml.parsers.expat.ExpatError as e: error("XML parsing error: %s" % unicode(e), alt_text=None) sys.exit(2) except Exception as e: msg = unicode(e) if not msg: msg = repr(e) error(msg) sys.exit(2) # gracefully exit with error condition # write output out.write(doc.toprettyxml(indent=' ', **encoding)) # only close output file, but not stdout out.close()
def generate_launch_description(): # TODO(wjwwood): Use a substitution to find share directory once this is implemented in launch urdf = os.path.join(get_package_share_directory('kuka10'), 'urdf', 'kuka10.urdf'), ctrlr_param = os.path.join(get_package_share_directory('kuka10'), 'config', 'fake_controller_config.yaml') use_sim_time = LaunchConfiguration('use_sim_time', default='true') world_file_name = 'workspace' urdf_config = xacro.process_file(urdf) robot_description = {'robot_description': urdf.toxml()} world = os.path.join(get_package_share_directory('kuka10'), 'worlds', world_file_name) rviz_config_dir = os.path.join(get_package_share_directory('kuka10'), 'rviz', 'kuka10.rviz') return LaunchDescription([ Node(package='controller_manager', executable='ros2_control_node', parameters=[robot_description, ctrlr_param], output={ 'stdout': 'screen', 'stderr': 'screen', }), Node(package='robot_state_publisher', executable='robot_state_publisher', output='screen', arguments=[urdf]), Node(package='rviz2', executable='rviz2', arguments=['-d', rviz_config_dir], output='screen'), Node(package='joint_state_publisher_gui', executable='joint_state_publisher_gui', output='screen') #ExecuteProcess(cmd=['gazebo', '--verbose', world, '-s', 'libgazebo_ros_init.so'],output='screen') ])
def parse(file_path: str, **kwargs) -> str: """parse sdf, urdf, or xacro file Args: file_path (str): file path to parse **kwargs: Arbitrary keyword arguments Returns: str: string of processed file contents Raises: Exception: GazeboXmlLoader parse file loading or non-recognized type exception """ _, file_extension = os.path.splitext(file_path) try: if file_extension in ['.sdf', '.urdf']: with open(file_path, "r") as file_pointer: xml = file_pointer.read() return xml if file_extension == '.xacro': xacro_xml = xacro.process_file(input_file_name=file_path, mappings=kwargs).toxml() return xacro_xml log_and_exit( "[GazeboXmlLoader]: file type {} not recognizable".format( file_extension), SIMAPP_SIMULATION_WORKER_EXCEPTION, SIMAPP_EVENT_ERROR_CODE_500) except Exception as ex: log_and_exit( "[GazeboXmlLoader]: file open or parse failure, {}".format(ex), SIMAPP_SIMULATION_WORKER_EXCEPTION, SIMAPP_EVENT_ERROR_CODE_500)
def _load_xacro(module, package, fname): rospack = rospkg.RosPack() package_path = rospack.get_path(package) fname2 = os.path.join(package_path, 'urdf', fname + '.xacro') urdf_text = xacro.process_file(fname2).toprettyxml(indent=' ') urdf_json_dict = {'urdf': urdf_text} urdf_json = json.dumps(urdf_json_dict) return module.SendCommand('LoadString ' + urdf_json)
def generate_launch_description(): # Get URDF via xacro robot_description_path = os.path.join( get_package_share_directory('robot_description'), 'urdf', 'panda.xacro') robot_description_config = xacro.process_file(robot_description_path, mappings={ 'end_effector': 'true', 'gazebo': 'false' }) robot_description = {'robot_description': robot_description_config.toxml()} robot_controller = os.path.join( get_package_share_directory('robot_hw_interface'), 'config', 'robot_controllers.yaml') rviz_config_file = os.path.join( get_package_share_directory('robot_hw_interface'), 'rviz', 'panda.rviz') control_node = Node( package='controller_manager', executable='ros2_control_node', parameters=[robot_description, robot_controller], output={ 'stdout': 'screen', 'stderr': 'screen', }, ) robot_state_publisher_node = Node(package='robot_state_publisher', executable='robot_state_publisher', output='both', parameters=[robot_description]) start_controller_node = Node( package='robot_hw_interface', executable='start_controller', output='screen', ) rviz_node = Node( package='rviz2', executable='rviz2', name='rviz2', output='log', arguments=['-d', rviz_config_file], ) return LaunchDescription([ control_node, start_controller_node, robot_state_publisher_node, rviz_node, ])
def generate_launch_description(): launch_arg_name_space = actions.DeclareLaunchArgument('name_space', default_value=''), # name_space = '' # Variable we would like to adjust as a an argument for the launch file: name_space = launch_arg_name_space # I.e ros2 launch xacro_launch_argument example.launch.py --namespace 'new_namespace' package_name = 'xacro_launch_argument' package_path = os.path.join(get_package_share_directory(package_name)) xacro_path = os.path.join(package_path, 'urdf', 'example.urdf.xacro') doc = xacro.process_file(xacro_path, mappings={'ns_namespace': name_space}) robot_params = {'robot_description': doc.toxml()} print( "-----------------------------------------------------------------------------------------------------------" ) print("xacro file path: {}".format(xacro_path)) print( "-----------------------------------------------------------------------------------------------------------" ) print(f"Name space: {name_space}") print( "-----------------------------------------------------------------------------------------------------------" ) print(doc.toxml()) print( "-----------------------------------------------------------------------------------------------------------" ) node_robot_state_publisher = Node( package='robot_state_publisher', executable='robot_state_publisher', name='robot_state_publisher', namespace=name_space, output='screen', parameters=[robot_params], ) if name_space != '': name_space = name_space + '_' static_tf = Node(package='tf2_ros', executable='static_transform_publisher', name='static_transform_publisher', output='log', arguments=[ '1.0', '0', '0.55', '0.0', '0.0', '0.0', 'world', name_space + 'odom' ]) return LaunchDescription([ node_robot_state_publisher, static_tf, ])
def generate_launch_description(): doc = xacro.process_file(xacro_path) robot_desc = doc.toprettyxml(indent=' ') f = open(urdf_path, 'w') f.write(robot_desc) f.close() rsp = launch_ros.actions.Node(package='robot_state_publisher', executable='robot_state_publisher', output='both', arguments=[urdf_path]) return launch.LaunchDescription([rsp])
def to_urdf(xacro_path, urdf_path=None): # If no URDF path is given, use a temporary file if urdf_path is None: urdf_path = tempfile.mktemp(prefix='%s_' % os.path.basename(xacro_path)) # open and process file doc = xacro.process_file(xacro_path) # open the output file print(urdf_path) out = xacro.open_output(urdf_path) out.write(doc.toprettyxml(indent=' ')) return urdf_path # Return path to the urdf file
def generate_robot_description(enable_dummy): share_dir_path = os.path.join( get_package_share_directory('miniv_description')) xacro_path = "" if enable_dummy: xacro_path = os.path.join(share_dir_path, 'urdf', 'miniv_dummy.urdf.xacro') else: xacro_path = os.path.join(share_dir_path, 'urdf', 'miniv_robot.urdf.xacro') doc = xacro.process_file(xacro_path) robot_description = {"robot_description": doc.toxml()} return robot_description
def generate_launch_description(): # Get URDF via xacro robot_description_path = os.path.join( get_package_share_directory('ros2_control_demo_robot'), 'description', 'rrbot_system_position_only.urdf.xacro') robot_description_config = xacro.process_file(robot_description_path, mappings={'slowdown': '3.0'}) robot_description = {'robot_description': robot_description_config.toxml()} rrbot_forward_controller = os.path.join( get_package_share_directory('ros2_control_demo_robot'), 'config', 'rrbot_controllers.yaml' ) rviz_config_file = os.path.join( get_package_share_directory('ros2_control_demo_robot'), 'rviz', 'rrbot.rviz' ) control_node = Node( package='controller_manager', executable='ros2_control_node', parameters=[robot_description, rrbot_forward_controller], output={ 'stdout': 'screen', 'stderr': 'screen', }, ) robot_state_publisher_node = Node( package='robot_state_publisher', executable='robot_state_publisher', output='both', parameters=[robot_description] ) rviz_node = Node( package='rviz2', executable='rviz2', name='rviz2', output='log', arguments=['-d', rviz_config_file], ) return LaunchDescription([ control_node, robot_state_publisher_node, rviz_node, ])
def generate_launch_description(): pkg_share = FindPackageShare('robot_state_publisher').find( 'robot_state_publisher') urdf_dir = os.path.join(pkg_share, 'urdf') xacro_file = os.path.join(urdf_dir, 'test-desc.urdf.xacro') doc = xacro.process_file(xacro_file) robot_desc = doc.toprettyxml(indent=' ') params = {'robot_description': robot_desc} rsp = launch_ros.actions.Node(package='robot_state_publisher', executable='robot_state_publisher', output='both', parameters=[params]) return launch.LaunchDescription([rsp])
def to_urdf(xacro_path, parameters=None): """Convert the given xacro file to URDF file. * xacro_path -- the path to the xacro file * parameters -- to be used when xacro file is parsed. """ urdf_path = tempfile.mktemp(prefix="%s_" % os.path.basename(xacro_path)) # open and process file doc = xacro.process_file(xacro_path, mappings=parameters) # open the output file out = xacro.open_output(urdf_path) out.write(doc.toprettyxml(indent=' ')) return urdf_path
def generate_launch_description(): # Get URDF via xacro robot_description_path = os.path.join( get_package_share_directory("ros2_control_demo_robot"), "description", "rrbot", "rrbot_system_position_only.urdf.xacro", ) robot_description_config = xacro.process_file(robot_description_path, mappings={"slowdown": "3.0"}) robot_description = {"robot_description": robot_description_config.toxml()} rrbot_forward_controller = os.path.join( get_package_share_directory("ros2_control_demo_robot"), "config", "rrbot_controllers.yaml") rviz_config_file = os.path.join( get_package_share_directory("ros2_control_demo_robot"), "rviz", "rrbot.rviz") control_node = Node( package="controller_manager", executable="ros2_control_node", parameters=[robot_description, rrbot_forward_controller], output={ "stdout": "screen", "stderr": "screen", }, ) robot_state_publisher_node = Node( package="robot_state_publisher", executable="robot_state_publisher", output="both", parameters=[robot_description], ) rviz_node = Node( package="rviz2", executable="rviz2", name="rviz2", output="log", arguments=["-d", rviz_config_file], ) return LaunchDescription([ control_node, robot_state_publisher_node, rviz_node, ])
def to_urdf(xacro_path, urdf_path=None): """Convert the given xacro file to URDF file. * xacro_path -- the path to the xacro file * urdf_path -- the path to the urdf file """ # If no URDF path is given, use a temporary file if urdf_path is None: urdf_path = tempfile.mktemp(prefix="%s_" % os.path.basename(xacro_path)) # open and process file doc = xacro.process_file(xacro_path) # open the output file out = xacro.open_output(urdf_path) out.write(doc.toprettyxml(indent=' ')) return urdf_path # Return path to the urdf file
def test_urdf_turtlebot(self): """ Check if check_urdf command passes with the urdf that is generated in the .test file this test case is called from. """ resulted_urdf_file_relpath = "./sample_kobuki.urdf" kobuki_xacro_file_path = rospkg.RosPack().get_path( 'openni_description') + "/test/sample_kobuki.urdf.xacro" self.assertTrue(os.path.isfile(kobuki_xacro_file_path)) xacro_output_memory = xacro.process_file(kobuki_xacro_file_path) xacro_output_file = xacro.open_output(resulted_urdf_file_relpath) xacro_output_file.write(xacro_output_memory.toprettyxml(indent=' ')) xacro_output_file.close() self.assertTrue(os.path.isfile(resulted_urdf_file_relpath)) self.assertEqual( 0, subprocess.call(["check_urdf", resulted_urdf_file_relpath]))
def update(self) -> None: """Process the xacro file and update files & directories.""" xacro.all_includes = [] self._doc = xacro.process_file( self.root_file, **{ 'output': None, 'just_deps': False, 'xacro_ns': True, 'verbosity': 1, 'mappings': {} }) self._files = { os.path.realpath(file) for file in xacro.all_includes + [self.root_file] } self._dirs = {os.path.dirname(file) for file in self._files}
def generate_launch_description(): gazebo = IncludeLaunchDescription( PythonLaunchDescriptionSource([ os.path.join(get_package_share_directory("gazebo_ros"), "launch"), "/gazebo.launch.py", ]), launch_arguments={"verbose": "false"}.items(), ) robot_description_path = os.path.join( get_package_share_directory("ros2_control_demo_robot"), "description", "rrbot", "rrbot_system_position_only.urdf.xacro", ) robot_description_config = xacro.process_file(robot_description_path, mappings={"use_sim": "true"}) robot_description = {"robot_description": robot_description_config.toxml()} node_robot_state_publisher = Node( package="robot_state_publisher", executable="robot_state_publisher", output="screen", parameters=[robot_description], ) spawn_entity = Node( package="gazebo_ros", executable="spawn_entity.py", arguments=[ "-topic", "robot_description", "-entity", "rrbot_system_position" ], output="screen", ) spawn_controller = Node( package="controller_manager", executable="spawner.py", arguments=["joint_state_broadcaster"], output="screen", ) return LaunchDescription([ gazebo, node_robot_state_publisher, spawn_entity, spawn_controller, ])
def generate_launch_description(): # Get URDF via xacro robot_description_path = os.path.join( get_package_share_directory("ros2_control_demo_robot"), "description", "diffbot_system.urdf.xacro", ) robot_description_config = xacro.process_file(robot_description_path) robot_description = {"robot_description": robot_description_config.toxml()} diffbot_diff_drive_controller = os.path.join( get_package_share_directory("ros2_control_demo_robot"), "config", "diffbot_diff_drive_controller.yaml", ) node_robot_state_publisher = Node( package="robot_state_publisher", executable="robot_state_publisher", output="screen", parameters=[robot_description], ) controller_manager_node = Node( package="controller_manager", executable="ros2_control_node", parameters=[robot_description, diffbot_diff_drive_controller], output={ "stdout": "screen", "stderr": "screen", }, ) spawn_controller = Node( package="controller_manager", executable="spawner.py", arguments=["joint_state_broadcaster"], output="screen", ) return LaunchDescription([ node_robot_state_publisher, controller_manager_node, spawn_controller, ])
def get_state_publisher_node(): xacro_file = os.path.join( get_package_share_directory('clumsybot_description'), 'urdf', 'clumsybot.urdf.xacro') urdf_contents = xacro.process_file(xacro_file).toprettyxml(indent=' ') print("URDF robot description file :" + xacro_file) print(urdf_contents) return Node(package='robot_state_publisher', executable='robot_state_publisher', name='robot_state_publisher', output='screen', parameters=[{ 'use_sim_time': USE_SIM_TIME, 'robot_description': urdf_contents }])