diff --git a/easy_handeye2 b/easy_handeye2 new file mode 160000 index 0000000..c788191 --- /dev/null +++ b/easy_handeye2 @@ -0,0 +1 @@ +Subproject commit c788191e33135d114b3793f1d1f554d6fd13ebe1 diff --git a/hand_eye_calibration/config/camera_config.yaml b/hand_eye_calibration/config/camera_config.yaml new file mode 100644 index 0000000..22738eb --- /dev/null +++ b/hand_eye_calibration/config/camera_config.yaml @@ -0,0 +1,24 @@ +/oak1: + ros__parameters: + camera: + i_mx_id: "184430103175341300" + i_nn_type: none + stereo: + i_subpixel: true + +/oak2: + ros__parameters: + camera: + i_mx_id: "184430106196980F00" + i_nn_type: none + stereo: + i_subpixel: true + +/oak3: + ros__parameters: + camera: + i_mx_id: "1844301001A47F0E00" + i_nn_type: none + stereo: + i_subpixel: true + diff --git a/hand_eye_calibration/hand_eye_calibration/__init__.py b/hand_eye_calibration/hand_eye_calibration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hand_eye_calibration/launch/apriltag_detector.launch.py b/hand_eye_calibration/launch/apriltag_detector.launch.py new file mode 100644 index 0000000..810b5a1 --- /dev/null +++ b/hand_eye_calibration/launch/apriltag_detector.launch.py @@ -0,0 +1,122 @@ +# Copyright 2023 Trossen Robotics +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +from launch import LaunchDescription +from launch.actions import ( + DeclareLaunchArgument, + OpaqueFunction, +) +from launch.substitutions import ( + LaunchConfiguration, + PathJoinSubstitution, +) +from launch_ros.actions import Node +from launch_ros.substitutions import FindPackageShare + + +def launch_setup(context): + + tags_config_launch_arg = LaunchConfiguration('tags_config') + camera_frame_launch_arg = LaunchConfiguration('camera_frame') + apriltag_ns_launch_arg = LaunchConfiguration('apriltag_ns') + camera_color_topic_launch_arg = LaunchConfiguration('camera_color_topic') + camera_info_topic_launch_arg = LaunchConfiguration('camera_info_topic') + + remappings = [("~/image_rect", camera_color_topic_launch_arg), + ("~/camera_info", camera_info_topic_launch_arg)] + + continuous_detector_node = Node( + package='apriltag_ros', + executable='apriltag_ros_continuous_detector_node', + name='ar_tracker', + parameters=[ + tags_config_launch_arg.perform(context), + {"publish_tf":True} + ], + arguments=[ + apriltag_ns_launch_arg.perform(context) + ], + remappings=remappings, + ) + + picture_snapper_node = Node( + package='interbotix_perception_modules', + executable='picture_snapper', + name='picture_snapper', + namespace=apriltag_ns_launch_arg.perform(context), + parameters=[ + { + 'camera_color_topic': camera_color_topic_launch_arg, + 'camera_info_topic': camera_info_topic_launch_arg, + 'camera_frame': camera_frame_launch_arg, + } + ], + arguments=[ + apriltag_ns_launch_arg.perform(context) + ], + ) + + return [ + continuous_detector_node, + ] + + +def generate_launch_description(): + declared_arguments = [ + DeclareLaunchArgument( + 'tags_config', + default_value=PathJoinSubstitution([ + FindPackageShare('interbotix_perception_modules'), + 'config', + 'tags.yaml' + ]), + description='filepath to the AprilTag tags configuration file.', + ), + DeclareLaunchArgument( + 'camera_frame', + default_value='oak_rgb_camera_optical_frame', + description='the camera frame in which the AprilTag will be detected.', + ), + DeclareLaunchArgument( + 'apriltag_ns', + default_value='apriltag', + description='namespace where the AprilTag related nodes and parameters are located.', + ), + DeclareLaunchArgument( + 'camera_color_topic', + default_value='oak/rgb/image_raw', + description='the absolute ROS topic name to subscribe to color images.', + ), + DeclareLaunchArgument( + 'camera_info_topic', + default_value='oak/rgb/camera_info', + description='the absolute ROS topic name to subscribe to the camera info.', + ), + ] + + return LaunchDescription(declared_arguments + [OpaqueFunction(function=launch_setup)]) diff --git a/hand_eye_calibration/launch/robot_calibration.launch.py b/hand_eye_calibration/launch/robot_calibration.launch.py new file mode 100644 index 0000000..99e8076 --- /dev/null +++ b/hand_eye_calibration/launch/robot_calibration.launch.py @@ -0,0 +1,231 @@ +# Copyright 2023 Trossen Robotics +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +import os + +from ament_index_python.packages import get_package_share_directory + +from launch import LaunchDescription +from launch.actions import ( + DeclareLaunchArgument, + IncludeLaunchDescription, + OpaqueFunction, +) +from launch.conditions import IfCondition, LaunchConfigurationEquals +from launch.launch_description_sources import PythonLaunchDescriptionSource +from launch.substitutions import ( + LaunchConfiguration, + PathJoinSubstitution, + PythonExpression, + TextSubstitution, +) +from launch_ros.actions import Node +from launch_ros.substitutions import FindPackageShare +from launch_ros.parameter_descriptions import ParameterValue +import yaml + + +from easy_handeye2.common_launch import arg_calibration_type, arg_tracking_base_frame, arg_tracking_marker_frame, arg_robot_base_frame, \ + arg_robot_effector_frame + + +def load_yaml(package_name, file_path): + package_path = get_package_share_directory(package_name) + absolute_file_path = os.path.join(package_path, file_path) + + try: + with open(absolute_file_path, 'r') as file: + return yaml.safe_load(file) + except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available + return None + + +def launch_setup(context, *args, **kwargs): + + calibration_launch_arg = LaunchConfiguration('calibrate') + evaluation_launch_arg = LaunchConfiguration('evaluate') + publish_launch_arg = LaunchConfiguration('publish') + camera1_name = LaunchConfiguration('cam1_name').perform(context) + camera2_name = LaunchConfiguration('cam2_name').perform(context) + camera3_name = LaunchConfiguration('cam3_name').perform(context) + + calib_name_launch_arg = LaunchConfiguration('calib_name') + + depthai_prefix = get_package_share_directory("depthai_ros_driver") + interbotix_prefix = get_package_share_directory("interbotix_xscobot_moveit") + easy_handeye_prefix = get_package_share_directory("easy_handeye2") + calibration_prefix = get_package_share_directory("hand_eye_calibration") + + interbotix_moveit = IncludeLaunchDescription( + PythonLaunchDescriptionSource( + os.path.join(interbotix_prefix, 'launch', + 'xscobot_moveit.launch.py') + ), + launch_arguments={"robot_model": "dx400", + "hardware_type": "fake"}.items()) + + spatial_rgbd1 = IncludeLaunchDescription( + PythonLaunchDescriptionSource( + os.path.join(depthai_prefix, 'launch', + 'rgbd_pcl.launch.py') + ), + launch_arguments={"name": camera1_name, + # "parent_frame": "dx400/ee_gripper_link", + "params_file": PathJoinSubstitution([calibration_prefix, 'config', 'camera_config.yaml']), + "cam_pos_z": str(0.1)}.items()) + + spatial_rgbd2 = IncludeLaunchDescription( + PythonLaunchDescriptionSource( + os.path.join(depthai_prefix, 'launch', + 'rgbd_pcl.launch.py') + ), + launch_arguments={"name": camera2_name, + # "parent_frame": "dx400/ee_gripper_link", + "params_file": PathJoinSubstitution([calibration_prefix, 'config', 'camera_config.yaml']), + "cam_pos_z": str(-0.1) + }.items()) + + spatial_rgbd3 = IncludeLaunchDescription( + PythonLaunchDescriptionSource( + os.path.join(depthai_prefix, 'launch', + 'rgbd_pcl.launch.py') + ), + launch_arguments={"name": camera3_name, + # "parent_frame": "dx400/ee_gripper_link", + "params_file": PathJoinSubstitution([calibration_prefix, 'config', 'camera_config.yaml']), + "cam_pos_z": str(0.4) + }.items()) + + apriltag_detection = IncludeLaunchDescription( + PythonLaunchDescriptionSource( + os.path.join(calibration_prefix, 'launch', + 'apriltag_detector.launch.py') + ), + launch_arguments={"camera_color_topic": "/"+camera1_name+"/rgb/image_raw", + "camera_info_topic": "/"+camera1_name+"/rgb/camera_info", + "camera_frame": "oak_rgb_camera_optical_frame" + }.items()) + + easy_handeye_calibration = IncludeLaunchDescription( + PythonLaunchDescriptionSource( + os.path.join(easy_handeye_prefix, 'launch', + 'calibrate.launch.py') + ), + launch_arguments={"calibration_type": "eye_on_base", + "name": calib_name_launch_arg.perform(context), + "robot_base_frame": "dx400/base_link", + "robot_effector_frame": "dx400/ee_gripper_link", + "tracking_base_frame": "oak_rgb_camera_optical_frame", + "tracking_marker_frame": "tag_5"}.items(), + condition=LaunchConfigurationEquals( + launch_configuration_name='calibrate', + expected_value='true' + )) + + easy_handeye_evaluation = IncludeLaunchDescription( + PythonLaunchDescriptionSource( + os.path.join(easy_handeye_prefix, 'launch', + 'evaluate.launch.py') + ), + launch_arguments={"name": calib_name_launch_arg. + perform(context)}.items(), + condition=LaunchConfigurationEquals( + launch_configuration_name='evaluate', + expected_value='true' + )) + + easy_handeye_publish = IncludeLaunchDescription( + PythonLaunchDescriptionSource( + os.path.join(easy_handeye_prefix, 'launch', + 'publish.launch.py') + ), + launch_arguments={"name": calib_name_launch_arg. + perform(context)}.items(), + condition=LaunchConfigurationEquals( + launch_configuration_name='publish', + expected_value='true' + )) + + + + return [ + interbotix_moveit, + spatial_rgbd1, + # spatial_rgbd2, + # spatial_rgbd3, + apriltag_detection, + easy_handeye_calibration, + # easy_handeye_evaluation, + # easy_handeye_publish, + + ] + + +def generate_launch_description(): + declared_arguments = [ + DeclareLaunchArgument( + 'calibrate', + default_value='false', + choices=('true', 'false'), + description="Launches Hand-Eye Calibration", + ), + DeclareLaunchArgument( + 'evaluate', + default_value='false', + choices=('true', 'false'), + description="Launches Hand-Eye Calibration Evaluation", + ), + DeclareLaunchArgument( + 'publish', + default_value='false', + choices=('true', 'false'), + description="Publishes Hand-Eye Calibration values", + ), + DeclareLaunchArgument( + 'calib_name', + default_value='eob_cam1', + description="Name of the calibration values to save", + ), + DeclareLaunchArgument( + 'cam1_name', + default_value='oak1', + description="Name of camera 1", + ), + DeclareLaunchArgument( + 'cam2_name', + default_value='oak2', + description="Name of camera 2", + ), + DeclareLaunchArgument( + 'cam3_name', + default_value='oak3', + description="Name of camera 3", + ) + ] + + return LaunchDescription(declared_arguments + [OpaqueFunction(function=launch_setup)]) diff --git a/hand_eye_calibration/package.xml b/hand_eye_calibration/package.xml new file mode 100644 index 0000000..d2a505f --- /dev/null +++ b/hand_eye_calibration/package.xml @@ -0,0 +1,36 @@ + + + + hand_eye_calibration + 0.0.0 + The interbotix_ros_calibration package + Pinak Jani + BSD-3-Clause + + ament_cmake + + apriltag_ros + cv_bridge + pcl_conversions + pcl_ros + launch + launch_ros + rclpy + tf2_ros + tf2_geometry_msgs + interbotix_xs_msgs + interbotix_perception_msgs + interbotix_perception_pipelines + interbotix_common_modules + visualization_msgs + std_srvs + sensor_msgs + tf_transformations + + + ament_python + + diff --git a/hand_eye_calibration/resource/hand_eye_calibration b/hand_eye_calibration/resource/hand_eye_calibration new file mode 100644 index 0000000..e69de29 diff --git a/hand_eye_calibration/setup.cfg b/hand_eye_calibration/setup.cfg new file mode 100644 index 0000000..05e6034 --- /dev/null +++ b/hand_eye_calibration/setup.cfg @@ -0,0 +1,4 @@ +[develop] +script_dir=$base/lib/hand_eye_calibration +[install] +install_scripts=$base/lib/hand_eye_calibration diff --git a/hand_eye_calibration/setup.py b/hand_eye_calibration/setup.py new file mode 100644 index 0000000..9bcb202 --- /dev/null +++ b/hand_eye_calibration/setup.py @@ -0,0 +1,31 @@ +from setuptools import find_packages, setup +from glob import glob +import os + +package_name = 'hand_eye_calibration' + +setup( + name=package_name, + version='0.0.0', + packages=find_packages(exclude=['test']), + data_files=[ + ('share/ament_index/resource_index/packages', + ['resource/' + package_name]), + ('share/' + package_name, ['package.xml']), + (os.path.join('share', package_name, 'launch'), + glob(os.path.join('launch', '*.launch.py'))), + (os.path.join('share', package_name, 'config'), + glob(os.path.join('config', '*.yaml'))), + ], + install_requires=['setuptools'], + zip_safe=True, + maintainer='Pinak Jani', + maintainer_email='pinakjani99@gmail.com', + description='The interbotix_ros_calibration package', + license='BSD', + tests_require=['pytest'], + entry_points={ + 'console_scripts': [ + ], + }, +) diff --git a/hand_eye_calibration/test/test_copyright.py b/hand_eye_calibration/test/test_copyright.py new file mode 100644 index 0000000..97a3919 --- /dev/null +++ b/hand_eye_calibration/test/test_copyright.py @@ -0,0 +1,25 @@ +# Copyright 2015 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ament_copyright.main import main +import pytest + + +# Remove the `skip` decorator once the source file(s) have a copyright header +@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.') +@pytest.mark.copyright +@pytest.mark.linter +def test_copyright(): + rc = main(argv=['.', 'test']) + assert rc == 0, 'Found errors' diff --git a/hand_eye_calibration/test/test_flake8.py b/hand_eye_calibration/test/test_flake8.py new file mode 100644 index 0000000..27ee107 --- /dev/null +++ b/hand_eye_calibration/test/test_flake8.py @@ -0,0 +1,25 @@ +# Copyright 2017 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ament_flake8.main import main_with_errors +import pytest + + +@pytest.mark.flake8 +@pytest.mark.linter +def test_flake8(): + rc, errors = main_with_errors(argv=[]) + assert rc == 0, \ + 'Found %d code style errors / warnings:\n' % len(errors) + \ + '\n'.join(errors) diff --git a/hand_eye_calibration/test/test_pep257.py b/hand_eye_calibration/test/test_pep257.py new file mode 100644 index 0000000..b234a38 --- /dev/null +++ b/hand_eye_calibration/test/test_pep257.py @@ -0,0 +1,23 @@ +# Copyright 2015 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ament_pep257.main import main +import pytest + + +@pytest.mark.linter +@pytest.mark.pep257 +def test_pep257(): + rc = main(argv=['.', 'test']) + assert rc == 0, 'Found code style errors / warnings'