Last active
July 9, 2023 02:30
-
-
Save BuckyI/1e69f87725c23c09bc8d599d5708baae to your computer and use it in GitHub Desktop.
[learning] launch file from moveit2 tutorial [referenced from: https://www.notion.so/mightymjolnir/MIoveit2-temperory-note-5f57377d7f76445eb7d7ac2bd1d7840e]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from launch import LaunchDescription | |
from launch.actions import DeclareLaunchArgument, OpaqueFunction | |
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution | |
from launch.conditions import IfCondition, UnlessCondition | |
from launch_ros.actions import Node | |
from launch_ros.substitutions import FindPackageShare | |
from launch.actions import ExecuteProcess | |
from ament_index_python.packages import get_package_share_directory | |
from moveit_configs_utils import MoveItConfigsBuilder | |
def generate_launch_description(): | |
declared_arguments = [] | |
declared_arguments.append( | |
DeclareLaunchArgument( | |
"rviz_config", | |
default_value="panda_moveit_config_demo.rviz", | |
description="RViz configuration file", | |
) | |
) | |
# OpaqueFunction is an action which calls a function whose | |
return LaunchDescription( | |
declared_arguments + [OpaqueFunction(function=launch_setup)] | |
) | |
def launch_setup(context, *args, **kwargs): | |
moveit_config = ( | |
# load from package whose name is `moveit_resources_panda_moveit_config` | |
MoveItConfigsBuilder("moveit_resources_panda") | |
# Load robot description. | |
.robot_description(file_path="config/panda.urdf.xacro") | |
# Load trajectory execution and moveit controller managers' parameters | |
.trajectory_execution( | |
file_path="config/gripper_moveit_controllers.yaml" | |
).planning_scene_monitor( # modify default settings | |
publish_robot_description=True, publish_robot_description_semantic=True | |
) | |
# Load planning pipelines parameters from `config/xxx_planning.yaml` | |
.planning_pipelines( | |
pipelines=["ompl", "chomp", "pilz_industrial_motion_planner"] | |
) | |
# Get a `MoveItConfigs` instance with all parameters loaded. | |
.to_moveit_configs() | |
) # brackets can me omitted actually | |
# Start the actual move_group node/action server | |
run_move_group_node = Node( | |
package="moveit_ros_move_group", | |
executable="move_group", | |
output="screen", | |
parameters=[moveit_config.to_dict()], | |
) | |
# retrieve "rviz_config" from launch_configurations, which may be set via CLI | |
rviz_base = LaunchConfiguration("rviz_config") | |
# find riviz config file `*.rviz` from share path of package `moveit2_tutorials`, | |
# e.g. install/moveit2_tutorials/ashare/moveit2_tutorials/launch/ | |
rviz_config = PathJoinSubstitution( | |
[FindPackageShare("moveit2_tutorials"), "launch", rviz_base] | |
) | |
# RViz | |
rviz_node = Node( | |
package="rviz2", | |
executable="rviz2", | |
name="rviz2", | |
output="log", | |
arguments=["-d", rviz_config], | |
parameters=[ | |
moveit_config.robot_description, | |
moveit_config.robot_description_semantic, | |
moveit_config.robot_description_kinematics, | |
moveit_config.planning_pipelines, | |
moveit_config.joint_limits, | |
], | |
) | |
# Static TF | |
static_tf = 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", "world", "panda_link0"], | |
) | |
# Publish TF | |
robot_state_publisher = Node( | |
package="robot_state_publisher", | |
executable="robot_state_publisher", | |
name="robot_state_publisher", | |
output="both", | |
parameters=[moveit_config.robot_description], | |
) | |
# ros2_control using FakeSystem as hardware | |
# it's `config/ros2_controllers.yaml` in package `moveit_resources_panda_moveit_config` | |
ros2_controllers_path = os.path.join( | |
get_package_share_directory("moveit_resources_panda_moveit_config"), | |
"config", | |
"ros2_controllers.yaml", | |
) | |
ros2_control_node = Node( | |
package="controller_manager", | |
executable="ros2_control_node", | |
parameters=[moveit_config.robot_description, ros2_controllers_path], | |
output="both", | |
) | |
# publish joint states | |
joint_state_broadcaster_spawner = Node( | |
package="controller_manager", | |
executable="spawner", | |
arguments=[ | |
"joint_state_broadcaster", | |
"--controller-manager-timeout", | |
"300", | |
"--controller-manager", | |
"/controller_manager", | |
], | |
) | |
# load controllers | |
arm_controller_spawner = Node( | |
package="controller_manager", | |
executable="spawner", | |
arguments=["panda_arm_controller", "-c", "/controller_manager"], | |
) | |
hand_controller_spawner = Node( | |
package="controller_manager", | |
executable="spawner", | |
arguments=["panda_hand_controller", "-c", "/controller_manager"], | |
) | |
nodes_to_start = [ | |
rviz_node, | |
static_tf, | |
robot_state_publisher, | |
run_move_group_node, | |
ros2_control_node, | |
joint_state_broadcaster_spawner, | |
arm_controller_spawner, | |
hand_controller_spawner, | |
] | |
return nodes_to_start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This config file is used by ros2_control | |
controller_manager: | |
ros__parameters: | |
update_rate: 100 # Hz | |
panda_arm_controller: | |
type: joint_trajectory_controller/JointTrajectoryController | |
panda_hand_controller: | |
type: position_controllers/GripperActionController | |
joint_state_broadcaster: | |
type: joint_state_broadcaster/JointStateBroadcaster | |
panda_arm_controller: | |
ros__parameters: | |
command_interfaces: | |
- position | |
state_interfaces: | |
- position | |
- velocity | |
joints: | |
- panda_joint1 | |
- panda_joint2 | |
- panda_joint3 | |
- panda_joint4 | |
- panda_joint5 | |
- panda_joint6 | |
- panda_joint7 | |
panda_hand_controller: | |
ros__parameters: | |
joint: panda_finger_joint1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment