Skip to content

Commit 9583a83

Browse files
committed
Port auto_init_403 test
1 parent c68300d commit 9583a83

File tree

6 files changed

+127
-47
lines changed

6 files changed

+127
-47
lines changed

fiducial_slam/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ install(FILES fiducials.rviz
8888
if(BUILD_TESTING)
8989

9090
find_package(ament_cmake_gtest REQUIRED)
91+
find_package(ament_cmake_nose REQUIRED)
9192
find_package(ros_testing REQUIRED)
9293

9394
install(DIRECTORY test/test_images
@@ -109,6 +110,13 @@ if(BUILD_TESTING)
109110
target_link_libraries(auto_init_403_test)
110111
ament_target_dependencies(auto_init_403_test ${DEPENDENCIES})
111112
add_ros_test(test/auto_init_403.test.py ARGS "test_binary_dir:=${CMAKE_CURRENT_BINARY_DIR}")
113+
114+
# init_map_aruco
115+
install(FILES test/map_test.py # I guess there is a better way
116+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test
117+
PERMISSIONS OWNER_READ OWNER_EXECUTE
118+
)
119+
add_ros_test(test/init_map_aruco.test.py ARGS "test_binary_dir:=${CMAKE_CURRENT_BINARY_DIR}/test")
112120
endif()
113121
# if(CATKIN_ENABLE_TESTING)
114122
# find_package(catkin REQUIRED COMPONENTS

fiducial_slam/package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
<test_depend>ros_testing</test_depend>
3232
<test_depend>ament_cmake_test</test_depend>
33+
<test_depend>ament_cmake_node</test_depend>
34+
<test_depend>fiducial_msgs</test_depend>
35+
<test_depend>aruco_detect</test_depend>
3336
<member_of_group>rosidl_interface_packages</member_of_group>
3437
<export>
3538
<build_type>ament_cmake</build_type>
16 KB
Binary file not shown.

fiducial_slam/test/auto_init_403.test

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import unittest
2+
3+
import launch
4+
import launch_ros
5+
import launch_testing
6+
from pprint import pprint
7+
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
8+
from ament_index_python.packages import get_package_share_directory
9+
10+
import pytest
11+
12+
@pytest.mark.rostest
13+
def generate_test_description():
14+
test_node = launch_ros.actions.Node(
15+
executable=PathJoinSubstitution([LaunchConfiguration('test_binary_dir'), 'map_test.py']),
16+
output='screen',
17+
parameters=[
18+
{"min_lines":7},
19+
{"expected_pose":"0 0 0 0 0 0 1"},
20+
],
21+
)
22+
23+
rosbag_player = launch.actions.ExecuteProcess(
24+
cmd=['ros2', 'bag', 'play', '-l', '/home/alex/Projects/PortFiducialsToROS2/ros2_fiducials_ws/src/fiducials/fiducial_slam/test/aruco_transforms.db3'],
25+
output='screen'
26+
)
27+
28+
static_tranform_publisher = launch_ros.actions.Node(
29+
package='tf2_ros',
30+
executable='static_transform_publisher',
31+
name='camera_base',
32+
arguments="0.0 0.0 0.0 0.0 0.0 0.0 1.0 base_link raspicam".split()
33+
)
34+
35+
36+
# aruco_detect = launch_ros.actions.Node(
37+
# package='aruco_detect',
38+
# namespace='aruco_detect',
39+
# executable='aruco_detect',
40+
# name='aruco_detect',
41+
# parameters=[
42+
# {"image_transport":'raw'},
43+
# {"publish_images":True},
44+
# {"fiducial_len":0.145},
45+
# ],
46+
# #Not sure if the remapping is working properly TODO
47+
# remappings=[
48+
# ('camera/compressed', 'camera/image/compressed'),
49+
# ('fiducial_vertices', '/fiducial_vertices'),
50+
# ('fiducial_transforms', '/fiducial_transforms')
51+
# ]
52+
# )
53+
54+
fiducial_slam = launch_ros.actions.Node(
55+
package='fiducial_slam',
56+
executable='fiducial_slam_node',
57+
name='fiducial_slam_node',
58+
parameters=[
59+
{"map_frame":'map'},
60+
{"odom_frame":""},
61+
{"base_frame":"base_link"},
62+
{"future_date_transforms", "0.0"},
63+
{"publish_6dof_pose","true"},
64+
{"map_file":"/dev/null"}
65+
],
66+
)
67+
68+
69+
return launch.LaunchDescription([
70+
launch.actions.DeclareLaunchArgument(name='test_binary_dir', # From https://github.com/ros-planning/moveit2/blob/1e1337b46daed0aaa1252b87367c1824f46c9b1a/moveit_ros/moveit_servo/test/launch/servo_launch_test_common.py#L92
71+
description='Binary directory of package containing test executables'),
72+
# other fixture actions
73+
fiducial_slam,
74+
test_node,
75+
rosbag_player,
76+
static_tranform_publisher,
77+
#launch_testing.util.KeepAliveProc(), # From https://github.com/ros2/geometry2/blob/a1be44fdbd8c032351ffd3ddff8467d000f4c6d7/test_tf2/test/buffer_client_tester.launch.py#L39
78+
launch_testing.actions.ReadyToTest(),
79+
]), locals()
80+
81+
82+
class TestTestTermination(unittest.TestCase):
83+
def test_termination(self, test_node, proc_output, proc_info):
84+
proc_info.assertWaitForShutdown(process=test_node, timeout=(30))
85+
86+
@launch_testing.post_shutdown_test()
87+
class TestProcessOutput(unittest.TestCase):
88+
def test_no_failed_tests(self, proc_output, proc_info, test_node):
89+
# Check that process exits with code -15 code: termination request, sent to the program
90+
pprint(proc_info[test_node].returncode)
91+
number_of_failed_tests = 0
92+
launch_testing.asserts.assertExitCodes(proc_info, [number_of_failed_tests], process=test_node)

fiducial_slam/test/map_test.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import os
1010
import math
1111

12-
import rospy
13-
import rostest
12+
import rclpy
13+
from rclpy.node import Node
1414

1515
from fiducial_msgs.msg import FiducialMapEntryArray
1616
from geometry_msgs.msg import PoseWithCovarianceStamped
@@ -35,6 +35,10 @@ def __init__(self, *args):
3535
self.mapEntries = -1
3636
self.map = {}
3737
self.pose = None
38+
self.node = Node("test_map")
39+
40+
self.map_subscription = self.node.create_subscription(FiducialMapEntryArray, "/fiducial_map", self.mapCallback, 1)
41+
self.pose_subscription = self.node.create_subscription(PoseWithCovarianceStamped,"/fiducial_pose", self.poseCallback, 1)
3842

3943
def mapCallback(self, msg):
4044
self.mapEntries = len(msg.fiducials)
@@ -49,20 +53,19 @@ def poseCallback(self, msg):
4953
orientation.x, orientation.y, orientation.z, orientation.w)
5054

5155
def test_map(self):
52-
rospy.init_node('test_map')
53-
minLines = rospy.get_param("~min_lines", 1)
54-
expect = rospy.get_param("~expect", "")
55-
expectedPose = rospy.get_param("~expected_pose", "")
56+
self.node.declare_parameter("min_lines", 1)
57+
minLines = self.node.get_parameter('min_lines').value
58+
59+
expect = self.node.declare_parameter("expect", "")
60+
expect = self.node.get_parameter('expect').value
5661

57-
rospy.Subscriber("/fiducial_map", FiducialMapEntryArray,
58-
self.mapCallback)
59-
rospy.Subscriber("/fiducial_pose", PoseWithCovarianceStamped,
60-
self.poseCallback)
62+
self.node.declare_parameter("expected_pose", "")
63+
expectedPose = self.node.get_parameter('expected_pose').value
6164

62-
print("test_map");
6365
t = 0
6466
while True:
65-
if self.mapEntries >= minLines and self.pose != None:
67+
rclpy.spin_once(self.node) #Spin the node to receive callbacks
68+
if self.mapEntries >= minLines and self.pose != None: #If there are map entries and a pose is set
6669
if expectedPose != "":
6770
ep = expectedPose.split()
6871
for i in range(len(ep)):
@@ -82,11 +85,12 @@ def test_map(self):
8285
self.fail("fiducial %d %s expected %s" % \
8386
(fid, fiducial, ex,))
8487
return
85-
time.sleep(0.5)
86-
87-
if __name__ == '__main__':
88-
try:
89-
rostest.run('rostest', NAME, MapTest, sys.argv)
90-
except KeyboardInterrupt:
91-
pass
92-
print("exiting")
88+
#time.sleep(0.5)
89+
90+
def main(args=None):
91+
sys.argv = [sys.argv[0]]
92+
unittest.main()
93+
94+
if __name__ == "__main__":
95+
rclpy.init()
96+
main()

0 commit comments

Comments
 (0)