moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
servo_utils.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
8from launch_param_builder import ParameterBuilder
9
10
12 moveit_config = (
13 MoveItConfigsBuilder("moveit_resources_panda")
14 .robot_description(file_path="config/panda.urdf.xacro")
15 .to_moveit_configs()
16 )
17
18 # Get parameters for the Servo node
19 servo_params = {
20 "moveit_servo_test": ParameterBuilder("moveit_servo")
21 .yaml("config/panda_simulated_config.yaml")
22 .to_dict()
23 }
24
25 # This filter parameter should be >1. Increase it for greater smoothing but slower motion.
26 low_pass_filter_coeff = {"butterworth_filter_coeff": 1.5}
27
28 # ros2_control using FakeSystem as hardware
29 ros2_controllers_path = os.path.join(
30 get_package_share_directory("moveit_resources_panda_moveit_config"),
31 "config",
32 "ros2_controllers.yaml",
33 )
34 ros2_control_node = launch_ros.actions.Node(
35 package="controller_manager",
36 executable="ros2_control_node",
37 parameters=[ros2_controllers_path],
38 remappings=[
39 ("/controller_manager/robot_description", "/robot_description"),
40 ],
41 output="screen",
42 )
43
44 joint_state_broadcaster_spawner = launch_ros.actions.Node(
45 package="controller_manager",
46 executable="spawner",
47 arguments=[
48 "joint_state_broadcaster",
49 "--controller-manager-timeout",
50 "300",
51 "--controller-manager",
52 "/controller_manager",
53 ],
54 )
55
56 panda_arm_controller_spawner = launch_ros.actions.Node(
57 package="controller_manager",
58 executable="spawner",
59 arguments=["panda_arm_controller", "-c", "/controller_manager"],
60 )
61
62 # Component nodes for tf and Servo
63 test_container = launch_ros.actions.ComposableNodeContainer(
64 name="servo_utils_tests_container",
65 namespace="/",
66 package="rclcpp_components",
67 executable="component_container_mt",
68 composable_node_descriptions=[
69 launch_ros.descriptions.ComposableNode(
70 package="robot_state_publisher",
71 plugin="robot_state_publisher::RobotStatePublisher",
72 name="robot_state_publisher",
73 parameters=[moveit_config.robot_description],
74 ),
75 launch_ros.descriptions.ComposableNode(
76 package="tf2_ros",
77 plugin="tf2_ros::StaticTransformBroadcasterNode",
78 name="static_tf2_broadcaster",
79 parameters=[{"/child_frame_id": "panda_link0", "/frame_id": "world"}],
80 ),
81 ],
82 output="screen",
83 )
84
85 servo_gtest = launch_ros.actions.Node(
86 executable=launch.substitutions.PathJoinSubstitution(
87 [
88 launch.substitutions.LaunchConfiguration("test_binary_dir"),
89 "moveit_servo_utils_test",
90 ]
91 ),
92 parameters=[
93 servo_params,
94 low_pass_filter_coeff,
95 moveit_config.robot_description,
96 moveit_config.robot_description_semantic,
97 moveit_config.robot_description_kinematics,
98 ],
99 output="screen",
100 )
101
102 return launch.LaunchDescription(
103 [
104 launch.actions.DeclareLaunchArgument(
105 name="test_binary_dir",
106 description="Binary directory of package "
107 "containing test executables",
108 ),
109 ros2_control_node,
110 joint_state_broadcaster_spawner,
111 panda_arm_controller_spawner,
112 test_container,
113 launch.actions.TimerAction(period=2.0, actions=[servo_gtest]),
114 launch_testing.actions.ReadyToTest(),
115 ]
116 ), {
117 "servo_gtest": servo_gtest,
118 }
119
120
121class TestGTestWaitForCompletion(unittest.TestCase):
122 # Waits for test to complete, then waits a bit to make sure result files are generated
123 def test_gtest_run_complete(self, servo_gtest):
124 self.proc_info.assertWaitForShutdown(servo_gtest, timeout=4000.0)
125
126
127@launch_testing.post_shutdown_test()
128class TestGTestProcessPostShutdown(unittest.TestCase):
129 # Checks if the test has been completed with acceptable exit codes (successful codes)
130 def test_gtest_pass(self, proc_info, servo_gtest):
131 launch_testing.asserts.assertExitCodes(proc_info, process=servo_gtest)
test_gtest_pass(self, proc_info, servo_gtest)