7 | Compare two ObjectDetectionStatus messages.
8 |
9 |
10 | First ObjectDetectionStatus message to compare.
11 | Second ObjectDetectionStatus message to compare.
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | Captures an ObjectDetectionStatus message and makes it available on an output port.
20 |
21 |
22 | ObjectDetectionStatus topic the behavior subscribes to.
23 | Contains the message that was received on the topic.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/epick_hardware_tests/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | epick_hardware_tests
5 | 0.0.1
6 | ROS2 driver for the Robotiq EPick gripper.
7 | Giovanni Remigi
8 | BSD
9 | Giovanni Remigi
10 |
11 | ament_cmake
12 |
13 | launch
14 | launch_ros
15 | epick_driver
16 |
17 |
18 | ament_clang_format
19 |
20 | ament_clang_tidy
21 |
22 | ament_cmake_copyright
23 |
24 | ament_cmake_lint_cmake
25 |
26 | ament_lint_auto
27 |
28 | ament_lint_common
29 |
30 |
31 | ament_cmake
32 |
33 |
34 |
--------------------------------------------------------------------------------
/epick_moveit_plugin/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # See https://docs.ros.org/en/foxy/How-To-Guides/Ament-CMake-Documentation.html
2 |
3 | cmake_minimum_required(VERSION 3.8)
4 | project(epick_moveit_plugin VERSION 0.0.1 LANGUAGES CXX)
5 |
6 | # This module provides installation directories as per the GNU coding standards.
7 | include(GNUInstallDirs)
8 |
9 | set(CMAKE_EXPORT_COMPILE_COMMANDS true)
10 |
11 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
12 | add_compile_options(-Wall -Wextra -Wpedantic)
13 | endif()
14 |
15 | find_package(ament_cmake REQUIRED)
16 | find_package(moveit_ros_control_interface REQUIRED)
17 | find_package(moveit_simple_controller_manager REQUIRED)
18 | find_package(pluginlib REQUIRED)
19 |
20 | add_library(epick_gripper_controller_allocator SHARED
21 | src/epick_gripper_controller_allocator.cpp
22 | )
23 | ament_target_dependencies(epick_gripper_controller_allocator PUBLIC
24 | pluginlib
25 | moveit_ros_control_interface
26 | moveit_simple_controller_manager
27 | )
28 |
29 | # Register the Epick gripper controller allocator plugin with MoveIt's ros_control interface
30 | pluginlib_export_plugin_description_file(moveit_ros_control_interface moveit_ros_control_interface_plugins.xml)
31 |
32 | # Install our library.
33 | install(
34 | TARGETS epick_gripper_controller_allocator
35 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # lib
36 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # lib
37 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # bin
38 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # include
39 | )
40 |
41 | ament_package()
42 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2022, PickNik Robotics
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | 3. Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/epick_driver/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | epick_driver
5 | 0.0.1
6 | ROS2 driver for the Robotiq EPick gripper.
7 | Giovanni Remigi
8 | BSD
9 | Giovanni Remigi
10 |
11 | ament_cmake
12 |
13 | hardware_interface
14 | lifecycle_msgs
15 | pluginlib
16 | rclcpp_lifecycle
17 | serial
18 |
19 |
20 | ament_clang_format
21 |
22 | ament_clang_tidy
23 |
24 | ament_cmake_copyright
25 |
26 | ament_cmake_lint_cmake
27 |
28 | ament_lint_auto
29 |
30 | ament_lint_common
31 |
32 |
33 | ament_cmake_gmock
34 | ros2_control_test_assets
35 |
36 |
37 | ament_cmake
38 |
39 |
40 |
--------------------------------------------------------------------------------
/epick_moveit_studio/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.8)
2 | project(epick_moveit_studio LANGUAGES CXX)
3 |
4 | set(CMAKE_EXPORT_COMPILE_COMMANDS true)
5 |
6 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
7 | add_compile_options(-Wall -Wextra -Wpedantic)
8 | endif()
9 |
10 | find_package(ament_cmake REQUIRED)
11 | find_package(epick_msgs REQUIRED)
12 | find_package(moveit_studio_behavior_interface REQUIRED)
13 | find_package(pluginlib REQUIRED)
14 |
15 | add_library(epick_behaviors SHARED
16 | src/compare_epick_object_detection_status.cpp
17 | src/get_epick_object_detection_status.cpp
18 | src/behavior_loader.cpp
19 | )
20 | target_include_directories(epick_behaviors
21 | PUBLIC $
22 | PUBLIC $
23 | )
24 | target_link_libraries(epick_behaviors PUBLIC moveit_studio_behavior_interface::async_behavior_base)
25 | ament_target_dependencies(epick_behaviors PUBLIC
26 | epick_msgs
27 | moveit_studio_behavior_interface
28 | pluginlib
29 | )
30 |
31 | install(
32 | TARGETS
33 | epick_behaviors
34 | EXPORT export_${PROJECT_NAME}
35 | ARCHIVE DESTINATION lib
36 | LIBRARY DESTINATION lib
37 | RUNTIME DESTINATION bin
38 | INCLUDES DESTINATION include
39 | )
40 |
41 | install(
42 | DIRECTORY
43 | config
44 | DESTINATION share/${PROJECT_NAME}
45 | )
46 |
47 |
48 | if(BUILD_TESTING)
49 | add_subdirectory(test)
50 | endif()
51 |
52 | pluginlib_export_plugin_description_file(moveit_studio_behavior_interface behavior_plugin_description.xml)
53 |
54 | ament_export_include_directories(include)
55 | ament_export_libraries(epick_behaviors)
56 | ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
57 | ament_export_dependencies(epick_msgs moveit_studio_behavior_interface pluginlib)
58 | ament_package()
59 |
--------------------------------------------------------------------------------
/epick_description/urdf/helper_macros.xacro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | # To use:
2 | #
3 | # pre-commit run -a
4 | #
5 | # Or:
6 | #
7 | # pre-commit install # (runs every time you commit in git)
8 | #
9 | # To update this file:
10 | #
11 | # pre-commit autoupdate
12 | #
13 | # See https://github.com/pre-commit/pre-commit
14 | repos:
15 | # Standard hooks
16 | - repo: https://github.com/pre-commit/pre-commit-hooks
17 | rev: v4.4.0
18 | hooks:
19 | - id: check-added-large-files
20 | exclude: \.(stl|dae)$
21 | - id: check-ast
22 | - id: check-case-conflict
23 | - id: check-docstring-first
24 | - id: check-merge-conflict
25 | - id: check-symlinks
26 | - id: check-yaml
27 | args: ['--unsafe'] # Fixes errors parsing custom YAML constructors like ur_description's !degrees
28 | - id: debug-statements
29 | - id: end-of-file-fixer
30 | - id: mixed-line-ending
31 | - id: trailing-whitespace
32 | - id: fix-byte-order-marker
33 |
34 | - repo: https://github.com/psf/black
35 | rev: 23.3.0
36 | hooks:
37 | - id: black
38 |
39 | - repo: https://github.com/pycqa/flake8
40 | rev: 5.0.4
41 | hooks:
42 | - id: flake8
43 | # configured in .flake8 file
44 |
45 | - repo: https://github.com/codespell-project/codespell
46 | rev: v2.2.5
47 | hooks:
48 | - id: codespell
49 | args: ['--write-changes', '-L', 'atleast,inout'] # Provide a comma-separated list of misspelled words that codespell should ignore (for example: '-L', 'word1,word2,word3').
50 | exclude: \.(svg|pyc|stl|dae|lock)$
51 |
52 | - repo: https://github.com/pre-commit/mirrors-clang-format
53 | rev: v16.0.6
54 | hooks:
55 | - id: clang-format
56 | name: clang-format
57 | description: Format files with ClangFormat.
58 | entry: clang-format-14
59 | language: system
60 | files: \.(c|cc|cxx|cpp|frag|glsl|h|hpp|hxx|ih|ispc|ipp|java|m|proto|vert)$
61 | args: ['-fallback-style=none', '-i']
62 |
--------------------------------------------------------------------------------
/epick_driver/include/epick_driver/visibility_control.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #define EPICK_DRIVER_EXPORT __attribute__((visibility("default")))
32 | #define EPICK_DRIVER_IMPORT
33 | #define EPICK_DRIVER_PUBLIC __attribute__((visibility("default")))
34 | #define EPICK_DRIVER_LOCAL __attribute__((visibility("hidden")))
35 | #define EPICK_DRIVER_PUBLIC_TYPE
36 |
--------------------------------------------------------------------------------
/epick_hardware_tests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # See https://docs.ros.org/en/foxy/How-To-Guides/Ament-CMake-Documentation.html
2 |
3 | cmake_minimum_required(VERSION 3.8)
4 | project(epick_hardware_tests VERSION 0.0.1 LANGUAGES CXX)
5 |
6 | # This module provides installation directories as per the GNU coding standards.
7 | include(GNUInstallDirs)
8 |
9 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
10 | add_compile_options(-Wall -Wextra -Wpedantic)
11 | endif()
12 |
13 | find_package(ament_cmake REQUIRED)
14 | find_package(hardware_interface REQUIRED)
15 | find_package(pluginlib REQUIRED)
16 | find_package(rclcpp REQUIRED)
17 | find_package(serial REQUIRED)
18 | find_package(epick_driver REQUIRED)
19 |
20 | set(THIS_PACKAGE_INCLUDE_DEPENDS
21 | ament_cmake
22 | hardware_interface
23 | pluginlib
24 | rclcpp
25 | rclcpp_lifecycle
26 | serial
27 | )
28 |
29 | add_executable(activate
30 | src/activate.cpp
31 | src/command_line_utility.hpp
32 | src/command_line_utility.cpp
33 | )
34 | ament_target_dependencies(activate epick_driver)
35 |
36 | add_executable(deactivate
37 | src/deactivate.cpp
38 | src/command_line_utility.hpp
39 | src/command_line_utility.cpp
40 | )
41 | ament_target_dependencies(deactivate epick_driver)
42 |
43 | add_executable(get_status
44 | src/get_status.cpp
45 | src/command_line_utility.hpp
46 | src/command_line_utility.cpp
47 | )
48 | ament_target_dependencies(get_status epick_driver)
49 |
50 | add_executable(grip
51 | src/grip.cpp
52 | src/command_line_utility.hpp
53 | src/command_line_utility.cpp
54 | )
55 | ament_target_dependencies(grip epick_driver)
56 |
57 | add_executable(release
58 | src/release.cpp
59 | src/command_line_utility.hpp
60 | src/command_line_utility.cpp
61 | )
62 | ament_target_dependencies(release epick_driver)
63 |
64 | add_executable(break
65 | src/break.cpp
66 | src/command_line_utility.hpp
67 | src/command_line_utility.cpp
68 | )
69 | ament_target_dependencies(break epick_driver)
70 |
71 | ament_package()
72 |
--------------------------------------------------------------------------------
/epick_driver/include/epick_driver/crc_utils.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 | #include
33 |
34 | namespace epick_driver::crc_utils
35 | {
36 | /**
37 | * @brief Compute the CRC for the CRC-16 MODBUS protocol.
38 | * @param data The data to compute the CRC for.
39 | * @return A 16-bits CRC.
40 | */
41 | uint16_t compute_crc(const std::vector& data);
42 | } // namespace epick_driver::crc_utils
43 |
--------------------------------------------------------------------------------
/epick_driver/tests/test_data_utils.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #include
30 |
31 | #include
32 |
33 | namespace epick_driver::test
34 | {
35 | TEST(TestDataUtils, to_lower)
36 | {
37 | const char* str1 = "HeLlO";
38 | ASSERT_EQ(data_utils::to_lower(str1), "hello");
39 |
40 | std::string str2{ "HeLlO" };
41 | ASSERT_EQ(data_utils::to_lower(str2), "hello");
42 | }
43 | } // namespace epick_driver::test
44 |
--------------------------------------------------------------------------------
/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | BasedOnStyle: Google
3 | ColumnLimit: 120
4 | MaxEmptyLinesToKeep: 1
5 | SortIncludes: false
6 |
7 | Standard: Auto
8 | IndentWidth: 2
9 | TabWidth: 2
10 | UseTab: Never
11 | AccessModifierOffset: -2
12 | ConstructorInitializerIndentWidth: 2
13 | NamespaceIndentation: None
14 | ContinuationIndentWidth: 4
15 | IndentCaseLabels: true
16 | IndentFunctionDeclarationAfterType: false
17 |
18 | AlignEscapedNewlinesLeft: false
19 | AlignTrailingComments: true
20 |
21 | AllowAllParametersOfDeclarationOnNextLine: false
22 | ExperimentalAutoDetectBinPacking: false
23 | ObjCSpaceBeforeProtocolList: true
24 | Cpp11BracedListStyle: false
25 |
26 | AllowShortBlocksOnASingleLine: true
27 | AllowShortIfStatementsOnASingleLine: false
28 | AllowShortLoopsOnASingleLine: false
29 | AllowShortFunctionsOnASingleLine: None
30 | AllowShortCaseLabelsOnASingleLine: false
31 |
32 | AlwaysBreakTemplateDeclarations: true
33 | AlwaysBreakBeforeMultilineStrings: false
34 | BreakBeforeBinaryOperators: false
35 | BreakBeforeTernaryOperators: false
36 | BreakConstructorInitializersBeforeComma: true
37 |
38 | BinPackParameters: true
39 | ConstructorInitializerAllOnOneLineOrOnePerLine: true
40 | DerivePointerBinding: false
41 | PointerBindsToType: true
42 |
43 | PenaltyExcessCharacter: 50
44 | PenaltyBreakBeforeFirstCallParameter: 30
45 | PenaltyBreakComment: 1000
46 | PenaltyBreakFirstLessLess: 10
47 | PenaltyBreakString: 100
48 | PenaltyReturnTypeOnItsOwnLine: 50
49 |
50 | SpacesBeforeTrailingComments: 2
51 | SpacesInParentheses: false
52 | SpacesInAngles: false
53 | SpaceInEmptyParentheses: false
54 | SpacesInCStyleCastParentheses: false
55 | SpaceAfterCStyleCast: false
56 | SpaceAfterControlStatementKeyword: true
57 | SpaceBeforeAssignmentOperators: true
58 |
59 | # Configure each individual brace in BraceWrapping
60 | BreakBeforeBraces: Custom
61 |
62 | # Control of individual brace wrapping cases
63 | BraceWrapping:
64 | AfterCaseLabel: true
65 | AfterClass: true
66 | AfterControlStatement: true
67 | AfterEnum: true
68 | AfterFunction: true
69 | AfterNamespace: true
70 | AfterStruct: true
71 | AfterUnion: true
72 | BeforeCatch: true
73 | BeforeElse: true
74 | IndentBraces: false
75 | ...
76 |
--------------------------------------------------------------------------------
/.clang-tidy:
--------------------------------------------------------------------------------
1 | ---
2 | # TODO(henningkayser): Re-enable performance-unnecessary-value-param once #214 is resolved
3 | Checks: '-*,
4 | performance-*,
5 | -performance-unnecessary-value-param,
6 | llvm-namespace-comment,
7 | modernize-redundant-void-arg,
8 | modernize-use-nullptr,
9 | modernize-use-default,
10 | modernize-use-override,
11 | modernize-loop-convert,
12 | readability-named-parameter,
13 | readability-redundant-smartptr-get,
14 | readability-redundant-string-cstr,
15 | readability-simplify-boolean-expr,
16 | readability-container-size-empty,
17 | readability-identifier-naming,
18 | '
19 | HeaderFilterRegex: ''
20 | AnalyzeTemporaryDtors: false
21 | CheckOptions:
22 | - key: llvm-namespace-comment.ShortNamespaceLines
23 | value: '10'
24 | - key: llvm-namespace-comment.SpacesBeforeComments
25 | value: '2'
26 | - key: readability-braces-around-statements.ShortStatementLines
27 | value: '2'
28 | # type names
29 | - key: readability-identifier-naming.ClassCase
30 | value: CamelCase
31 | - key: readability-identifier-naming.EnumCase
32 | value: CamelCase
33 | - key: readability-identifier-naming.UnionCase
34 | value: CamelCase
35 | # method names
36 | - key: readability-identifier-naming.MethodCase
37 | value: camelBack
38 | # variable names
39 | - key: readability-identifier-naming.VariableCase
40 | value: lower_case
41 | - key: readability-identifier-naming.ClassMemberSuffix
42 | value: '_'
43 | # const static or global variables are UPPER_CASE
44 | - key: readability-identifier-naming.EnumConstantCase
45 | value: UPPER_CASE
46 | - key: readability-identifier-naming.StaticConstantCase
47 | value: UPPER_CASE
48 | - key: readability-identifier-naming.ClassConstantCase
49 | value: UPPER_CASE
50 | - key: readability-identifier-naming.GlobalVariableCase
51 | value: UPPER_CASE
52 | ...
53 |
--------------------------------------------------------------------------------
/epick_driver/include/epick_driver/default_serial_factory.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 |
33 | #include
34 | #include
35 | #include
36 |
37 | namespace epick_driver
38 | {
39 | /**
40 | * This class is used to create a default driver to interact with the hardware.
41 | */
42 | class DefaultSerialFactory : public SerialFactory
43 | {
44 | public:
45 | DefaultSerialFactory() = default;
46 |
47 | /**
48 | * @brief Create a serial interface.
49 | * @param info The hardware information.
50 | * @return A sarial interface to communicate with the hardware.
51 | */
52 | std::unique_ptr create(const hardware_interface::HardwareInfo& info) const;
53 |
54 | protected:
55 | // Seam for testing.
56 | virtual std::unique_ptr create_serial() const;
57 | };
58 | } // namespace epick_driver
59 |
--------------------------------------------------------------------------------
/epick_driver/include/epick_driver/driver_factory.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 |
33 | #include
34 |
35 | #include
36 |
37 | namespace epick_driver
38 | {
39 | /**
40 | * The hardware interface internally uses a factory to create and configure a
41 | * driver to interact with the Epick Gripper.
42 | * A factory is used to keep the code cleaner but also to simplify testing.
43 | * With a factory, we can test that the parameters read by the hardware
44 | * interface are correctly parsed and passed down to the driver.
45 | * A factory can also be mocked to return different implementation of the
46 | * Driver (or mocks) that do not require interaction with the real hardware.
47 | */
48 | class DriverFactory
49 | {
50 | public:
51 | virtual std::unique_ptr create(const hardware_interface::HardwareInfo& info) const = 0;
52 | };
53 | } // namespace epick_driver
54 |
--------------------------------------------------------------------------------
/epick_driver/include/epick_driver/default_driver_factory.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 |
33 | #include
34 | #include
35 | #include
36 |
37 | namespace epick_driver
38 | {
39 | /**
40 | * This class is used to create a default driver to interact with the hardware.
41 | */
42 | class DefaultDriverFactory : public DriverFactory
43 | {
44 | public:
45 | DefaultDriverFactory() = default;
46 |
47 | /**
48 | * @brief Create a driver.
49 | * @param info The hardware information.
50 | * @return A driver to interact with the hardware.
51 | */
52 | std::unique_ptr create(const hardware_interface::HardwareInfo& info) const;
53 |
54 | protected:
55 | // Seam for testing.
56 | virtual std::unique_ptr create_driver(const hardware_interface::HardwareInfo& info) const;
57 | };
58 | } // namespace epick_driver
59 |
--------------------------------------------------------------------------------
/epick_driver/include/epick_driver/driver_exception.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | namespace epick_driver
36 | {
37 | /**
38 | * This is a custom exception thrown by the Driver.
39 | */
40 | class DriverException : public std::exception
41 | {
42 | std::string what_;
43 |
44 | public:
45 | explicit DriverException(const std::string& description)
46 | {
47 | std::stringstream ss;
48 | ss << "DriverException: " << description << ".";
49 | what_ = ss.str();
50 | }
51 |
52 | DriverException(const DriverException& other) : what_(other.what_)
53 | {
54 | }
55 |
56 | ~DriverException() override = default;
57 |
58 | // Disable copy constructors
59 | DriverException& operator=(const DriverException&) = delete;
60 |
61 | [[nodiscard]] const char* what() const throw() override
62 | {
63 | return what_.c_str();
64 | }
65 | };
66 | } // namespace epick_driver
67 |
--------------------------------------------------------------------------------
/epick_driver/tests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Add support for GTest.
2 | find_package(ament_cmake_gtest REQUIRED)
3 | find_package(ament_cmake_gmock REQUIRED)
4 | find_package(ament_lint_auto REQUIRED)
5 | find_package(ros2_control_test_assets REQUIRED)
6 |
7 | ament_lint_auto_find_test_dependencies()
8 |
9 | # GMock throws an error if we don't switch off this option in tests.
10 | if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
11 | add_compile_options(-Wno-sign-conversion)
12 | endif()
13 |
14 | ###############################################################################
15 | # test_default_driver
16 |
17 | ament_add_gmock(test_default_driver
18 | test_default_driver.cpp
19 | mock/mock_serial.hpp
20 | )
21 | target_include_directories(test_default_driver
22 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
23 | )
24 | target_link_libraries(test_default_driver epick_driver)
25 |
26 | ###############################################################################
27 | # test_epick_gripper_hardware_interface
28 |
29 | ament_add_gmock(test_epick_gripper_hardware_interface
30 | test_epick_gripper_hardware_interface.cpp
31 | )
32 | target_include_directories(test_epick_gripper_hardware_interface
33 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
34 | )
35 | target_link_libraries(test_epick_gripper_hardware_interface epick_driver)
36 | ament_target_dependencies(test_epick_gripper_hardware_interface
37 | ros2_control_test_assets
38 | )
39 |
40 | ###############################################################################
41 | # test_default_serial_factory
42 |
43 | ament_add_gmock(test_default_serial_factory
44 | test_default_serial_factory.cpp
45 | mock/mock_serial.hpp
46 | )
47 | target_include_directories(test_default_serial_factory
48 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
49 | )
50 | target_link_libraries(test_default_serial_factory epick_driver)
51 |
52 | ###############################################################################
53 | # test_default_driver_factory
54 |
55 | ament_add_gmock(test_default_driver_factory
56 | test_default_driver_factory.cpp
57 | mock/mock_driver.hpp
58 | )
59 | target_include_directories(test_default_driver_factory
60 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
61 | )
62 | target_link_libraries(test_default_driver_factory epick_driver)
63 |
64 | ###############################################################################
65 | # test_data_utils
66 |
67 | ament_add_gmock(test_data_utils
68 | test_data_utils.cpp
69 | )
70 | target_include_directories(test_data_utils
71 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
72 | )
73 | target_link_libraries(test_data_utils epick_driver)
74 |
--------------------------------------------------------------------------------
/epick_driver/include/epick_driver/serial_factory.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 |
33 | #include
34 |
35 | #include
36 |
37 | namespace epick_driver
38 | {
39 | /**
40 | * This factory is used to create and configure a Serial interface
41 | * implementation that is used by the driver to interact with the hardware.
42 | * A factory is used to keep the code cleaner but also to simplify testing.
43 | * With a factory, we can test that the parameters read by the hardware
44 | * interface are correctly parsed and passed down to the serial interface.
45 | * A factory can also be mocked to return different implementation of the
46 | * serial interface (or mocks) that do not require interaction with the real
47 | * hardware.
48 | */
49 | class SerialFactory
50 | {
51 | public:
52 | virtual std::unique_ptr create(const hardware_interface::HardwareInfo& info) const = 0;
53 | };
54 |
55 | } // namespace epick_driver
56 |
--------------------------------------------------------------------------------
/epick_description/urdf/epick_body.xacro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
22 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/epick_driver/tests/mock/mock_serial.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 |
33 | #include
34 | #include
35 |
36 | #include
37 |
38 | namespace epick_driver::test
39 | {
40 | class MockSerial : public epick_driver::Serial
41 | {
42 | public:
43 | MOCK_METHOD(void, open, (), (override));
44 | MOCK_METHOD(bool, is_open, (), (override, const));
45 | MOCK_METHOD(void, close, (), (override));
46 | MOCK_METHOD(std::vector, read, (size_t size), (override));
47 | MOCK_METHOD(void, write, (const std::vector& buffer), (override));
48 | MOCK_METHOD(void, set_port, (const std::string& port), (override));
49 | MOCK_METHOD(std::string, get_port, (), (override, const));
50 | MOCK_METHOD(void, set_timeout, (std::chrono::milliseconds timeout), (override));
51 | MOCK_METHOD(std::chrono::milliseconds, get_timeout, (), (override, const));
52 | MOCK_METHOD(void, set_baudrate, (uint32_t baudrate), (override));
53 | MOCK_METHOD(uint32_t, get_baudrate, (), (override, const));
54 | };
55 | } // namespace epick_driver::test
56 |
--------------------------------------------------------------------------------
/epick_controllers/include/epick_controllers/epick_status_publisher_controller.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | namespace epick_controllers
36 | {
37 | class EpickStatusPublisherController : public controller_interface::ControllerInterface
38 | {
39 | public:
40 | controller_interface::InterfaceConfiguration command_interface_configuration() const override;
41 |
42 | controller_interface::InterfaceConfiguration state_interface_configuration() const override;
43 |
44 | controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override;
45 |
46 | CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override;
47 |
48 | CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override;
49 |
50 | CallbackReturn on_init() override;
51 |
52 | private:
53 | rclcpp::Publisher::SharedPtr object_detection_status_pub_;
54 | };
55 | } // namespace epick_controllers
56 |
--------------------------------------------------------------------------------
/epick_driver/tests/mock/mock_driver.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 |
33 | #include
34 |
35 | #include
36 |
37 | namespace epick_driver::test
38 | {
39 | class MockDriver : public epick_driver::Driver
40 | {
41 | public:
42 | MOCK_METHOD(void, set_slave_address, (uint8_t slave_address), (override));
43 | MOCK_METHOD(void, set_mode, (GripperMode mode), (override));
44 | MOCK_METHOD(void, set_grip_max_vacuum_pressure, (float vacuum_pressure), (override));
45 | MOCK_METHOD(void, set_grip_min_vacuum_pressure, (float vacuum_pressure), (override));
46 | MOCK_METHOD(void, set_grip_timeout, (std::chrono::milliseconds grip_timeout), (override));
47 | MOCK_METHOD(void, set_release_timeout, (std::chrono::milliseconds release_timeout), (override));
48 | MOCK_METHOD(bool, connect, (), (override));
49 | MOCK_METHOD(void, disconnect, (), (override));
50 | MOCK_METHOD(void, activate, (), (override));
51 | MOCK_METHOD(void, deactivate, (), (override));
52 | MOCK_METHOD(void, grip, (), (override));
53 | MOCK_METHOD(void, release, (), (override));
54 | MOCK_METHOD(GripperStatus, get_status, (), (override));
55 | };
56 | } // namespace epick_driver::test
57 |
--------------------------------------------------------------------------------
/epick_driver/include/epick_driver/default_serial.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 |
33 | #include
34 | #include
35 | #include
36 |
37 | #include
38 |
39 | namespace serial
40 | {
41 | class Serial;
42 | }
43 |
44 | namespace epick_driver
45 | {
46 | class DefaultSerial : public Serial
47 | {
48 | public:
49 | /**
50 | * Creates a Serial object to send and receive bytes to and from the serial
51 | * port.
52 | */
53 | DefaultSerial();
54 |
55 | void open() override;
56 |
57 | [[nodiscard]] bool is_open() const override;
58 |
59 | void close() override;
60 |
61 | [[nodiscard]] std::vector read(size_t size = 1) override;
62 | void write(const std::vector& data) override;
63 |
64 | void set_port(const std::string& port) override;
65 | [[nodiscard]] std::string get_port() const override;
66 |
67 | void set_timeout(std::chrono::milliseconds timeout_ms) override;
68 | [[nodiscard]] std::chrono::milliseconds get_timeout() const override;
69 |
70 | void set_baudrate(uint32_t baudrate) override;
71 | [[nodiscard]] uint32_t get_baudrate() const override;
72 |
73 | private:
74 | std::unique_ptr serial_ = nullptr;
75 | };
76 | } // namespace epick_driver
77 |
--------------------------------------------------------------------------------
/epick_moveit_studio/src/get_epick_object_detection_status.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #include
30 |
31 | #include
32 | #include
33 |
34 | namespace
35 | {
36 | /** @brief Maximum duration to wait for a message to be published before failing. */
37 | constexpr auto kWaitDuration = std::chrono::seconds{ 1 };
38 | } // namespace
39 |
40 | namespace epick_moveit_studio
41 | {
42 | GetEpickObjectDetectionStatus::GetEpickObjectDetectionStatus(
43 | const std::string& name, const BT::NodeConfiguration& config,
44 | const std::shared_ptr& shared_resources)
45 | : moveit_studio::behaviors::GetMessageFromTopicBehaviorBase(name, config,
46 | shared_resources)
47 | {
48 | }
49 |
50 | tl::expected, std::string> GetEpickObjectDetectionStatus::getWaitForMessageTimeout()
51 | {
52 | return kWaitDuration;
53 | }
54 |
55 | } // namespace epick_moveit_studio
56 |
57 | template class moveit_studio::behaviors::GetMessageFromTopicBehaviorBase;
58 |
--------------------------------------------------------------------------------
/epick_controllers/include/epick_controllers/epick_controller.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | namespace epick_controllers
36 | {
37 | class EpickController : public controller_interface::ControllerInterface
38 | {
39 | public:
40 | controller_interface::InterfaceConfiguration command_interface_configuration() const override;
41 |
42 | controller_interface::InterfaceConfiguration state_interface_configuration() const override;
43 |
44 | controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override;
45 |
46 | CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override;
47 |
48 | CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override;
49 |
50 | CallbackReturn on_init() override;
51 |
52 | private:
53 | // When we send a true, the gripper will begin to grip, when false the gripper will release.
54 | rclcpp::Service::SharedPtr grip_srv_;
55 |
56 | // The logic of the server to control the gripper.
57 | bool grip_cmd(std_srvs::srv::SetBool::Request::SharedPtr request,
58 | std_srvs::srv::SetBool::Response::SharedPtr response);
59 | };
60 | } // namespace epick_controllers
61 |
--------------------------------------------------------------------------------
/epick_moveit_studio/src/behavior_loader.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | // Include headers for your custom Behaviors
36 | #include
37 | #include
38 |
39 | namespace epick_moveit_studio
40 | {
41 | class BehaviorLoader : public moveit_studio::behaviors::SharedResourcesNodeLoaderBase
42 | {
43 | public:
44 | void registerBehaviors(BT::BehaviorTreeFactory& factory,
45 | const std::shared_ptr& shared_resources) override
46 | {
47 | moveit_studio::behaviors::registerBehavior(factory,
48 | "CompareEpickObjectDetectionStatus");
49 | moveit_studio::behaviors::registerBehavior(factory, "GetEpickObjectDetectionStatus",
50 | shared_resources);
51 | }
52 | };
53 |
54 | } // namespace epick_moveit_studio
55 |
56 | PLUGINLIB_EXPORT_CLASS(epick_moveit_studio::BehaviorLoader, moveit_studio::behaviors::SharedResourcesNodeLoaderBase);
57 |
--------------------------------------------------------------------------------
/epick_moveit_studio/src/compare_epick_object_detection_status.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | namespace
35 | {
36 | constexpr auto kPortIDValue1 = "value1";
37 | constexpr auto kPortIDValue2 = "value2";
38 | } // namespace
39 |
40 | namespace epick_moveit_studio
41 | {
42 | CompareEpickObjectDetectionStatus::CompareEpickObjectDetectionStatus(const std::string& name,
43 | const BT::NodeConfiguration& config)
44 | : BT::SyncActionNode(name, config)
45 | {
46 | }
47 |
48 | BT::PortsList CompareEpickObjectDetectionStatus::providedPorts()
49 | {
50 | return BT::PortsList{
51 | BT::InputPort(kPortIDValue1),
52 | BT::InputPort(kPortIDValue2),
53 | };
54 | }
55 |
56 | BT::NodeStatus CompareEpickObjectDetectionStatus::tick()
57 | {
58 | const auto value1 = getInput(kPortIDValue1);
59 | const auto value2 = getInput(kPortIDValue2);
60 |
61 | if (!value1.has_value() || !value2.has_value())
62 | {
63 | return BT::NodeStatus::FAILURE;
64 | }
65 |
66 | if (value1.value().status == value2.value().status)
67 | {
68 | return BT::NodeStatus::SUCCESS;
69 | }
70 | else
71 | {
72 | return BT::NodeStatus::FAILURE;
73 | }
74 | }
75 | } // namespace epick_moveit_studio
76 |
--------------------------------------------------------------------------------
/epick_hardware_tests/src/command_line_utility.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #include "command_line_utility.hpp"
30 |
31 | #include
32 |
33 | void CommandLineUtility::registerHandler(const std::string& parameter, ParameterHandler handler, bool isMandatory)
34 | {
35 | handlers[parameter] = handler;
36 | if (isMandatory)
37 | {
38 | mandatoryParams.insert(parameter);
39 | }
40 | }
41 |
42 | bool CommandLineUtility::parse(int argc, char* argv[])
43 | {
44 | for (int i = 1; i < argc; i++)
45 | {
46 | auto it = handlers.find(argv[i]);
47 | if (it != handlers.end())
48 | {
49 | receivedParams.insert(it->first);
50 |
51 | if (std::holds_alternative(it->second))
52 | {
53 | auto& handler = std::get(it->second);
54 | i++;
55 | if (i < argc)
56 | {
57 | handler(argv[i]);
58 | }
59 | else
60 | {
61 | std::cerr << it->first << " requires a value.\n";
62 | }
63 | }
64 | else if (std::holds_alternative(it->second))
65 | {
66 | auto& handler = std::get(it->second);
67 | handler();
68 | }
69 | }
70 | else
71 | {
72 | std::cerr << "Unknown argument: " << argv[i] << "\n";
73 | return false;
74 | }
75 | }
76 |
77 | for (const auto& param : mandatoryParams)
78 | {
79 | if (receivedParams.find(param) == receivedParams.end())
80 | {
81 | std::cerr << "Missing mandatory argument: " << param << "\n";
82 | return false;
83 | }
84 | }
85 |
86 | return true;
87 | }
88 |
--------------------------------------------------------------------------------
/epick_hardware_tests/src/command_line_utility.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 PickNik, Inc.
2 | //
3 | // Redistribution and use in source and binary forms, with or without
4 | // modification, are permitted provided that the following conditions are met:
5 | //
6 | // * Redistributions of source code must retain the above copyright
7 | // notice, this list of conditions and the following disclaimer.
8 | //
9 | // * Redistributions in binary form must reproduce the above copyright
10 | // notice, this list of conditions and the following disclaimer in the
11 | // documentation and/or other materials provided with the distribution.
12 | //
13 | // * Neither the name of the {copyright_holder} nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | // POSSIBILITY OF SUCH DAMAGE.
28 |
29 | #pragma once
30 |
31 | #include
32 | #include