Skip to content

Commit

Permalink
Simplify argument for rsp (#277)
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Servin <[email protected]>
  • Loading branch information
garyservin authored Dec 20, 2024
1 parent 59e667f commit aee0145
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 61 deletions.
3 changes: 0 additions & 3 deletions andino_bringup/launch/andino_robot.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ def generate_launch_description():
PythonLaunchDescriptionSource(
os.path.join(pkg_andino_description, 'launch', 'andino_description.launch.py'),
),
launch_arguments={
'rsp': 'True',
}.items()
)

# Include andino_control launch file
Expand Down
45 changes: 22 additions & 23 deletions andino_description/launch/andino_description.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,41 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os
import xacro

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription, LaunchContext
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration

from launch_ros.actions import Node
from launch import LaunchDescription

import xacro

def generate_launch_description():

# Arguments
rsp_argument = DeclareLaunchArgument('rsp', default_value='true',
description='Run robot state publisher node.')

# Obtains andino_description's share directory path.
pkg_andino_description = get_package_share_directory('andino_description')

# Obtain urdf from xacro files.
arguments = {'yaml_config_dir': os.path.join(pkg_andino_description, 'config', 'andino')}
doc = xacro.process_file(os.path.join(pkg_andino_description, 'urdf', 'andino.urdf.xacro'), mappings = arguments)
arguments = {
'yaml_config_dir': os.path.join(pkg_andino_description, 'config', 'andino')
}
doc = xacro.process_file(
os.path.join(pkg_andino_description, 'urdf', 'andino.urdf.xacro'),
mappings=arguments,
)
robot_desc = doc.toprettyxml(indent=' ')
params = {'robot_description': robot_desc,
'publish_frequency': 30.0}
params = {'robot_description': robot_desc, 'publish_frequency': 30.0}

# Robot state publisher
rsp = Node(package='robot_state_publisher',
executable='robot_state_publisher',
namespace='',
output='both',
parameters=[params],
condition=IfCondition(LaunchConfiguration('rsp'))
rsp = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
namespace='',
output='both',
parameters=[params],
)

return LaunchDescription([
rsp_argument,
rsp,
])
return LaunchDescription(
[
rsp,
]
)
71 changes: 36 additions & 35 deletions andino_description/launch/view_andino.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,37 @@
import os

from ament_index_python.packages import get_package_share_directory

from launch_ros.actions import Node
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

import xacro

def generate_launch_description():

# Arguments
rviz_argument = DeclareLaunchArgument('rviz', default_value='true',
description='Open RViz.')
rsp_argument = DeclareLaunchArgument('rsp', default_value='true',
description='Run robot state publisher node.')
jsp_argument = DeclareLaunchArgument('jsp', default_value='true',
description='Run joint state publisher node.')
rviz_argument = DeclareLaunchArgument(
'rviz', default_value='true', description='Open RViz.'
)
rsp_argument = DeclareLaunchArgument(
'rsp', default_value='true', description='Run robot state publisher node.'
)
jsp_argument = DeclareLaunchArgument(
'jsp', default_value='true', description='Run joint state publisher node.'
)

# Obtains andino_description's share directory path.
pkg_andino_description = get_package_share_directory('andino_description')

# Obtain urdf from xacro files.
arguments = {'yaml_config_dir': os.path.join(pkg_andino_description, 'config', 'andino')}
doc = xacro.process_file(os.path.join(pkg_andino_description, 'urdf', 'andino.urdf.xacro'), mappings = arguments)
robot_desc = doc.toprettyxml(indent=' ')
params = {'robot_description': robot_desc,
'publish_frequency': 30.0}

# Robot state publisher
rsp = Node(package='robot_state_publisher',
executable='robot_state_publisher',
namespace='',
output='both',
parameters=[params],
condition=IfCondition(LaunchConfiguration('rsp'))
rsp = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(
pkg_andino_description, 'launch', 'andino_description.launch.py'
),
),
condition=IfCondition(LaunchConfiguration('rsp')),
)

# Joint state publisher gui
Expand All @@ -74,22 +70,27 @@ def generate_launch_description():
executable='joint_state_publisher_gui',
namespace='',
name='joint_state_publisher_gui',
condition=IfCondition(LaunchConfiguration('jsp'))
condition=IfCondition(LaunchConfiguration('jsp')),
)

# RViz
rviz = Node(
package='rviz2',
executable='rviz2',
arguments=['-d', os.path.join(pkg_andino_description, 'rviz', 'andino_description.rviz')],
condition=IfCondition(LaunchConfiguration('rviz'))
arguments=[
'-d',
os.path.join(pkg_andino_description, 'rviz', 'andino_description.rviz'),
],
condition=IfCondition(LaunchConfiguration('rviz')),
)

return LaunchDescription([
jsp_argument,
rviz_argument,
rsp_argument,
jsp_gui,
rviz,
rsp,
])
return LaunchDescription(
[
jsp_argument,
rviz_argument,
rsp_argument,
jsp_gui,
rviz,
rsp,
]
)

0 comments on commit aee0145

Please sign in to comment.