Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Testing of migration to ROS2 Humble #737

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added costmap_cspace/COLCON_IGNORE
Empty file.
Empty file.
Empty file added map_organizer/COLCON_IGNORE
Empty file.
Empty file added neonavigation/COLCON_IGNORE
Empty file.
42 changes: 14 additions & 28 deletions neonavigation_common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
cmake_minimum_required(VERSION 3.1.3)
cmake_minimum_required(VERSION 3.5)
project(neonavigation_common)
find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

set(CATKIN_DEPENDS
roscpp
)

find_package(catkin REQUIRED COMPONENTS ${CATKIN_DEPENDS})
catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS ${CATKIN_DEPENDS}
)


set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(include ${catkin_INCLUDE_DIRS})
include_directories(include)
ament_auto_add_library(neonavigation_common SHARED
src/neonavigation_node.cpp)


if(CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
add_subdirectory(test)

find_package(roslint REQUIRED)
roslint_cpp()
roslint_add_test()
if(BUILD_TESTING)
set(ament_cmake_copyright_FOUND TRUE)
set(ament_cmake_uncrustify_FOUND TRUE)
set(ament_cmake_cpplint_FOUND TRUE)
ament_auto_find_test_dependencies()
ament_lint_auto_find_test_dependencies()
endif()


install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)
ament_auto_package()
48 changes: 24 additions & 24 deletions neonavigation_common/include/neonavigation_common/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#ifndef NEONAVIGATION_COMMON_COMPATIBILITY_H
#define NEONAVIGATION_COMMON_COMPATIBILITY_H

#include <ros/ros.h>
#include "rclcpp/rclcpp.hpp"

#include <string>

Expand All @@ -57,7 +57,7 @@ STATIC_ASSERT(supported_level <= default_level && default_level <= current_level
int getCompat()
{
int compat(default_level);
ros::NodeHandle("/").param("neonavigation_compatible", compat, compat);
rclcpp::Node("/").param("neonavigation_compatible", compat, compat);

return compat;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ void checkCompatMode()
ros::this_node::getName().c_str(), current_level);
}
}
std::string getSimplifiedNamespace(ros::NodeHandle& nh)
std::string getSimplifiedNamespace(rclcpp::Node& nh)
{
if (nh.getUnresolvedNamespace() == ros::this_node::getName())
return std::string("~/");
Expand All @@ -100,17 +100,17 @@ std::string getSimplifiedNamespace(ros::NodeHandle& nh)
}
template <class M>
ros::Subscriber subscribe(
ros::NodeHandle& nh_new,
rclcpp::Node& nh_new,
const std::string& topic_new,
ros::NodeHandle& nh_old,
rclcpp::Node& nh_old,
const std::string& topic_old,
uint32_t queue_size,
void (*fp)(M),
const ros::TransportHints& transport_hints = ros::TransportHints())
{
if (getCompat() != current_level)
{
ROS_ERROR(
RCLCPP_ERROR(rclcpp::get_logger("NeonavigationCommon"),
"Use %s (%s%s) topic instead of %s (%s%s)",
nh_new.resolveName(topic_new, false).c_str(),
getSimplifiedNamespace(nh_new).c_str(), topic_new.c_str(),
Expand All @@ -125,9 +125,9 @@ ros::Subscriber subscribe(
}
template <class M, class T>
ros::Subscriber subscribe(
ros::NodeHandle& nh_new,
rclcpp::Node& nh_new,
const std::string& topic_new,
ros::NodeHandle& nh_old,
rclcpp::Node& nh_old,
const std::string& topic_old,
uint32_t queue_size,
void (T::*fp)(M) const,
Expand All @@ -136,7 +136,7 @@ ros::Subscriber subscribe(
{
if (getCompat() != current_level)
{
ROS_ERROR(
RCLCPP_ERROR(rclcpp::get_logger("NeonavigationCommon"),
"Use %s (%s%s) topic instead of %s (%s%s)",
nh_new.resolveName(topic_new, false).c_str(),
getSimplifiedNamespace(nh_new).c_str(), topic_new.c_str(),
Expand All @@ -151,9 +151,9 @@ ros::Subscriber subscribe(
}
template <class M, class T>
ros::Subscriber subscribe(
ros::NodeHandle& nh_new,
rclcpp::Node& nh_new,
const std::string& topic_new,
ros::NodeHandle& nh_old,
rclcpp::Node& nh_old,
const std::string& topic_old,
uint32_t queue_size,
void (T::*fp)(M),
Expand All @@ -162,7 +162,7 @@ ros::Subscriber subscribe(
{
if (getCompat() != current_level)
{
ROS_ERROR(
RCLCPP_ERROR(rclcpp::get_logger("NeonavigationCommon"),
"Use %s (%s%s) topic instead of %s (%s%s)",
nh_new.resolveName(topic_new, false).c_str(),
getSimplifiedNamespace(nh_new).c_str(), topic_new.c_str(),
Expand All @@ -177,18 +177,18 @@ ros::Subscriber subscribe(
}
template <class M>
ros::Subscriber subscribe(
ros::NodeHandle& nh_new,
rclcpp::Node& nh_new,
const std::string& topic_new,
ros::NodeHandle& nh_old,
rclcpp::Node& nh_old,
const std::string& topic_old,
uint32_t queue_size,
const boost::function<void(const boost::shared_ptr<M const>&)>& callback,
const std::function<void(const std::shared_ptr<M const>&)>& callback,
const ros::VoidConstPtr& tracked_object = ros::VoidConstPtr(),
const ros::TransportHints& transport_hints = ros::TransportHints())
{
if (getCompat() != current_level)
{
ROS_ERROR(
RCLCPP_ERROR(rclcpp::get_logger("NeonavigationCommon"),
"Use %s (%s%s) topic instead of %s (%s%s)",
nh_new.resolveName(topic_new, false).c_str(),
getSimplifiedNamespace(nh_new).c_str(), topic_new.c_str(),
Expand All @@ -203,16 +203,16 @@ ros::Subscriber subscribe(
}
template <class M>
ros::Publisher advertise(
ros::NodeHandle& nh_new,
rclcpp::Node& nh_new,
const std::string& topic_new,
ros::NodeHandle& nh_old,
rclcpp::Node& nh_old,
const std::string& topic_old,
uint32_t queue_size,
bool latch = false)
{
if (getCompat() != current_level)
{
ROS_ERROR(
RCLCPP_ERROR(rclcpp::get_logger("NeonavigationCommon"),
"Use %s (%s%s) topic instead of %s (%s%s)",
nh_new.resolveName(topic_new, false).c_str(),
getSimplifiedNamespace(nh_new).c_str(), topic_new.c_str(),
Expand All @@ -227,16 +227,16 @@ ros::Publisher advertise(
}
template <class T, class MReq, class MRes>
ros::ServiceServer advertiseService(
ros::NodeHandle& nh_new,
rclcpp::Node& nh_new,
const std::string& service_new,
ros::NodeHandle& nh_old,
rclcpp::Node& nh_old,
const std::string& service_old,
bool (T::*srv_func)(MReq&, MRes&),
T* obj)
{
if (getCompat() != current_level)
{
ROS_ERROR(
RCLCPP_ERROR(rclcpp::get_logger("NeonavigationCommon"),
"Use %s (%s%s) service instead of %s (%s%s)",
nh_new.resolveName(service_new, false).c_str(),
getSimplifiedNamespace(nh_new).c_str(), service_new.c_str(),
Expand All @@ -252,14 +252,14 @@ ros::ServiceServer advertiseService(

template <typename T>
void deprecatedParam(
const ros::NodeHandle& nh,
const rclcpp::Node& nh,
const std::string& key,
T& param,
const T& default_value)
{
if (nh.hasParam(key))
{
ROS_ERROR(
RCLCPP_ERROR(rclcpp::get_logger("NeonavigationCommon"),
"Use of the parameter %s is deprecated. Don't use this.",
nh.resolveName(key, false).c_str());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2024, the neonavigation authors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef NEONAVIGATION_COMMON__NEONAVIGATION_NODE_HPP_
#define NEONAVIGATION_COMMON__NEONAVIGATION_NODE_HPP_

#include <string>
#include <variant>
#include <vector>
#include <unordered_map>

#include <rclcpp/rclcpp.hpp>
#include <rcl_interfaces/msg/set_parameters_result.hpp>

#include <neonavigation_common_msgs/srv/get_logger_levels.hpp>
#include <neonavigation_common_msgs/srv/set_logger_levels.hpp>

namespace neonavigation_common
{
class NeonavigationNode : public rclcpp::Node
{
public:
explicit NeonavigationNode(const std::string& node_name, const rclcpp::NodeOptions& options);

// Disable copy and move. declare_dynamic_parameter() will not work correctly if copied.
NeonavigationNode& operator=(const NeonavigationNode&) = delete;
NeonavigationNode(const NeonavigationNode&) = delete;

protected:
OnSetParametersCallbackHandle::SharedPtr parameter_handler_;
bool parameter_handler_disabled_;
using ParamType = std::variant<int64_t*, double*, bool*, std::string*>;
std::unordered_map<std::string, ParamType> params_;
rclcpp::Service<neonavigation_common_msgs::srv::GetLoggerLevels>::SharedPtr get_loggers_service_;
rclcpp::Service<neonavigation_common_msgs::srv::SetLoggerLevels>::SharedPtr set_loggers_service_;

template <typename T>
void declare_dynamic_parameter(const std::string& name, T* const param, const T& default_value)
Comment on lines +63 to +64
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare_dynamic_parameter() function is added to replace dynamic_reconfigure.

{
// Disable cbParameter while declaring parameters
parameter_handler_disabled_ = true;
*param = declare_parameter(name, default_value);
params_[name] = param;
parameter_handler_disabled_ = false;
}

void create_logger_services();
rcl_interfaces::msg::SetParametersResult cbParameter(const std::vector<rclcpp::Parameter>& parameters);

// This function is called after a parameter is updated.
virtual void onDynamicParameterUpdated(const std::vector<rclcpp::Parameter>&)
{
}
};

} // namespace neonavigation_common

#endif // NEONAVIGATION_COMMON__NEONAVIGATION_NODE_HPP_
21 changes: 14 additions & 7 deletions neonavigation_common/package.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0"?>
<package format="2">
<?xml-model
href="http://download.ros.org/schema/package_format3.xsd"
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>neonavigation_common</name>
<version>0.17.1</version>
<description>Common headers for neonavigation meta-package</description>
Expand All @@ -8,11 +11,15 @@
<license>BSD</license>
<author email="[email protected]">Atsushi Watanabe</author>

<buildtool_depend>catkin</buildtool_depend>
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_auto</buildtool_depend>
<depend>rclcpp</depend>
<depend>neonavigation_common_msgs</depend>

<depend>roscpp</depend>
<test_depend>roslint</test_depend>
<test_depend>rostest</test_depend>
<test_depend>std_srvs</test_depend>
<test_depend>std_msgs</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading
Loading