moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
move_group_api.test.py
Go to the documentation of this file.
1import os
2import launch
3import unittest
4import launch_ros
5import launch_testing
6from ament_index_python.packages import get_package_share_directory
7from moveit_configs_utils import MoveItConfigsBuilder
8
9
11 moveit_config = (
12 MoveItConfigsBuilder("moveit_resources_panda")
13 .robot_description(
14 file_path="config/panda.urdf.xacro",
15 )
16 .robot_description_semantic(file_path="config/panda.srdf")
18 publish_robot_description=True, publish_robot_description_semantic=True
19 )
20 .trajectory_execution(file_path="config/gripper_moveit_controllers.yaml")
21 .planning_pipelines(
22 pipelines=["ompl", "chomp", "pilz_industrial_motion_planner", "stomp"]
23 )
24 .to_moveit_configs()
25 )
26
27 # Start the actual move_group node/action server
28 move_group_node = launch_ros.actions.Node(
29 package="moveit_ros_move_group",
30 executable="move_group",
31 output="screen",
32 parameters=[moveit_config.to_dict()],
33 arguments=["--ros-args", "--log-level", "info"],
34 )
35
36 # ros2_control using FakeSystem as hardware
37 ros2_controllers_path = os.path.join(
38 get_package_share_directory("moveit_resources_panda_moveit_config"),
39 "config",
40 "ros2_controllers.yaml",
41 )
42 ros2_control_node = launch_ros.actions.Node(
43 package="controller_manager",
44 executable="ros2_control_node",
45 parameters=[ros2_controllers_path],
46 remappings=[
47 ("/controller_manager/robot_description", "/robot_description"),
48 ],
49 output="screen",
50 )
51
52 joint_state_broadcaster_spawner = launch_ros.actions.Node(
53 package="controller_manager",
54 executable="spawner",
55 arguments=[
56 "joint_state_broadcaster",
57 "--controller-manager",
58 "/controller_manager",
59 ],
60 output="screen",
61 )
62
63 panda_arm_controller_spawner = launch_ros.actions.Node(
64 package="controller_manager",
65 executable="spawner",
66 arguments=["panda_arm_controller", "-c", "/controller_manager"],
67 )
68
69 panda_hand_controller_spawner = launch_ros.actions.Node(
70 package="controller_manager",
71 executable="spawner",
72 arguments=["panda_hand_controller", "-c", "/controller_manager"],
73 )
74
75 # Static TF
76 static_tf_node = launch_ros.actions.Node(
77 package="tf2_ros",
78 executable="static_transform_publisher",
79 name="static_transform_publisher",
80 output="log",
81 arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "panda_link0"],
82 )
83
84 # Publish TF
85 robot_state_publisher = launch_ros.actions.Node(
86 package="robot_state_publisher",
87 executable="robot_state_publisher",
88 name="robot_state_publisher",
89 output="both",
90 parameters=[moveit_config.robot_description],
91 )
92
93 move_group_gtest = launch_ros.actions.Node(
94 executable=launch.substitutions.PathJoinSubstitution(
95 [
96 launch.substitutions.LaunchConfiguration("test_binary_dir"),
97 "move_group_api_test",
98 ]
99 ),
100 parameters=[moveit_config.to_dict()],
101 output="screen",
102 )
103
104 return launch.LaunchDescription(
105 [
106 launch.actions.DeclareLaunchArgument(
107 name="test_binary_dir",
108 description="Binary directory of package "
109 "containing test executables",
110 ),
111 static_tf_node,
112 robot_state_publisher,
113 move_group_node,
114 ros2_control_node,
115 joint_state_broadcaster_spawner,
116 panda_arm_controller_spawner,
117 panda_hand_controller_spawner,
118 move_group_gtest,
119 # launch.actions.TimerAction(period=15.0, actions=[move_group_gtest]),
120 launch_testing.actions.ReadyToTest(),
121 ]
122 ), {
123 "move_group_gtest": move_group_gtest,
124 }
125
126
127class TestGTestWaitForCompletion(unittest.TestCase):
128 # Waits for test to complete, then waits a bit to make sure result files are generated
129 def test_gtest_run_complete(self, move_group_gtest):
130 self.proc_info.assertWaitForShutdown(move_group_gtest, timeout=4000.0)
131
132
133@launch_testing.post_shutdown_test()
134class TestGTestProcessPostShutdown(unittest.TestCase):
135 # Checks if the test has been completed with acceptable exit codes (successful codes)
136 def test_gtest_pass(self, proc_info, move_group_gtest):
137 launch_testing.asserts.assertExitCodes(proc_info, process=move_group_gtest)
test_gtest_pass(self, proc_info, move_group_gtest)