Skip to content

Commit

Permalink
Image Transport rework port in progress for review (#84)
Browse files Browse the repository at this point in the history
* Remove boost where possible.

* ros::VoidPtr to std::shared_ptr<void>

* Conversions around boost where necessary.

* Ignore other packages for now.

* Basic ament_cmake port.

* Port camera_common.

* Port publisher.

* Convert subscriber.

* Port single_subscriber_publisher.

* Type updates.

VoidPtr -> std::shared_ptr<void>
sensor_msgs::Image -> sensor_msgs::msg::Image
sensor_msgs::ImageConstPtr -> sensor_msgs::msg::Image::ConstSharedPtr

* Replace queue_size and latch with qos.

* Implement simple subscriber and publisher.

* Refactor.

* Restore comments and naming.

* Fixup transport and add republisher back in.

* Add library export.

* Address reviewer feedback.

* Clean up a few warnings, remove boost headers.

* compile_definitions -> compile_options

* Reviewer feedback on necessary includes.

* Address comments about CMakeLists and package.

* Switch to RCLCPP loggers.

* ERROR -> FATAL where asserts were used.

* Add TODOs for ROS2 assert equivalents back.

* Added a TODO for getNumPublishers.
  • Loading branch information
mjcarroll authored Aug 21, 2018
1 parent f9e705a commit 2aaa970
Show file tree
Hide file tree
Showing 40 changed files with 1,461 additions and 1,090 deletions.
Empty file.
Empty file.
Empty file added image_common/COLCON_IGNORE
Empty file.
140 changes: 96 additions & 44 deletions image_transport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,69 +1,121 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5)

project(image_transport)

find_package(catkin REQUIRED
COMPONENTS
message_filters
pluginlib
rosconsole
roscpp
roslib
sensor_msgs
)
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

find_package(Boost REQUIRED)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
DEPENDS message_filters pluginlib rosconsole roscpp roslib sensor_msgs
)
find_package(ament_cmake_ros REQUIRED)

find_package(message_filters REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)

include_directories(include ${catkin_INCLUDE_DIRS})
include_directories(include)

# Build libimage_transport
# Build image_transport library
add_library(${PROJECT_NAME}
src/camera_common.cpp
src/publisher.cpp
src/subscriber.cpp
src/single_subscriber_publisher.cpp
src/camera_publisher.cpp
src/camera_subscriber.cpp
src/image_transport.cpp
src/publisher.cpp
src/single_subscriber_publisher.cpp
src/subscriber.cpp
)
add_dependencies(${PROJECT_NAME} ${catkin_EXPORTED_TARGETS})
target_link_libraries(${PROJECT_NAME}
${Boost_LIBRARIES}
${catkin_LIBRARIES}

ament_target_dependencies(${PROJECT_NAME}
"message_filters"
"pluginlib"
"rclcpp"
"sensor_msgs"
)

# Build libimage_transport_plugins
add_library(${PROJECT_NAME}_plugins src/manifest.cpp src/raw_publisher.cpp)
target_link_libraries(${PROJECT_NAME}_plugins ${PROJECT_NAME})
target_compile_definitions(${PROJECT_NAME} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")

install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_plugins
DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
COMPONENT main
)
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# Build image_transport_plugins library (raw)
add_library(${PROJECT_NAME}_plugins
src/manifest.cpp
)
target_link_libraries(${PROJECT_NAME}_plugins ${PROJECT_NAME})

# add two execs
# Build list_trasnports
add_executable(list_transports src/list_transports.cpp)
target_link_libraries(list_transports ${PROJECT_NAME})

# Build republish
add_executable(republish src/republish.cpp)
target_link_libraries(republish ${PROJECT_NAME})

add_executable(list_transports src/list_transports.cpp)
target_link_libraries(list_transports
${PROJECT_NAME}
${catkin_LIBRARIES}
# Install plugin descriptions
pluginlib_export_plugin_description_file(image_transport default_plugins.xml)

# Install libraries
install(
TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_plugins
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

install(TARGETS list_transports republish
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# Install executables
install(
TARGETS list_transports republish
RUNTIME DESTINATION lib/${PROJECT_NAME}
)

# add xml file
install(FILES default_plugins.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# Install include directories
install(
DIRECTORY include/
DESTINATION include
)

ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})

ament_export_dependencies(message_filters)
ament_export_dependencies(rclcpp)
ament_export_dependencies(sensor_msgs)
ament_export_dependencies(pluginlib)

if(BUILD_TESTING)
#TODO(ros2) enable linting
#find_package(ament_lint_auto REQUIRED)
#ament_lint_auto_find_test_dependencies()

find_package(ament_cmake_gtest)

ament_add_gtest(${PROJECT_NAME}-camera_common test/test_camera_common.cpp)
if(TARGET ${PROJECT_NAME}-camera_common)
target_link_libraries(${PROJECT_NAME}-camera_common ${PROJECT_NAME})
endif()

ament_add_gtest(${PROJECT_NAME}-publisher test/test_publisher.cpp)
if(TARGET ${PROJECT_NAME}-publisher)
target_link_libraries(${PROJECT_NAME}-publisher ${PROJECT_NAME})
endif()

ament_add_gtest(${PROJECT_NAME}-subscriber test/test_subscriber.cpp)
if(TARGET ${PROJECT_NAME}-subscriber)
target_link_libraries(${PROJECT_NAME}-subscriber ${PROJECT_NAME})
endif()

ament_add_gtest(${PROJECT_NAME}-message_passing test/test_message_passing.cpp)
if(TARGET ${PROJECT_NAME}-message_passing)
target_link_libraries(${PROJECT_NAME}-message_passing ${PROJECT_NAME})
endif()

ament_add_gtest(${PROJECT_NAME}-single_subscriber_publisher test/test_single_subscriber_publisher.cpp)
if(TARGET ${PROJECT_NAME}-single_subscriber_publisher)
target_link_libraries(${PROJECT_NAME}-single_subscriber_publisher ${PROJECT_NAME})
endif()
endif()

ament_package()
12 changes: 9 additions & 3 deletions image_transport/default_plugins.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<library path="lib/libimage_transport_plugins">
<class name="image_transport/raw_pub" type="image_transport::RawPublisher" base_class_type="image_transport::PublisherPlugin">
<library path="image_transport_plugins">
<class
name="image_transport/raw_pub"
type="image_transport::RawPublisher"
base_class_type="image_transport::PublisherPlugin">
<description>
This is the default publisher. It publishes the Image as-is on the base topic.
</description>
</class>

<class name="image_transport/raw_sub" type="image_transport::RawSubscriber" base_class_type="image_transport::SubscriberPlugin">
<class
name="image_transport/raw_sub"
type="image_transport::RawSubscriber"
base_class_type="image_transport::SubscriberPlugin">
<description>
This is the default pass-through subscriber for topics of type sensor_msgs/Image.
</description>
Expand Down
17 changes: 11 additions & 6 deletions image_transport/include/image_transport/camera_common.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*********************************************************************
* Software License Agreement (BSD License)
*
*
* Copyright (c) 2009, Willow Garage, Inc.
* 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
Expand All @@ -17,7 +17,7 @@
* * Neither the name of the Willow Garage 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
Expand All @@ -42,11 +42,16 @@ namespace image_transport {
/**
* \brief Form the camera info topic name, sibling to the base topic.
*
* \note This function assumes that the name is completely resolved. If the \c
* base_topic is remapped the resulting camera info topic will be incorrect.
* \note This function assumes that the name is completely resolved. If the \c
* base_topic is remapped the resulting camera info topic will be incorrect.
*/
std::string getCameraInfoTopic(const std::string& base_topic);

/**
* \brief Replacement for uses of boost::erase_last_copy
*/
std::string erase_last_copy(const std::string& input, const std::string& search);

} //namespace image_transport

#endif
49 changes: 23 additions & 26 deletions image_transport/include/image_transport/camera_publisher.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*********************************************************************
* Software License Agreement (BSD License)
*
*
* Copyright (c) 2009, Willow Garage, Inc.
* 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
Expand All @@ -17,7 +17,7 @@
* * Neither the name of the Willow Garage 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
Expand All @@ -35,9 +35,12 @@
#ifndef IMAGE_TRANSPORT_CAMERA_PUBLISHER_H
#define IMAGE_TRANSPORT_CAMERA_PUBLISHER_H

#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/CameraInfo.h>
#include <rclcpp/macros.hpp>
#include <rclcpp/node.hpp>

#include <sensor_msgs/msg/image.hpp>
#include <sensor_msgs/msg/camera_info.hpp>

#include "image_transport/single_subscriber_publisher.h"

namespace image_transport {
Expand All @@ -62,7 +65,14 @@ class ImageTransport;
class CameraPublisher
{
public:
CameraPublisher() {}
CameraPublisher() = default;


CameraPublisher(rclcpp::Node::SharedPtr node,
const std::string& base_topic,
rmw_qos_profile_t custom_qos = rmw_qos_profile_default);

//TODO(ros2) Restore support for SubscriberStatusCallbacks when available.

/*!
* \brief Returns the number of subscribers that are currently connected to
Expand All @@ -85,13 +95,13 @@ class CameraPublisher
/*!
* \brief Publish an (image, info) pair on the topics associated with this CameraPublisher.
*/
void publish(const sensor_msgs::Image& image, const sensor_msgs::CameraInfo& info) const;
void publish(const sensor_msgs::msg::Image& image, const sensor_msgs::msg::CameraInfo& info) const;

/*!
* \brief Publish an (image, info) pair on the topics associated with this CameraPublisher.
*/
void publish(const sensor_msgs::ImageConstPtr& image,
const sensor_msgs::CameraInfoConstPtr& info) const;
void publish(const sensor_msgs::msg::Image::ConstSharedPtr& image,
const sensor_msgs::msg::CameraInfo::ConstSharedPtr& info) const;

/*!
* \brief Publish an (image, info) pair with given timestamp on the topics associated with
Expand All @@ -100,7 +110,7 @@ class CameraPublisher
* Convenience version, which sets the timestamps of both image and info to stamp before
* publishing.
*/
void publish(sensor_msgs::Image& image, sensor_msgs::CameraInfo& info, ros::Time stamp) const;
void publish(sensor_msgs::msg::Image& image, sensor_msgs::msg::CameraInfo& info, rclcpp::Time stamp) const;

/*!
* \brief Shutdown the advertisements associated with this Publisher.
Expand All @@ -113,21 +123,8 @@ class CameraPublisher
bool operator==(const CameraPublisher& rhs) const { return impl_ == rhs.impl_; }

private:
CameraPublisher(ImageTransport& image_it, ros::NodeHandle& info_nh,
const std::string& base_topic, uint32_t queue_size,
const SubscriberStatusCallback& image_connect_cb,
const SubscriberStatusCallback& image_disconnect_cb,
const ros::SubscriberStatusCallback& info_connect_cb,
const ros::SubscriberStatusCallback& info_disconnect_cb,
const ros::VoidPtr& tracked_object, bool latch);

struct Impl;
typedef boost::shared_ptr<Impl> ImplPtr;
typedef boost::weak_ptr<Impl> ImplWPtr;

ImplPtr impl_;

friend class ImageTransport;
std::shared_ptr<Impl> impl_;
};

} //namespace image_transport
Expand Down
Loading

0 comments on commit 2aaa970

Please sign in to comment.