diff --git a/CMakeLists.txt b/CMakeLists.txt index 2430f25..55d7575 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,12 @@ endif() project(mc_panda_lirmm LANGUAGES CXX VERSION 1.0) enable_testing() -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) find_package(mc_panda REQUIRED) add_subdirectory(modules) +add_subdirectory(cmake) if(BUILD_TESTING) add_subdirectory(tests) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt new file mode 100644 index 0000000..b3e190f --- /dev/null +++ b/cmake/CMakeLists.txt @@ -0,0 +1,11 @@ +include(CMakePackageConfigHelpers) +set(VERSION_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") +set(PROJECT_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake") +set(CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}") +write_basic_package_version_file( + ${VERSION_CONFIG} + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) +configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in" "${PROJECT_CONFIG}" INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}") +install(FILES "${PROJECT_CONFIG}" "${VERSION_CONFIG}" DESTINATION "${CONFIG_INSTALL_DIR}") diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 0000000..82a665b --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,8 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) +find_package(mc_panda REQUIRED) + +include("${CMAKE_CURRENT_LIST_DIR}/mc_panda_lirmmTargets.cmake") + +check_required_components(mc_panda_lirmm) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index cc6c449..81fbe75 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,7 +1,38 @@ -configure_file(config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/config.h") -add_robot(PandaLIRMM module.cpp module.h) -target_link_libraries(PandaLIRMM PUBLIC mc_panda::panda) -target_include_directories(PandaLIRMM PRIVATE $) +# Panda robot module library +set(panda_lirmm_HDR + include/mc_panda_lirmm/panda_lirmm.h + "${CMAKE_CURRENT_SOURCE_DIR}/include/mc_panda_lirmm/panda_lirmm.h" +) + +set(panda_lirmm_SRC + src/panda_lirmm.cpp +) +configure_file(include/mc_panda_lirmm/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/mc_panda_lirmm/config.h") + +add_library(mc_panda_lirmm SHARED ${panda_lirmm_SRC} ${panda_lirmm_HDR}) +add_library(mc_panda_lirmm::panda_lirmm ALIAS mc_panda_lirmm) +set_target_properties(mc_panda_lirmm PROPERTIES EXPORT_NAME panda_lirmm) +set_target_properties(mc_panda_lirmm PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION}) +target_link_libraries(mc_panda_lirmm PUBLIC mc_panda::panda) +target_include_directories(mc_panda_lirmm PUBLIC $ $) +target_include_directories(mc_panda_lirmm PUBLIC $ $) +target_compile_definitions(mc_panda_lirmm PRIVATE -DMC_PANDA_EXPORTS) +install(FILES ${panda_lirmm_HDR} DESTINATION include/mc_panda_lirmm) + +install(TARGETS mc_panda_lirmm + EXPORT mc_panda_lirmmTargets + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) + +install(EXPORT mc_panda_lirmmTargets + FILE mc_panda_lirmmTargets.cmake + NAMESPACE mc_panda_lirmm:: + DESTINATION lib/cmake/mc_panda_lirmm) + +add_robot(PandaLIRMM src/module.cpp) +target_link_libraries(PandaLIRMM PUBLIC mc_panda_lirmm::panda_lirmm) +target_compile_definitions(PandaLIRMM PRIVATE -DPANDA_DESCRIPTION_PATH="${PANDA_DESCRIPTION_PATH}") install(DIRECTORY rsdf/panda2_lirmm DESTINATION "${PANDA_DESCRIPTION_PATH}/rsdf" diff --git a/modules/config.h.in b/modules/include/mc_panda_lirmm/config.h.in similarity index 100% rename from modules/config.h.in rename to modules/include/mc_panda_lirmm/config.h.in diff --git a/modules/module.h b/modules/include/mc_panda_lirmm/panda_lirmm.h similarity index 79% rename from modules/module.h rename to modules/include/mc_panda_lirmm/panda_lirmm.h index cbd61bc..8e1f9ba 100644 --- a/modules/module.h +++ b/modules/include/mc_panda_lirmm/panda_lirmm.h @@ -44,20 +44,20 @@ static std::string pandaVariantUppercase(bool pump, bool foot, bool hand) return v; } -enum class Robots +enum class PandaLIRMMRobots { Panda2LIRMM, Panda6LIRMM, Panda7LIRMM }; -static std::string to_string(Robots robots) +static std::string to_string(PandaLIRMMRobots robots) { - if(robots == Robots::Panda2LIRMM) + if(robots == PandaLIRMMRobots::Panda2LIRMM) { return "Panda2LIRMM"; } - else if(robots == Robots::Panda6LIRMM) + else if(robots == PandaLIRMMRobots::Panda6LIRMM) { return "Panda6LIRMM"; } @@ -67,7 +67,7 @@ static std::string to_string(Robots robots) } } -inline static std::string NameFromParams(Robots robot, bool pump, bool foot, bool hand, bool fixSensorFrame) +inline static std::string NameFromParams(PandaLIRMMRobots robot, bool pump, bool foot, bool hand, bool fixSensorFrame) { auto name = to_string(robot) + pandaVariantUppercase(pump, foot, hand); if(!fixSensorFrame) @@ -84,7 +84,7 @@ static void ForAllVariants(Callback cb) {false, false, false}, {true, false, false}, {false, true, false}, {false, false, true}}; auto fixSensorFrameOptions = {true, false}; - for(auto robot : {Robots::Panda2LIRMM, Robots::Panda6LIRMM, Robots::Panda7LIRMM}) + for(auto robot : {PandaLIRMMRobots::Panda2LIRMM, PandaLIRMMRobots::Panda6LIRMM, PandaLIRMMRobots::Panda7LIRMM}) { for(auto endEffector : endEffectorOptions) { @@ -99,7 +99,7 @@ static void ForAllVariants(Callback cb) struct ROBOT_MODULE_API PandaLIRMM : public mc_robots::PandaRobotModule { public: - PandaLIRMM(Robots robot, bool pump, bool foot, bool hand, bool fixSensorFrame = true); + PandaLIRMM(PandaLIRMMRobots robot, bool pump, bool foot, bool hand, bool fixSensorFrame = true); protected: void create_urdf(); @@ -110,10 +110,4 @@ struct ROBOT_MODULE_API PandaLIRMM : public mc_robots::PandaRobotModule double box_mass); }; -struct ROBOT_MODULE_API Panda2LIRMM : public mc_robots::PandaLIRMM -{ -public: - Panda2LIRMM(bool pump, bool foot, bool hand, bool fixSensorFrame = true); -}; - } // namespace mc_robots diff --git a/modules/src/module.cpp b/modules/src/module.cpp new file mode 100644 index 0000000..65d7fe3 --- /dev/null +++ b/modules/src/module.cpp @@ -0,0 +1,42 @@ +#include + +extern "C" +{ + ROBOT_MODULE_API void MC_RTC_ROBOT_MODULE(std::vector & names) + { + using namespace mc_robots; + ForAllVariants([&names](PandaLIRMMRobots robot, bool pump, bool foot, bool hand, bool fixSensorFrame) + { names.push_back(NameFromParams(robot, pump, foot, hand, fixSensorFrame)); }); + } + ROBOT_MODULE_API void destroy(mc_rbdyn::RobotModule * ptr) + { + delete ptr; + } + ROBOT_MODULE_API mc_rbdyn::RobotModule * create(const std::string & n) + { + ROBOT_MODULE_CHECK_VERSION("PandaLIRMM") + + static auto variant_factory = []() + { + std::map> variant_factory; + using namespace mc_robots; + ForAllVariants( + [&variant_factory](PandaLIRMMRobots robot, bool pump, bool foot, bool hand, bool fixSensorFrame) + { + variant_factory[NameFromParams(robot, pump, foot, hand, fixSensorFrame)] = [=]() + { return new PandaLIRMM(robot, pump, foot, hand, fixSensorFrame); }; + }); + return variant_factory; + }(); + auto it = variant_factory.find(n); + if(it != variant_factory.end()) + { + return it->second(); + } + else + { + mc_rtc::log::error("PandaLIRMM module Cannot create an object of type {}", n); + return nullptr; + } + } +} diff --git a/modules/module.cpp b/modules/src/panda_lirmm.cpp similarity index 78% rename from modules/module.cpp rename to modules/src/panda_lirmm.cpp index 6358db8..db06ec2 100644 --- a/modules/module.cpp +++ b/modules/src/panda_lirmm.cpp @@ -1,7 +1,7 @@ -#include "module.h" #include -#include "config.h" #include +#include +#include #include #include @@ -52,12 +52,12 @@ Eigen::Vector3d computeBoxCenterOfMass(const Eigen::Vector3d & size, double mass return com_vector; } -PandaLIRMM::PandaLIRMM(Robots robot, bool pump, bool foot, bool hand, bool fixSensorFrame) +PandaLIRMM::PandaLIRMM(PandaLIRMMRobots robot, bool pump, bool foot, bool hand, bool fixSensorFrame) : mc_robots::PandaRobotModule(pump, foot, hand) { this->name += "_" + pandaVariant(pump, foot, hand); - if(robot == Robots::Panda2LIRMM) + if(robot == PandaLIRMMRobots::Panda2LIRMM) { this->name = "panda2_lirmm_" + pandaVariant(pump, foot, hand); auto size = Eigen::Vector3d{0.75, 1.0, 0.75}; @@ -67,7 +67,7 @@ PandaLIRMM::PandaLIRMM(Robots robot, bool pump, bool foot, bool hand, bool fixSe _default_attitude = {1, 0, 0, 0, 0, 0, size.z()}; create_urdf(); } - else if(robot == Robots::Panda6LIRMM) + else if(robot == PandaLIRMMRobots::Panda6LIRMM) { this->name = "panda6_lirmm_" + pandaVariant(pump, foot, hand); double mass = 40; @@ -78,7 +78,7 @@ PandaLIRMM::PandaLIRMM(Robots robot, bool pump, bool foot, bool hand, bool fixSe _default_attitude = {1, 0, 0, 0, 0, 0, size.z()}; create_urdf(); } - else if(robot == Robots::Panda7LIRMM) + else if(robot == PandaLIRMMRobots::Panda7LIRMM) { this->name = "panda7_lirmm_" + pandaVariant(pump, foot, hand); double mass = 10; @@ -163,44 +163,3 @@ void PandaLIRMM::create_urdf() } } // namespace mc_robots - -extern "C" -{ - ROBOT_MODULE_API void MC_RTC_ROBOT_MODULE(std::vector & names) - { - using namespace mc_robots; - ForAllVariants([&names](Robots robot, bool pump, bool foot, bool hand, bool fixSensorFrame) - { names.push_back(NameFromParams(robot, pump, foot, hand, fixSensorFrame)); }); - } - ROBOT_MODULE_API void destroy(mc_rbdyn::RobotModule * ptr) - { - delete ptr; - } - ROBOT_MODULE_API mc_rbdyn::RobotModule * create(const std::string & n) - { - ROBOT_MODULE_CHECK_VERSION("PandaLIRMM") - - static auto variant_factory = []() - { - std::map> variant_factory; - using namespace mc_robots; - ForAllVariants( - [&variant_factory](Robots robot, bool pump, bool foot, bool hand, bool fixSensorFrame) - { - variant_factory[NameFromParams(robot, pump, foot, hand, fixSensorFrame)] = [=]() - { return new PandaLIRMM(robot, pump, foot, hand, fixSensorFrame); }; - }); - return variant_factory; - }(); - auto it = variant_factory.find(n); - if(it != variant_factory.end()) - { - return it->second(); - } - else - { - mc_rtc::log::error("PandaLIRMM module Cannot create an object of type {}", n); - return nullptr; - } - } -}