Skip to content

Commit 213a718

Browse files
author
Alexander Gutenkunst
committed
Port to ROS2 foxy (draft)
- Builds + basics seem to run - Tests need to be ported - CI needs to be integrated - Further tests especially for fiducial_slam are needed
1 parent 713ac3a commit 213a718

29 files changed

+852
-599
lines changed

aruco_detect/CMakeLists.txt

Lines changed: 72 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,105 @@
1-
2-
cmake_minimum_required(VERSION 2.8.3)
1+
cmake_minimum_required(VERSION 3.5)
32
project(aruco_detect)
43

5-
find_package(catkin REQUIRED COMPONENTS
6-
roscpp
7-
tf2_geometry_msgs
8-
tf2_ros
9-
tf2
10-
visualization_msgs
11-
vision_msgs
12-
image_transport
13-
cv_bridge
14-
sensor_msgs
15-
std_msgs
16-
fiducial_msgs
17-
dynamic_reconfigure
18-
)
4+
if(NOT CMAKE_CXX_STANDARD)
5+
set(CMAKE_CXX_STANDARD 14)
6+
endif()
7+
8+
9+
find_package(rclcpp REQUIRED)
10+
find_package(tf2_geometry_msgs REQUIRED)
11+
find_package(tf2_ros REQUIRED)
12+
find_package(tf2 REQUIRED)
13+
find_package(visualization_msgs REQUIRED)
14+
find_package(vision_msgs REQUIRED)
15+
find_package(image_transport REQUIRED)
16+
find_package(cv_bridge REQUIRED)
17+
find_package(sensor_msgs REQUIRED)
18+
find_package(std_msgs REQUIRED)
19+
find_package(std_srvs REQUIRED)
20+
find_package(fiducial_msgs REQUIRED)
21+
find_package(geometry_msgs REQUIRED)
22+
#find_package(dynamic_reconfigure REQUIRED)
1923

2024
find_package(OpenCV REQUIRED)
2125

22-
generate_dynamic_reconfigure_options(cfg/DetectorParams.cfg)
26+
#generate_dynamic_reconfigure_options(cfg/DetectorParams.cfg)
27+
28+
#catkin_package(INCLUDE_DIRS DEPENDS OpenCV)
2329

24-
catkin_package(INCLUDE_DIRS DEPENDS OpenCV)
30+
31+
set(DEPENDENCIES
32+
rclcpp
33+
sensor_msgs
34+
std_msgs
35+
std_srvs
36+
visualization_msgs
37+
vision_msgs
38+
fiducial_msgs
39+
geometry_msgs
40+
cv_bridge
41+
tf2_ros
42+
image_transport
43+
)
2544

2645
###########
2746
## Build ##
2847
###########
2948

3049
add_definitions(-std=c++11)
3150

32-
include_directories(${catkin_INCLUDE_DIRS})
33-
include_directories(${OpenCV_INCLUDE_DIRS})
51+
#include_directories(${OpenCV_INCLUDE_DIRS})
3452

3553
add_executable(aruco_detect src/aruco_detect.cpp)
3654

37-
add_dependencies(aruco_detect ${${PROJECT_NAME}_EXPORTED_TARGETS}
38-
${catkin_EXPORTED_TARGETS})
55+
#add_dependencies(aruco_detect ${${PROJECT_NAME}_EXPORTED_TARGETS})
3956

40-
target_link_libraries(aruco_detect ${catkin_LIBRARIES} ${OpenCV_LIBS})
57+
ament_target_dependencies(aruco_detect ${DEPENDENCIES} OpenCV)
4158

4259
#############
4360
## Install ##
4461
#############
4562

46-
## Mark executables and/or libraries for installation
4763
install(TARGETS aruco_detect
48-
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
49-
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
50-
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
64+
DESTINATION lib/${PROJECT_NAME}
5165
)
5266

53-
catkin_install_python(PROGRAMS scripts/create_markers.py
54-
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
67+
install(DIRECTORY launch
68+
DESTINATION share/${PROJECT_NAME}
5569
)
56-
install(DIRECTORY launch/
57-
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
58-
)
70+
71+
## Mark executables and/or libraries for installation
72+
# install(TARGETS aruco_detect
73+
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
74+
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
75+
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
76+
# )
77+
78+
install(PROGRAMS scripts/create_markers.py
79+
DESTINATION lib/${PROJECT_NAME}
80+
)
81+
# install(DIRECTORY launch/
82+
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
83+
# )
5984

6085
###########
6186
## Tests ##
6287
###########
6388

64-
if(CATKIN_ENABLE_TESTING)
65-
find_package(rostest REQUIRED)
89+
# if(CATKIN_ENABLE_TESTING)
90+
# find_package(rostest REQUIRED)
6691

67-
# Tests need c++11
68-
add_definitions(-std=c++11)
92+
# # Tests need c++11
93+
# add_definitions(-std=c++11)
6994

70-
add_rostest_gtest(aruco_images_test
71-
test/aruco_images.test
72-
test/aruco_images_test.cpp)
73-
target_link_libraries(aruco_images_test ${catkin_LIBRARIES} ${OpenCV_LIBS})
74-
endif()
95+
# add_rostest_gtest(aruco_images_test
96+
# test/aruco_images.test
97+
# test/aruco_images_test.cpp)
98+
# target_link_libraries(aruco_images_test ${catkin_LIBRARIES} ${OpenCV_LIBS})
99+
# endif()
100+
101+
################################################################################
102+
# Macro for ament package
103+
################################################################################
104+
ament_export_include_directories(include)
105+
ament_package()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from launch import LaunchDescription
2+
from launch.actions import DeclareLaunchArgument, LogInfo
3+
from launch_ros.actions import Node
4+
from launch.substitutions import LaunchConfiguration
5+
6+
def generate_launch_description():
7+
return LaunchDescription([
8+
DeclareLaunchArgument('camera', default_value='camera'),
9+
DeclareLaunchArgument('image', default_value='image'),
10+
DeclareLaunchArgument('transport', default_value='compressed'),
11+
DeclareLaunchArgument('fiducial_len', default_value='0.14'),
12+
DeclareLaunchArgument('dictionary', default_value='7'),
13+
DeclareLaunchArgument('do_pose_estimation', default_value='True'),
14+
DeclareLaunchArgument('vis_msgs', default_value="False"),
15+
DeclareLaunchArgument('ignore_fiducials', default_value=""),
16+
DeclareLaunchArgument('fiducial_len_override', default_value=""),
17+
Node(
18+
package='aruco_detect',
19+
namespace='aruco_detect',
20+
executable='aruco_detect',
21+
name='aruco_detect',
22+
parameters=[
23+
{"image_transport":LaunchConfiguration('transport')},
24+
{"publish_images":True},
25+
{"fiducial_len":LaunchConfiguration('fiducial_len')},
26+
{"dictionary":LaunchConfiguration('dictionary')},
27+
{"do_pose_estimation":LaunchConfiguration('do_pose_estimation')},
28+
{"vis_msgs":LaunchConfiguration('vis_msgs')},
29+
{"ignore_fiducials":LaunchConfiguration('ignore_fiducials')},
30+
{"fiducial_len_override":LaunchConfiguration('fiducial_len_override')}
31+
],
32+
#Not sure if the remapping is working properly TODO
33+
remappings=[
34+
('camera/compressed', [LaunchConfiguration('camera'), '/',LaunchConfiguration('image'), '/', LaunchConfiguration('transport')]),
35+
('camera_info', [LaunchConfiguration('camera'), '/camera_info']),
36+
]
37+
)
38+
])

aruco_detect/package.xml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
<author email="[email protected]">Jim Vaughan</author>
1313

14-
<buildtool_depend>catkin</buildtool_depend>
15-
16-
<depend>roscpp</depend>
14+
<depend>rclcpp</depend>
1715
<depend>tf2_geometry_msgs</depend>
1816
<depend>tf2_ros</depend>
1917
<depend>tf2</depend>
@@ -23,8 +21,15 @@
2321
<depend>sensor_msgs</depend>
2422
<depend>cv_bridge</depend>
2523
<depend>fiducial_msgs</depend>
26-
<depend>dynamic_reconfigure</depend>
27-
<depend>python-cairosvg</depend>
28-
<depend>python-joblib</depend>
24+
<depend>std_srvs</depend>
25+
<depend>geometry_msgs</depend>
26+
<!--<depend>dynamic_reconfigure</depend>-->
27+
28+
<!-- <depend>python-cairosvg</depend> Installed via pip3 install cairosvg -->
29+
<depend>python-joblib</depend> <!-- TODO Manually needed to install apt python3-joblib -->
30+
31+
<export>
32+
<build_type>ament_cmake</build_type>
33+
</export>
2934

3035
</package>

aruco_detect/scripts/create_markers.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22

33
import os, sys, argparse
44
import subprocess
55
import imp, importlib
6+
import cairosvg
67

78
# Hack if a user has 'em' instead of 'empy' installed with pip
89
# If the module em doesn't have the expand function use the full path
@@ -15,9 +16,11 @@
1516
break
1617
# For-else: else is called if loop doesn't break
1718
else:
18-
print "ERROR: could not find module em, please sudo apt install python-empy"
19+
print("ERROR: could not find module em, please sudo apt install python-empy")
1920
exit(2)
2021

22+
23+
# TODO Needs `python3 -m pip install opencv-contrib-python` on Ubuntu 20
2124
import cv2
2225
import cv2.aruco as aruco
2326

@@ -28,8 +31,8 @@
2831
def checkCmd(cmd, package):
2932
rc = os.system("which %s > /dev/null" % cmd)
3033
if rc != 0:
31-
print """This utility requires %s. It can be installed by typing:
32-
sudo apt install %s""" % (cmd, package)
34+
print("""This utility requires %s. It can be installed by typing:
35+
sudo apt install %s""" % (cmd, package))
3336
sys.exit(1)
3437

3538
def genSvg(id, dicno, paper_size):
@@ -83,22 +86,24 @@ def genSvg(id, dicno, paper_size):
8386
""", {"id": id, "dicno": dicno, "paper_width": paper_size[0], "paper_height": paper_size[1], "fid_len": 140.0})
8487

8588
def genMarker(i, dicno, paper_size):
86-
print " Marker %d\r" % i,
89+
print(" Marker %d\r" % i)
8790
sys.stdout.flush()
8891
aruco_dict = aruco.Dictionary_get(dicno)
8992
img = aruco.drawMarker(aruco_dict, i, 2000)
9093
cv2.imwrite("/tmp/marker%d.png" % i, img)
9194
svg = genSvg(i, dicno, paper_size)
92-
cairo = subprocess.Popen(('cairosvg', '-f', 'pdf', '-o', '/tmp/marker%d.pdf' % i, '/dev/stdin'), stdin=subprocess.PIPE)
93-
cairo.communicate(input=svg)
95+
96+
# This would cause errors with python3
97+
#cairo = subprocess.Popen(('cairosvg', '-f', 'pdf', '-o', '/tmp/marker%d.pdf' % i, '/dev/stdin'), stdin=subprocess.PIPE)
98+
#cairo.communicate(input=svg)
9499
# This way is faster than subprocess, but causes problems when cairosvg is installed from pip
95100
# because newer versions only support python3, and opencv3 from ros does not
96-
# cairosvg.svg2pdf(bytestring=svg, write_to='/tmp/marker%d.pdf' % i)
101+
cairosvg.svg2pdf(bytestring=svg, write_to='/tmp/marker%d.pdf' % i)
97102
os.remove("/tmp/marker%d.png" % i)
98103

99104
if __name__ == "__main__":
100105
checkCmd("pdfunite", "poppler-utils")
101-
checkCmd("cairosvg", "python-cairosvg")
106+
#checkCmd("cairosvg", "python-cairosvg")
102107

103108

104109
parser = argparse.ArgumentParser(description='Generate Aruco Markers.')
@@ -135,11 +140,11 @@ def genMarker(i, dicno, paper_size):
135140
for i in markers:
136141
genMarker(i, dicno, paper_size)
137142

138-
print "Combining into %s" % outfile
143+
print("Combining into %s" % outfile)
139144
os.system("pdfunite %s %s" % (" ".join(pdfs), outfile))
140145
for f in pdfs:
141146
os.remove(f)
142147

143-
print '\033[91m' + """After printing, please make sure that the long lines around the marker are
144-
EXACTLY 14.0 cm long. This is required for accurate position estimation.""" + '\033[0m'
148+
print('\033[91m' + """After printing, please make sure that the long lines around the marker are
149+
EXACTLY 14.0 cm long. This is required for accurate position estimation.""" + '\033[0m')
145150

0 commit comments

Comments
 (0)