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

Refactor intra-process demo into components. #402

Draft
wants to merge 1 commit into
base: rolling
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
33 changes: 29 additions & 4 deletions intra_process_demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ endif()

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(rmw REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
Expand All @@ -27,13 +28,27 @@ ament_export_include_directories(include)
##

# Simple example of using unique_ptr to minimize copies.

add_library(two_node_pipeline_components SHARED
src/two_node_pipeline/producer_component.cpp
src/two_node_pipeline/consumer_component.cpp
)
target_compile_definitions(two_node_pipeline_components
PRIVATE "INTRA_PROCESS_DEMO_BUILDING_DLL")
ament_target_dependencies(two_node_pipeline_components
"rclcpp" "rclcpp_components" "rcutils" "std_msgs")

rclcpp_components_register_nodes(two_node_pipeline_components
"intra_process_demo::two_node_pipeline::Producer"
"intra_process_demo::two_node_pipeline::Consumer")

add_executable(two_node_pipeline
src/two_node_pipeline/two_node_pipeline.cpp)
ament_target_dependencies(two_node_pipeline
"rclcpp"
"std_msgs")
target_link_libraries(two_node_pipeline
two_node_pipeline_components)

# Simple example of a cyclic pipeline which uses no allocation while iterating.

# Simple example of a cyclic pipeline which uses no allocation while iterating.
add_executable(cyclic_pipeline
src/cyclic_pipeline/cyclic_pipeline.cpp)
ament_target_dependencies(cyclic_pipeline
Expand Down Expand Up @@ -80,6 +95,11 @@ ament_target_dependencies(image_view_node
"sensor_msgs"
"OpenCV")

install(TARGETS
two_node_pipeline_components
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)

install(TARGETS
two_node_pipeline
cyclic_pipeline
Expand All @@ -95,6 +115,11 @@ install(
DESTINATION include
)

install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef IMAGE_PIPELINE__CAMERA_NODE_HPP_
#define IMAGE_PIPELINE__CAMERA_NODE_HPP_
#ifndef INTRA_PROCESS_DEMO__IMAGE_PIPELINE__CAMERA_NODE_HPP_
#define INTRA_PROCESS_DEMO__IMAGE_PIPELINE__CAMERA_NODE_HPP_

#include <chrono>
#include <sstream>
Expand Down Expand Up @@ -110,4 +110,4 @@ class CameraNode : public rclcpp::Node
cv::Mat frame_;
};

#endif // IMAGE_PIPELINE__CAMERA_NODE_HPP_
#endif // INTRA_PROCESS_DEMO__IMAGE_PIPELINE__CAMERA_NODE_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef IMAGE_PIPELINE__COMMON_HPP_
#define IMAGE_PIPELINE__COMMON_HPP_
#ifndef INTRA_PROCESS_DEMO__IMAGE_PIPELINE__COMMON_HPP_
#define INTRA_PROCESS_DEMO__IMAGE_PIPELINE__COMMON_HPP_

#ifdef _WIN32
#include <process.h>
Expand Down Expand Up @@ -85,4 +85,4 @@ draw_on_image(cv::Mat & image, const std::string & text, int height)
cv::Scalar(0, 255, 0));
}

#endif // IMAGE_PIPELINE__COMMON_HPP_
#endif // INTRA_PROCESS_DEMO__IMAGE_PIPELINE__COMMON_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef IMAGE_PIPELINE__IMAGE_VIEW_NODE_HPP_
#define IMAGE_PIPELINE__IMAGE_VIEW_NODE_HPP_
#ifndef INTRA_PROCESS_DEMO__IMAGE_PIPELINE__IMAGE_VIEW_NODE_HPP_
#define INTRA_PROCESS_DEMO__IMAGE_PIPELINE__IMAGE_VIEW_NODE_HPP_

#include <sstream>
#include <string>
Expand Down Expand Up @@ -78,4 +78,4 @@ class ImageViewNode : public rclcpp::Node
cv::Mat frame_;
};

#endif // IMAGE_PIPELINE__IMAGE_VIEW_NODE_HPP_
#endif // INTRA_PROCESS_DEMO__IMAGE_PIPELINE__IMAGE_VIEW_NODE_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef IMAGE_PIPELINE__WATERMARK_NODE_HPP_
#define IMAGE_PIPELINE__WATERMARK_NODE_HPP_
#ifndef INTRA_PROCESS_DEMO__IMAGE_PIPELINE__WATERMARK_NODE_HPP_
#define INTRA_PROCESS_DEMO__IMAGE_PIPELINE__WATERMARK_NODE_HPP_

#include <memory>
#include <sstream>
Expand Down Expand Up @@ -69,4 +69,4 @@ class WatermarkNode : public rclcpp::Node
cv::Mat frame_;
};

#endif // IMAGE_PIPELINE__WATERMARK_NODE_HPP_
#endif // INTRA_PROCESS_DEMO__IMAGE_PIPELINE__WATERMARK_NODE_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2019 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.

#ifndef INTRA_PROCESS_DEMO__TWO_NODE_PIPELINE__CONSUMER_COMPONENT_HPP_
#define INTRA_PROCESS_DEMO__TWO_NODE_PIPELINE__CONSUMER_COMPONENT_HPP_

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int32.hpp"

#include "intra_process_demo/visibility_control.h"

namespace intra_process_demo
{
namespace two_node_pipeline
{

class Consumer : public rclcpp::Node
{
public:
INTRA_PROCESS_DEMO_PUBLIC
explicit Consumer(const rclcpp::NodeOptions & options);

explicit Consumer(
const std::string & name,
const std::string & input,
const rclcpp::NodeOptions & options);

private:
rclcpp::Subscription<std_msgs::msg::Int32>::SharedPtr sub_;
};

} // namespace two_node_pipeline
} // namespace intra_process_demo

#endif // INTRA_PROCESS_DEMO__TWO_NODE_PIPELINE__CONSUMER_COMPONENT_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2016 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.

#ifndef INTRA_PROCESS_DEMO__TWO_NODE_PIPELINE__PRODUCER_COMPONENT_HPP_
#define INTRA_PROCESS_DEMO__TWO_NODE_PIPELINE__PRODUCER_COMPONENT_HPP_

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int32.hpp"

#include "intra_process_demo/visibility_control.h"

namespace intra_process_demo
{
namespace two_node_pipeline
{

class Producer : public rclcpp::Node
{
public:
INTRA_PROCESS_DEMO_PUBLIC
explicit Producer(const rclcpp::NodeOptions & options);

explicit Producer(
const std::string & name,
const std::string & output,
const rclcpp::NodeOptions & options);

private:
rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr pub_;
rclcpp::TimerBase::SharedPtr timer_;
};

} // namespace two_node_pipeline
} // namespace intra_process_demo

#endif // INTRA_PROCESS_DEMO__TWO_NODE_PIPELINE__PRODUCER_COMPONENT_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef INTRA_PROCESS_DEMO__VISIBILITY_CONTROL_H_
#define INTRA_PROCESS_DEMO__VISIBILITY_CONTROL_H_

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define INTRA_PROCESS_DEMO_EXPORT __attribute__ ((dllexport))
#define INTRA_PROCESS_DEMO_IMPORT __attribute__ ((dllimport))
#else
#define INTRA_PROCESS_DEMO_EXPORT __declspec(dllexport)
#define INTRA_PROCESS_DEMO_IMPORT __declspec(dllimport)
#endif
#ifdef INTRA_PROCESS_DEMO_BUILDING_LIBRARY
#define INTRA_PROCESS_DEMO_PUBLIC INTRA_PROCESS_DEMO_EXPORT
#else
#define INTRA_PROCESS_DEMO_PUBLIC INTRA_PROCESS_DEMO_IMPORT
#endif
#define INTRA_PROCESS_DEMO_PUBLIC_TYPE INTRA_PROCESS_DEMO_PUBLIC
#define INTRA_PROCESS_DEMO_LOCAL
#else
#define INTRA_PROCESS_DEMO_EXPORT __attribute__ ((visibility("default")))
#define INTRA_PROCESS_DEMO_IMPORT
#if __GNUC__ >= 4
#define INTRA_PROCESS_DEMO_PUBLIC __attribute__ ((visibility("default")))
#define INTRA_PROCESS_DEMO_LOCAL __attribute__ ((visibility("hidden")))
#else
#define INTRA_PROCESS_DEMO_PUBLIC
#define INTRA_PROCESS_DEMO_LOCAL
#endif
#define INTRA_PROCESS_DEMO_PUBLIC_TYPE
#endif

#endif // INTRA_PROCESS_DEMO__VISIBILITY_CONTROL_H_
45 changes: 45 additions & 0 deletions intra_process_demo/launch/two_node_pipeline_launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2019 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.

"""Launch a producer and a consumer in a component container, enabling intraprocess comms."""

from launch import LaunchDescription
from launch_ros.actions import ComposableNodeContainer
from launch_ros.descriptions import ComposableNode


def generate_launch_description():
return LaunchDescription([
ComposableNodeContainer(
node_namespace='/my_ns',
node_name='my_container',
package='rclcpp_components',
node_executable='component_container',
composable_node_descriptions=[
ComposableNode(
package='intra_process_demo',
node_namespace='/my_ns', node_name='my_producer',
node_plugin='intra_process_demo::two_node_pipeline::Producer',
extra_arguments=[{'use_intra_process_comms': True}],
),
ComposableNode(
package='intra_process_demo',
node_namespace='/my_ns', node_name='my_consumer',
node_plugin='intra_process_demo::two_node_pipeline::Consumer',
extra_arguments=[{'use_intra_process_comms': True}],
)
],
output='screen',
)
])
5 changes: 4 additions & 1 deletion intra_process_demo/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@

<build_depend>libopencv-dev</build_depend>
<build_depend>rclcpp</build_depend>
<build_depend>rclcpp_components</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>std_msgs</build_depend>

<exec_depend>launch</exec_depend>
<exec_depend>launch_ros</exec_depend>
<exec_depend>libopencv-dev</exec_depend>
<exec_depend>rclcpp</exec_depend>
<exec_depend>rclcpp_components</exec_depend>
<exec_depend>sensor_msgs</exec_depend>

<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>launch</test_depend>
<test_depend>launch_testing</test_depend>
<test_depend>launch_testing_ament_cmake</test_depend>
<test_depend>rmw_implementation_cmake</test_depend>
Expand Down
2 changes: 1 addition & 1 deletion intra_process_demo/src/image_pipeline/camera_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "image_pipeline/camera_node.hpp"
#include "intra_process_demo/image_pipeline/camera_node.hpp"

#include <rclcpp/rclcpp.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

#include <memory>

#include "image_pipeline/camera_node.hpp"
#include "image_pipeline/image_view_node.hpp"
#include "image_pipeline/watermark_node.hpp"
#include "intra_process_demo/image_pipeline/camera_node.hpp"
#include "intra_process_demo/image_pipeline/image_view_node.hpp"
#include "intra_process_demo/image_pipeline/watermark_node.hpp"

int main(int argc, char * argv[])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

#include <memory>

#include "image_pipeline/camera_node.hpp"
#include "image_pipeline/image_view_node.hpp"
#include "image_pipeline/watermark_node.hpp"
#include "intra_process_demo/image_pipeline/camera_node.hpp"
#include "intra_process_demo/image_pipeline/image_view_node.hpp"
#include "intra_process_demo/image_pipeline/watermark_node.hpp"

int main(int argc, char * argv[])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "image_pipeline/image_view_node.hpp"
#include "intra_process_demo/image_pipeline/image_view_node.hpp"

#include <rclcpp/rclcpp.hpp>

Expand Down
2 changes: 1 addition & 1 deletion intra_process_demo/src/image_pipeline/watermark_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "image_pipeline/watermark_node.hpp"
#include "intra_process_demo/image_pipeline/watermark_node.hpp"

#include <rclcpp/rclcpp.hpp>

Expand Down
Loading