moveit2
The MoveIt Motion Planning Framework for ROS 2.
test_servo_pose_tracking.test.py
Go to the documentation of this file.
1 import os
2 import pytest
3 import launch
4 import launch_ros
5 import launch_testing.actions
6 import launch_testing.asserts
7 import unittest
8 from ament_index_python.packages import get_package_share_directory
9 from launch_ros.actions import Node, ComposableNodeContainer
10 from launch_ros.descriptions import ComposableNode
11 from launch.actions import ExecuteProcess, TimerAction
12 from launch.some_substitutions_type import SomeSubstitutionsType
13 from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
14 from launch_param_builder import ParameterBuilder
15 from moveit_configs_utils import MoveItConfigsBuilder
16 
17 
18 def generate_servo_test_description(*args, gtest_name: SomeSubstitutionsType):
19  moveit_config = (
20  MoveItConfigsBuilder("moveit_resources_panda")
21  .robot_description(file_path="config/panda.urdf.xacro")
22  .to_moveit_configs()
23  )
24 
25  # Get parameters for the Pose Tracking and Servo nodes
26  servo_params = {
27  "moveit_servo": ParameterBuilder("moveit_servo")
28  .yaml("config/pose_tracking_settings.yaml")
29  .yaml("config/panda_simulated_config_pose_tracking.yaml")
30  .to_dict()
31  }
32 
33  # ros2_control using FakeSystem as hardware
34  ros2_controllers_path = os.path.join(
35  get_package_share_directory("moveit_resources_panda_moveit_config"),
36  "config",
37  "ros2_controllers.yaml",
38  )
39  ros2_control_node = Node(
40  package="controller_manager",
41  executable="ros2_control_node",
42  parameters=[moveit_config.robot_description, ros2_controllers_path],
43  output="screen",
44  )
45 
46  joint_state_broadcaster_spawner = Node(
47  package="controller_manager",
48  executable="spawner",
49  arguments=[
50  "joint_state_broadcaster",
51  "--controller-manager-timeout",
52  "300",
53  "--controller-manager",
54  "/controller_manager",
55  ],
56  )
57 
58  panda_arm_controller_spawner = Node(
59  package="controller_manager",
60  executable="spawner",
61  arguments=["panda_arm_controller", "-c", "/controller_manager"],
62  )
63 
64  # Component nodes for tf and Servo
65  test_container = ComposableNodeContainer(
66  name="test_pose_tracking_container",
67  namespace="/",
68  package="rclcpp_components",
69  executable="component_container_mt",
70  composable_node_descriptions=[
71  ComposableNode(
72  package="robot_state_publisher",
73  plugin="robot_state_publisher::RobotStatePublisher",
74  name="robot_state_publisher",
75  parameters=[moveit_config.robot_description],
76  ),
77  ComposableNode(
78  package="tf2_ros",
79  plugin="tf2_ros::StaticTransformBroadcasterNode",
80  name="static_tf2_broadcaster",
81  parameters=[{"/child_frame_id": "panda_link0", "/frame_id": "world"}],
82  ),
83  ],
84  output="screen",
85  )
86 
87  pose_tracking_gtest = launch_ros.actions.Node(
88  executable=PathJoinSubstitution(
89  [LaunchConfiguration("test_binary_dir"), gtest_name]
90  ),
91  parameters=[
92  moveit_config.to_dict(),
93  servo_params,
94  ],
95  output="screen",
96  )
97 
98  return launch.LaunchDescription(
99  [
100  launch.actions.DeclareLaunchArgument(
101  name="test_binary_dir",
102  description="Binary directory of package "
103  "containing test executables",
104  ),
105  ros2_control_node,
106  joint_state_broadcaster_spawner,
107  panda_arm_controller_spawner,
108  test_container,
109  TimerAction(period=2.0, actions=[pose_tracking_gtest]),
110  launch_testing.actions.ReadyToTest(),
111  ]
112  ), {
113  "test_container": test_container,
114  "servo_gtest": pose_tracking_gtest,
115  "ros2_control_node": ros2_control_node,
116  }
117 
118 
120  return generate_servo_test_description(gtest_name="test_servo_pose_tracking")
121 
122 
123 class TestGTestProcessActive(unittest.TestCase):
124  def test_gtest_run_complete(self, servo_gtest):
125  self.proc_info.assertWaitForShutdown(servo_gtest, timeout=4000.0)
126 
127 
128 @launch_testing.post_shutdown_test()
129 class TestGTestProcessPostShutdown(unittest.TestCase):
131  self, proc_info, test_container, servo_gtest, ros2_control_node
132  ):
133  launch_testing.asserts.assertExitCodes(proc_info, process=servo_gtest)
def test_gtest_pass(self, proc_info, test_container, servo_gtest, ros2_control_node)
def generate_servo_test_description(*args, SomeSubstitutionsType gtest_name)