diff --git a/.github/workflows/cpp-lint.yml b/.github/workflows/cpp-lint.yml deleted file mode 100644 index 77ea83d..0000000 --- a/.github/workflows/cpp-lint.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Cpp lint - -on: - pull_request: - push: - branches: [humble-devel] - -jobs: - clang-format-check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: RafikFarhad/clang-format-github-action@v3 - with: - sources: "src/**/*.h,src/**/*.c,test/**/*.c" - misspellings-check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: codespell-project/actions-codespell@v2 - with: - check_filenames: true - check_hidden: true diff --git a/.github/workflows/pre-commit_prek.yaml b/.github/workflows/pre-commit_prek.yaml new file mode 100644 index 0000000..eca26a0 --- /dev/null +++ b/.github/workflows/pre-commit_prek.yaml @@ -0,0 +1,11 @@ +--- +name: Pre-commit (Prek) + +on: [push] + +jobs: + prek: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: j178/prek-action@v1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fc71b55..7d08dcc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,159 +1,61 @@ -# Config based on: -# https://github.com/UniversalRobots/Universal_Robots_ROS2_Driver/blob/humble/.pre-commit-config.yaml -# To use: -# -# pre-commit run -a -# -# Or: -# -# pre-commit install # (runs every time you commit in git) -# -# To update this file: -# -# pre-commit autoupdate -# -# See https://github.com/pre-commit/pre-commit - repos: - # Standard hooks - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 - hooks: - - id: check-added-large-files - - id: check-ast - - id: check-byte-order-marker # Forbid UTF-8 byte-order markers - - id: check-case-conflict - - id: check-docstring-first - - id: check-merge-conflict - - id: check-symlinks - - id: check-xml - - id: check-yaml - - id: debug-statements - - id: destroyed-symlinks - - id: detect-private-key - - id: end-of-file-fixer - - id: mixed-line-ending - - id: trailing-whitespace - - # Python hooks - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.2 - hooks: - - id: pyupgrade - args: [--py310-plus] - - - repo: https://github.com/psf/black - rev: 22.3.0 - hooks: - - id: black - args: ["--line-length=100"] - - - repo: https://github.com/pycqa/pydocstyle - rev: 6.1.1 - hooks: - - id: pydocstyle - args: - [ - "--ignore=D100,D101,D102,D103,D104,D105,D106,D107,D203,D212,D401,D404", - ] - - - repo: https://github.com/pycqa/flake8 - rev: 3.9.0 - hooks: - - id: flake8 - args: ["--ignore=E501,W503"] - - # CPP hooks - # The same options as in ament_cppcheck are used, but its not working... - #- repo: https://github.com/pocc/pre-commit-hooks - #rev: v1.1.1 - #hooks: - #- id: cppcheck - #args: ['--error-exitcode=1', '-f', '--inline-suppr', '-q', '-rp', '--suppress=internalAstError', '--suppress=unknownMacro', '--verbose'] - - - repo: local - hooks: - - id: ament_cppcheck - name: ament_cppcheck - description: Static code analysis of C/C++ files. - stages: [commit] - entry: env AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS=1 ament_cppcheck - language: system - files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$ - - # Maybe use https://github.com/cpplint/cpplint instead - # TODO(macale) run it before release - # - repo: local - # hooks: - # - id: ament_cpplint - # name: ament_cpplint - # description: Static code analysis of C/C++ files. - # stages: [commit] - # entry: ament_cpplint - # language: system - # files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$ - # args: ["--linelength=120"] - - - repo: local - hooks: - - id: clang-format - name: clang-format - description: Format files with ClangFormat. - entry: clang-format-14 - language: system - files: \.(c|cc|cxx|cpp|frag|glsl|h|hpp|hxx|ih|ispc|ipp|java|js|m|proto|vert)$ - args: ["-fallback-style=none", "-i"] - - # Cmake hooks - - repo: https://github.com/cheshirekow/cmake-format-precommit - rev: v0.6.10 - hooks: - # Note: Do not use format - the wrapping function is bugged - # https://github.com/cheshirekow/cmake_format/issues/180 - - id: cmake-lint - args: ["--disable", "C0103"] - - repo: local - hooks: - - id: ament_lint_cmake - name: ament_lint_cmake - description: Check format of CMakeLists.txt files. - stages: [commit] - entry: ament_lint_cmake - args: ["--filter=-readability/wonkycase"] - language: system - files: CMakeLists.txt$ - - # Copyright - # TODO: turn on on public code release - # - repo: local - # hooks: - # - id: ament_copyright - # name: ament_copyright - # description: Check if copyright notice is available in all files. - # stages: [commit] - # entry: ament_copyright - # language: system - # args: ['--exclude', 'ur_robot_driver/doc/conf.py'] - - # Docs - RestructuredText hooks - - repo: https://github.com/PyCQA/doc8 - rev: 0.9.0a1 - hooks: - - id: doc8 - args: ["--max-line-length=100", "--ignore=D001"] - - - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.8.0 - hooks: - - id: rst-backticks - - id: rst-directive-colons - - id: rst-inline-touching-normal - - # Spellcheck in comments and docs - # skipping of *.svg files is not working... - - repo: https://github.com/codespell-project/codespell - rev: v2.0.0 - hooks: - - id: codespell - args: ["--write-changes"] - exclude: \.(svg|pyc|drawio)$ +- repo: https://gitlab.com/vojko.pribudic.foss/pre-commit-update + rev: v0.9.0 + hooks: + - id: pre-commit-update + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-added-large-files + - id: check-ast + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-json + - id: check-merge-conflict + - id: check-symlinks + - id: check-toml + - id: check-xml + - id: debug-statements + - id: destroyed-symlinks + - id: detect-private-key + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: mixed-line-ending + - id: trailing-whitespace + - id: check-yaml + - id: pretty-format-json + args: ["--autofix", "--no-sort-keys", "--indent", "2"] + +- repo: https://github.com/codespell-project/codespell + rev: v2.4.2 + hooks: + - id: codespell + args: [-w] + +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.15.8 + hooks: + - id: ruff-check + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + +- repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + - id: cmake-lint + +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v22.1.1 + hooks: + - id: clang-format + types_or: [c++, proto] + +- repo: https://github.com/tier4/pre-commit-hooks-ros + rev: v0.10.2 + hooks: + - id: prettier-xacro + - id: prettier-package-xml + - id: ros-include-guard + - id: sort-package-xml diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a87fb8..5b0fdea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,51 +13,25 @@ find_package(moveit_ros_planning_interface REQUIRED) find_package(std_msgs REQUIRED) find_package(yaml-cpp REQUIRED) include(FetchContent) -FetchContent_Declare( - argparse - GIT_REPOSITORY https://github.com/p-ranav/argparse.git -) +FetchContent_Declare(argparse + GIT_REPOSITORY https://github.com/p-ranav/argparse.git) FetchContent_MakeAvailable(argparse) -set( - SOURCE_FILES - src/args_parser.cpp - src/scene_objects_manager.cpp - src/spawner.cpp - src/yaml_parser.cpp -) +set(SOURCE_FILES src/args_parser.cpp src/scene_objects_manager.cpp + src/spawner.cpp src/yaml_parser.cpp) add_executable(${PROJECT_NAME} ${SOURCE_FILES}) -ament_target_dependencies( - ${PROJECT_NAME} - moveit_ros_planning_interface - rclcpp - std_msgs -) +ament_target_dependencies(${PROJECT_NAME} moveit_ros_planning_interface rclcpp + std_msgs) target_include_directories( - ${PROJECT_NAME} PUBLIC - "$" - "$" - ${argparse_SOURCE_DIR}/argparse/include -) - -target_link_libraries( ${PROJECT_NAME} - argparse - yaml-cpp -) - -install( - TARGETS ${PROJECT_NAME} - DESTINATION lib/${PROJECT_NAME} -) - -if(BUILD_TESTING) - find_package(ament_lint_auto REQUIRED) - set(ament_cmake_copyright_FOUND TRUE) - set(ament_cmake_cpplint_FOUND TRUE) - ament_lint_auto_find_test_dependencies() -endif() + PUBLIC "$" + "$" + ${argparse_SOURCE_DIR}/argparse/include) + +target_link_libraries(${PROJECT_NAME} argparse yaml-cpp) + +install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME}) ament_package() diff --git a/include/scene_objects_manager/args_parser.hpp b/include/scene_objects_manager/args_parser.hpp index 1b38ef9..11af868 100644 --- a/include/scene_objects_manager/args_parser.hpp +++ b/include/scene_objects_manager/args_parser.hpp @@ -1,5 +1,5 @@ -#ifndef ARGS_PARSER_HPP_INCLUDED -#define ARGS_PARSER_HPP_INCLUDED +#ifndef SCENE_OBJECTS_MANAGER__ARGS_PARSER_HPP_ +#define SCENE_OBJECTS_MANAGER__ARGS_PARSER_HPP_ #include #include @@ -20,4 +20,4 @@ const LaunchArguments parse_args( const std::vector& input_args); } // namespace sobjmanager -#endif // ARGS_PARSER_HPP_INCLUDED +#endif // SCENE_OBJECTS_MANAGER__ARGS_PARSER_HPP_ diff --git a/include/scene_objects_manager/scene_object.hpp b/include/scene_objects_manager/scene_object.hpp index 4d6b2c4..d25e70e 100644 --- a/include/scene_objects_manager/scene_object.hpp +++ b/include/scene_objects_manager/scene_object.hpp @@ -1,35 +1,35 @@ -#ifndef SCENE_OBJECT_HPP_INCLUDED -#define SCENE_OBJECT_HPP_INCLUDED -#include -#include - -#include -#include - -#include "scene_objects_manager/utils.hpp" -#include "yaml-cpp/yaml.h" - -namespace sobjmanager { - -using Point = geometry_msgs::msg::Point; -using Pose = geometry_msgs::msg::Pose; -using SolidPrimitive = shape_msgs::msg::SolidPrimitive; - -struct SceneObject { - std::string unique_id; - std::string pretty_name; - std::string frame_id; - uint8_t type; - Point size; - double scale; - Pose pose; - - static const inline std::map PRIMITIVE_STR_MAP = { - { "box", SolidPrimitive::BOX }, { "sphere", SolidPrimitive::SPHERE }, { "cylinder", SolidPrimitive::CYLINDER }, - { "cone", SolidPrimitive::CONE }, { "prism", SolidPrimitive::PRISM }, - }; - static const inline std::map PRIMITIVE_UINT_MAP = reverse_map(PRIMITIVE_STR_MAP); -}; - -} // namespace sobjmanager -#endif // SCENE_OBJECT_HPP_INCLUDED +#ifndef SCENE_OBJECTS_MANAGER__SCENE_OBJECT_HPP_ +#define SCENE_OBJECTS_MANAGER__SCENE_OBJECT_HPP_ +#include +#include + +#include +#include + +#include "scene_objects_manager/utils.hpp" +#include "yaml-cpp/yaml.h" + +namespace sobjmanager { + +using Point = geometry_msgs::msg::Point; +using Pose = geometry_msgs::msg::Pose; +using SolidPrimitive = shape_msgs::msg::SolidPrimitive; + +struct SceneObject { + std::string unique_id; + std::string pretty_name; + std::string frame_id; + uint8_t type; + Point size; + double scale; + Pose pose; + + static const inline std::map PRIMITIVE_STR_MAP = { + { "box", SolidPrimitive::BOX }, { "sphere", SolidPrimitive::SPHERE }, { "cylinder", SolidPrimitive::CYLINDER }, + { "cone", SolidPrimitive::CONE }, { "prism", SolidPrimitive::PRISM }, + }; + static const inline std::map PRIMITIVE_UINT_MAP = reverse_map(PRIMITIVE_STR_MAP); +}; + +} // namespace sobjmanager +#endif // SCENE_OBJECTS_MANAGER__SCENE_OBJECT_HPP_ diff --git a/include/scene_objects_manager/scene_objects_manager.hpp b/include/scene_objects_manager/scene_objects_manager.hpp index 9a1b461..0da7c0f 100644 --- a/include/scene_objects_manager/scene_objects_manager.hpp +++ b/include/scene_objects_manager/scene_objects_manager.hpp @@ -1,5 +1,5 @@ -#ifndef SCENE_OBJECTS_SPAWNER_HPP_INCLUDED -#define SCENE_OBJECTS_SPAWNER_HPP_INCLUDED +#ifndef SCENE_OBJECTS_MANAGER__SCENE_OBJECTS_MANAGER_HPP_ +#define SCENE_OBJECTS_MANAGER__SCENE_OBJECTS_MANAGER_HPP_ #include #include #include @@ -13,8 +13,8 @@ namespace sobjmanager { class SceneObjectsManager : public rclcpp::Node { public: - SceneObjectsManager() : Node("SceneObjectsManager"){}; + SceneObjectsManager() : Node("SceneObjectsManager") {}; }; } // namespace sobjmanager -#endif // SCENE_OBJECTS_SPAWNER_HPP_INCLUDED +#endif // SCENE_OBJECTS_MANAGER__SCENE_OBJECTS_MANAGER_HPP_ diff --git a/include/scene_objects_manager/spawner.hpp b/include/scene_objects_manager/spawner.hpp index 5e58066..f8b3ec6 100644 --- a/include/scene_objects_manager/spawner.hpp +++ b/include/scene_objects_manager/spawner.hpp @@ -1,28 +1,28 @@ -#ifndef OBJECT_SPAWNER_HPP_INCLUDED -#define OBJECT_SPAWNER_HPP_INCLUDED -#include - -#include - -#include "scene_objects_manager/scene_object.hpp" - -using CollisionObject = moveit_msgs::msg::CollisionObject; - -namespace sobjmanager { - -class Spawner { -public: - Spawner(std::string planning_frame_id); - - void spawn_object(const SceneObject& obj); - -private: - static CollisionObject make_collision_object(const SceneObject& raw_obj); - void spawn(const CollisionObject& object); - - std::string _planning_frame_id; - moveit::planning_interface::PlanningSceneInterface _planning_scene_interface; -}; - -} // namespace sobjmanager -#endif // OBJECT_SPAWNER_HPP_INCLUDED +#ifndef SCENE_OBJECTS_MANAGER__SPAWNER_HPP_ +#define SCENE_OBJECTS_MANAGER__SPAWNER_HPP_ +#include + +#include + +#include "scene_objects_manager/scene_object.hpp" + +using CollisionObject = moveit_msgs::msg::CollisionObject; + +namespace sobjmanager { + +class Spawner { +public: + Spawner(std::string planning_frame_id); + + void spawn_object(const SceneObject& obj); + +private: + static CollisionObject make_collision_object(const SceneObject& raw_obj); + void spawn(const CollisionObject& object); + + std::string _planning_frame_id; + moveit::planning_interface::PlanningSceneInterface _planning_scene_interface; +}; + +} // namespace sobjmanager +#endif // SCENE_OBJECTS_MANAGER__SPAWNER_HPP_ diff --git a/include/scene_objects_manager/utils.hpp b/include/scene_objects_manager/utils.hpp index 8e06b31..ecf07e5 100644 --- a/include/scene_objects_manager/utils.hpp +++ b/include/scene_objects_manager/utils.hpp @@ -1,13 +1,13 @@ -#ifndef UTILS_HPP_INCLUDED -#define UTILS_HPP_INCLUDED -#include - -template -static std::map reverse_map(const std::map& m) { - std::map r; - for (const auto& kv : m) - r[kv.second] = kv.first; - return r; -} - -#endif // UTILS_HPP_INCLUDED +#ifndef SCENE_OBJECTS_MANAGER__UTILS_HPP_ +#define SCENE_OBJECTS_MANAGER__UTILS_HPP_ +#include + +template +static std::map reverse_map(const std::map& m) { + std::map r; + for (const auto& kv : m) + r[kv.second] = kv.first; + return r; +} + +#endif // SCENE_OBJECTS_MANAGER__UTILS_HPP_ diff --git a/include/scene_objects_manager/yaml_parser.hpp b/include/scene_objects_manager/yaml_parser.hpp index 83e5e7c..5ad6014 100644 --- a/include/scene_objects_manager/yaml_parser.hpp +++ b/include/scene_objects_manager/yaml_parser.hpp @@ -1,13 +1,13 @@ -#ifndef YAML_PARSER_HPP_INCLUDED -#define YAML_PARSER_HPP_INCLUDED -#include -#include - -#include "scene_objects_manager/scene_object.hpp" - -namespace sobjmanager { - -std::vector load_scene_objects_from_yaml(std::filesystem::path path); - -} // namespace sobjmanager -#endif // YAML_PARSER_HPP_INCLUDED +#ifndef SCENE_OBJECTS_MANAGER__YAML_PARSER_HPP_ +#define SCENE_OBJECTS_MANAGER__YAML_PARSER_HPP_ +#include +#include + +#include "scene_objects_manager/scene_object.hpp" + +namespace sobjmanager { + +std::vector load_scene_objects_from_yaml(std::filesystem::path path); + +} // namespace sobjmanager +#endif // SCENE_OBJECTS_MANAGER__YAML_PARSER_HPP_ diff --git a/package.xml b/package.xml index fd4680e..8306827 100644 --- a/package.xml +++ b/package.xml @@ -15,7 +15,6 @@ std_msgs yaml-cpp - ament_lint_auto ament_lint_common