diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b573545..d8e9466 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,12 +15,12 @@ "source=${localEnv:HOME}${localEnv:USERPROFILE}/.bash_history,target=/home/ubuntu/.bash_history,type=bind", "source=/dev,target=/dev,type=bind" ], - "customizations": { + "customizations": { "vscode": { - "extensions": [ - "ms-vscode.cpptools", - "ms-vscode.cmake-tools" - ] + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools" + ] } } } \ No newline at end of file diff --git a/README.md b/README.md index f0b4134..f2a92ec 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ This keeps `amr_core` available as the command bridge while the digital twin rem ```bash source install/setup.bash -ros2 launch handsolo_ros handsolo.launch.py tm_use_simulation:=true +ros2 launch handsolo_ros handsolo.launch.py tm_use_simulation:=true use_rviz:=true ``` ## Docker diff --git a/handsolo_description/xacro/ld250_tm12x.urdf.xacro b/handsolo_description/xacro/ld250_tm12x.urdf.xacro index 62bbfaa..238e99f 100644 --- a/handsolo_description/xacro/ld250_tm12x.urdf.xacro +++ b/handsolo_description/xacro/ld250_tm12x.urdf.xacro @@ -2,7 +2,6 @@ - @@ -11,24 +10,13 @@ - - - - - - - - + - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/handsolo_ros/config/ld250_tm12x.srdf b/handsolo_ros/config/ld250_tm12x.srdf index f13889f..324d43f 100644 --- a/handsolo_ros/config/ld250_tm12x.srdf +++ b/handsolo_ros/config/ld250_tm12x.srdf @@ -48,6 +48,11 @@ + + + + + diff --git a/handsolo_ros/launch/handsolo/handsolo.moveit.launch.py b/handsolo_ros/launch/handsolo/handsolo.moveit.launch.py index 5b441a5..a5e2121 100644 --- a/handsolo_ros/launch/handsolo/handsolo.moveit.launch.py +++ b/handsolo_ros/launch/handsolo/handsolo.moveit.launch.py @@ -1,13 +1,25 @@ import os import yaml +import xacro from launch import LaunchDescription from launch_ros.actions import Node from ament_index_python.packages import get_package_share_directory -from moveit_configs_utils import MoveItConfigsBuilder + + +def load_file(package_name, file_path): + package_path = get_package_share_directory(package_name) + absolute_file_path = os.path.join(package_path, file_path) + + try: + with open(absolute_file_path, 'r') as file: + return file.read() + except EnvironmentError: + return None def load_yaml(package_name, file_path): - absolute_file_path = os.path.join(get_package_share_directory(package_name), file_path) + package_path = get_package_share_directory(package_name) + absolute_file_path = os.path.join(package_path, file_path) try: with open(absolute_file_path, 'r') as file: @@ -16,72 +28,81 @@ def load_yaml(package_name, file_path): return None -def get_moveit_config(): - moveit_config = ( - MoveItConfigsBuilder('ld250_tm12x', package_name='tm12x_moveit_config') - .robot_description( - file_path=os.path.join( - get_package_share_directory('handsolo_description'), - 'xacro', - 'ld250_tm12x.urdf.xacro', - ) - ) - .robot_description_semantic( - file_path=os.path.join( - get_package_share_directory('handsolo_ros'), - 'config', - 'ld250_tm12x.srdf', - ) - ) - .trajectory_execution( - file_path=os.path.join( - get_package_share_directory('tm12x_moveit_config'), - 'config', - 'moveit2_controllers.yaml', - ) - ) - .joint_limits( - file_path=os.path.join( - get_package_share_directory('tm12x_moveit_config'), - 'config', - 'joint_limits.yaml', - ) +def generate_launch_description(): + robot_description_config = xacro.process_file( + os.path.join( + get_package_share_directory('handsolo_description'), + 'xacro', + 'ld250_tm12x.urdf.xacro', ) - .planning_pipelines(default_planning_pipeline='ompl', pipelines=['ompl']) - .to_moveit_configs() ) - moveit_config.planning_pipelines['ompl'] = load_yaml('tm12x_moveit_config', 'config/ompl_planning.yaml') - return moveit_config + robot_description = {'robot_description': robot_description_config.toxml()} + robot_description_semantic_config = load_file('handsolo_ros', 'config/ld250_tm12x.srdf') + robot_description_semantic = {'robot_description_semantic': robot_description_semantic_config} -def generate_launch_description(): - moveit_config = get_moveit_config() + robot_description_kinematics = { + 'robot_description_kinematics': load_yaml('tm12x_moveit_config', 'config/kinematics.yaml') + } + + ompl_planning_pipeline_config = { + 'planning_pipelines': ['ompl'], + 'ompl': { + 'planning_plugin': 'ompl_interface/OMPLPlanner', + 'request_adapters': """default_planning_request_adapters/AddTimeOptimalParameterization + default_planning_request_adapters/FixWorkspaceBounds + default_planning_request_adapters/FixStartStateBounds + default_planning_request_adapters/FixStartStateCollision + default_planning_request_adapters/FixStartStatePathConstraints""", + 'start_state_max_bounds_error': 0.1, + }, + } + ompl_planning_yaml = load_yaml('tm12x_moveit_config', 'config/ompl_planning.yaml') + ompl_planning_pipeline_config['ompl'].update(ompl_planning_yaml) + + controllers_yaml = load_yaml('tm12x_moveit_config', 'config/controllers.yaml') + moveit_controllers = { + 'moveit_simple_controller_manager': controllers_yaml, + 'moveit_controller_manager': 'moveit_simple_controller_manager/MoveItSimpleControllerManager' + } + + trajectory_execution = { + 'moveit_manage_controllers': True, + 'trajectory_execution.allowed_execution_duration_scaling': 1.2, + 'trajectory_execution.allowed_goal_duration_margin': 0.5, + 'trajectory_execution.allowed_start_tolerance': 0.1, + } + + planning_scene_monitor_parameters = { + 'publish_planning_scene': True, + 'publish_geometry_updates': True, + 'publish_state_updates': True, + 'publish_transforms_updates': True, + } + + joint_limits_yaml = { + 'robot_description_planning': load_yaml('tm12x_moveit_config', 'config/joint_limits.yaml') + } - # Start the actual move_group node/action server run_move_group_node = Node( package='moveit_ros_move_group', executable='move_group', output='screen', emulate_tty=True, parameters=[ - moveit_config.to_dict(), - {"use_sim_time": True}, + robot_description, + robot_description_semantic, + robot_description_kinematics, + ompl_planning_pipeline_config, + trajectory_execution, + moveit_controllers, + planning_scene_monitor_parameters, + joint_limits_yaml, + {'use_sim_time': True}, ], ) - # Virtual Hand Solo to Base Link Static TF - static_tf_node = Node( - package='tf2_ros', - executable='static_transform_publisher', - name='static_transform_publisher', - output='log', - arguments=['0.0', '0.0', '0.0', '0.0', '0.0', '0.0', 'virtual_hand_solo/base_link', 'base'] - ) - - return LaunchDescription([ run_move_group_node, - static_tf_node - ]) + ]) - \ No newline at end of file diff --git a/handsolo_ros/launch/handsolo/handsolo.rviz.launch.py b/handsolo_ros/launch/handsolo/handsolo.rviz.launch.py index 45cec3f..dd4bedb 100644 --- a/handsolo_ros/launch/handsolo/handsolo.rviz.launch.py +++ b/handsolo_ros/launch/handsolo/handsolo.rviz.launch.py @@ -1,5 +1,7 @@ import os +import os import yaml +import xacro from launch import LaunchDescription from launch.actions import DeclareLaunchArgument from launch.conditions import IfCondition @@ -7,56 +9,30 @@ from launch_ros.actions import Node from launch_ros.substitutions import FindPackageShare from ament_index_python.packages import get_package_share_directory -from moveit_configs_utils import MoveItConfigsBuilder + + +def load_file(package_name, file_path): + package_path = get_package_share_directory(package_name) + absolute_file_path = os.path.join(package_path, file_path) + + try: + with open(absolute_file_path, 'r') as file: + return file.read() + except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available + return None def load_yaml(package_name, file_path): - absolute_file_path = os.path.join(get_package_share_directory(package_name), file_path) + package_path = get_package_share_directory(package_name) + absolute_file_path = os.path.join(package_path, file_path) try: with open(absolute_file_path, 'r') as file: return yaml.safe_load(file) - except OSError: + except OSError: # parent of IOError, OSError *and* WindowsError where available return None -def get_moveit_config(): - moveit_config = ( - MoveItConfigsBuilder('ld250_tm12x', package_name='tm12x_moveit_config') - .robot_description( - file_path=os.path.join( - get_package_share_directory('handsolo_description'), - 'xacro', - 'ld250_tm12x.urdf.xacro', - ) - ) - .robot_description_semantic( - file_path=os.path.join( - get_package_share_directory('handsolo_ros'), - 'config', - 'ld250_tm12x.srdf', - ) - ) - .trajectory_execution( - file_path=os.path.join( - get_package_share_directory('tm12x_moveit_config'), - 'config', - 'moveit2_controllers.yaml', - ) - ) - .joint_limits( - file_path=os.path.join( - get_package_share_directory('tm12x_moveit_config'), - 'config', - 'joint_limits.yaml', - ) - ) - .planning_pipelines(default_planning_pipeline='ompl', pipelines=['ompl']) - .to_moveit_configs() - ) - moveit_config.planning_pipelines['ompl'] = load_yaml('tm12x_moveit_config', 'config/ompl_planning.yaml') - return moveit_config - def generate_launch_description(): use_moveit = LaunchConfiguration('use_moveit') use_nav2 = LaunchConfiguration('use_nav2') @@ -72,13 +48,40 @@ def generate_launch_description(): default_value='false', description='Whether to start RViz with the Nav2 configuration' ) - moveit_config = get_moveit_config() - # RViz configurations + robot_description_config = xacro.process_file( + os.path.join( + get_package_share_directory('handsolo_description'), + 'xacro', + 'ld250_tm12x.urdf.xacro', + ) + ) + robot_description = {'robot_description': robot_description_config.toxml()} + + robot_description_semantic_config = load_file('handsolo_ros', 'config/ld250_tm12x.srdf') + robot_description_semantic = {'robot_description_semantic': robot_description_semantic_config} + + ompl_planning_pipeline_config = { + 'planning_pipelines': ['ompl'], + 'ompl': { + 'planning_plugin': 'ompl_interface/OMPLPlanner', + 'request_adapters': """default_planning_request_adapters/AddTimeOptimalParameterization + default_planning_request_adapters/FixWorkspaceBounds + default_planning_request_adapters/FixStartStateBounds + default_planning_request_adapters/FixStartStateCollision + default_planning_request_adapters/FixStartStatePathConstraints""", + 'start_state_max_bounds_error': 0.1, + }, + } + + kinematics_yaml = load_yaml('tm12x_moveit_config', 'config/kinematics.yaml') + robot_description_kinematics = {'robot_description_kinematics': kinematics_yaml} + moveit_rviz_config = PathJoinSubstitution([FindPackageShare('handsolo_ros'), 'rviz', 'handsolo-moveit.rviz']) nav2_rviz_cfg = PathJoinSubstitution([FindPackageShare('handsolo_ros'), 'rviz', 'handsolo-nav2.rviz']) - # RViz + joint_limits_yaml = {'robot_description_planning': load_yaml('tm12x_moveit_config', 'config/joint_limits.yaml')} + moveit_rviz_node = Node( package='rviz2', executable='rviz2', @@ -88,28 +91,26 @@ def generate_launch_description(): arguments=['-d', moveit_rviz_config], condition=IfCondition(use_moveit), parameters=[ - moveit_config.robot_description, - moveit_config.robot_description_semantic, - moveit_config.planning_pipelines, - moveit_config.robot_description_kinematics, - moveit_config.joint_limits, + robot_description, + robot_description_semantic, + ompl_planning_pipeline_config, + robot_description_kinematics, + joint_limits_yaml, ], ) - # RViz2 nav2_rviz_node = Node( package='rviz2', executable='rviz2', name='rviz2_nav2', arguments=['-d', nav2_rviz_cfg], condition=IfCondition(use_nav2), - # parameters=[{'use_sim_time': use_sim_time}], output='log' ) return LaunchDescription([ declare_use_moveit, declare_use_nav2, - moveit_rviz_node, + moveit_rviz_node, nav2_rviz_node ]) \ No newline at end of file