added primitive support for component style nodes
This commit is contained in:
parent
860f478294
commit
ea889664ea
5 changed files with 60 additions and 1 deletions
|
@ -8,9 +8,16 @@ ament_export_dependencies(ros_middleware_interface)
|
|||
|
||||
ament_export_include_directories(include)
|
||||
|
||||
ament_package()
|
||||
ament_package(
|
||||
CONFIG_EXTRAS rclcpp-extras.cmake
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY include/
|
||||
DESTINATION include
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY src/
|
||||
DESTINATION src/rclcpp
|
||||
)
|
||||
|
|
|
@ -112,6 +112,12 @@ private:
|
|||
} /* namespace node */
|
||||
} /* namespace rclcpp */
|
||||
|
||||
#define RCLCPP_REGISTER_NODE(Class) rclcpp::node::Node::SharedPtr \
|
||||
create_node() \
|
||||
{ \
|
||||
return rclcpp::node::Node::SharedPtr(new Class(rclcpp::contexts::default_context::DefaultContext::make_shared())); \
|
||||
}
|
||||
|
||||
#ifndef RCLCPP_RCLCPP_NODE_IMPL_HPP_
|
||||
// Template implementations
|
||||
#include "node_impl.hpp"
|
||||
|
|
|
@ -53,6 +53,10 @@ using rclcpp::subscription::SubscriptionBase;
|
|||
using rclcpp::subscription::Subscription;
|
||||
using rclcpp::rate::GenericRate;
|
||||
using rclcpp::rate::WallRate;
|
||||
using rclcpp::timer::GenericTimer;
|
||||
using rclcpp::timer::TimerBase;
|
||||
using rclcpp::timer::WallTimer;
|
||||
typedef rclcpp::context::Context::SharedPtr ContextSharedPtr;
|
||||
using rclcpp::utilities::ok;
|
||||
using rclcpp::utilities::init;
|
||||
using rclcpp::utilities::sleep_for;
|
||||
|
|
13
rclcpp/rclcpp-extras.cmake
Normal file
13
rclcpp/rclcpp-extras.cmake
Normal file
|
@ -0,0 +1,13 @@
|
|||
# copied from rclcpp/rclcpp-extras.cmake
|
||||
|
||||
set(rclcpp_node_main_SRC "${rclcpp_DIR}/../../../src/rclcpp/node_main.cpp")
|
||||
|
||||
function(rclcpp_create_node_main node_library_target)
|
||||
if(NOT TARGET ${node_library_target})
|
||||
message(FATAL_ERROR "rclcpp_create_node_main() the first argument must be a valid target name")
|
||||
endif()
|
||||
set(executable_name_ ${node_library_target}_node)
|
||||
add_executable(${executable_name_} ${rclcpp_node_main_SRC})
|
||||
target_link_libraries(${executable_name_} ${node_library_target})
|
||||
install(TARGETS ${executable_name_} DESTINATION bin)
|
||||
endfunction()
|
29
rclcpp/src/node_main.cpp
Normal file
29
rclcpp/src/node_main.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* Copyright 2014 Open Source Robotics Foundation, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
|
||||
// This forward declaration is implemented by the RCLCPP_REGISTER_NODE macro
|
||||
rclcpp::Node::SharedPtr create_node();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
rclcpp::init(argc, argv);
|
||||
rclcpp::executors::SingleThreadedExecutor executor;
|
||||
rclcpp::Node::SharedPtr node = create_node();
|
||||
executor.add_node(node);
|
||||
executor.spin();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue