Added camera component

This commit is contained in:
Roman Andrianov 2023-03-14 05:42:00 +00:00 committed by Igor Brylyov
parent 1177140a0c
commit 209e99a4b3
9 changed files with 168 additions and 8 deletions

View file

@ -0,0 +1,68 @@
cmake_minimum_required(VERSION 3.5)
project(camera_component)
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED True)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_ros REQUIRED)
find_package(image_transport REQUIRED)
find_package(ros_gz_bridge REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(env_manager REQUIRED)
find_package(ignition-transport11 REQUIRED)
set(GZ_TRANSPORT_VER ${ignition-transport11_VERSION_MAJOR})
find_package(ignition-msgs8 REQUIRED)
set(GZ_MSGS_VER ${ignition-msgs8_VERSION_MAJOR})
set(GZ_TARGET_PREFIX ignition)
add_library(ign_camera_component SHARED
src/ign_camera_component.cpp)
target_compile_definitions(ign_camera_component
PRIVATE "COMPOSITION_BUILDING_DLL")
target_link_libraries(ign_camera_component
${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}::core
${GZ_TARGET_PREFIX}-transport${GZ_TRANSPORT_VER}::core
)
ament_target_dependencies(ign_camera_component
"image_transport"
"ros_gz_bridge"
"rclcpp"
"rclcpp_components"
"sensor_msgs"
"env_manager")
rclcpp_components_register_nodes(ign_camera_component "camera_component::IgnCameraComponent")
set(node_plugins "${node_plugins}camera_component::IgnCameraComponent;$<TARGET_FILE:camera_component>\n")
install(TARGETS ign_camera_component
DESTINATION lib)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()

View file

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>camera_component</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="rom.andrianov1984@gmail.com">splinter1984</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>pkg-config</buildtool_depend>
<depend>image_transport</depend>
<depend>ros_gz_bridge</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>sensor_msgs</depend>
<depend>env_manager</depend>
<depend condition="$GZ_VERSION == fortress or $IGNITION_VERSION == fortress">ignition-msgs8</depend>
<depend condition="$GZ_VERSION == fortress or $IGNITION_VERSION == fortress">ignition-transport11</depend>
<depend condition="$GZ_VERSION == '' and $IGNITION_VERSION == ''">ignition-msgs8</depend>
<depend condition="$GZ_VERSION == '' and $IGNITION_VERSION == ''">ignition-transport11</depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>

View file

@ -0,0 +1,42 @@
#include <component_manager/publisher_component.hpp>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <ignition/transport/Node.hh>
#include <rclcpp/rclcpp.hpp>
#include <image_transport/image_transport.hpp>
#include <ros_gz_bridge/convert.hpp>
#include <sensor_msgs/msg/image.hpp>
namespace camera_component
{
class IgnCameraComponent: public env_manager::component_manager::PublisherComponent<sensor_msgs::msg::Image>
{
public:
explicit IgnCameraComponent(const rclcpp::NodeOptions &options)
: env_manager::component_manager::PublisherComponent<sensor_msgs::msg::Image>(options)
{
auto topic_name = "/camera";
_ign_node = std::make_shared<ignition::transport::Node>();
_ign_node->Subscribe(topic_name, &IgnCameraComponent::on_image, this);
}
private:
void on_image(const ignition::msgs::Image& img)
{
sensor_msgs::msg::Image rimg;
ros_gz_bridge::convert_gz_to_ros(img, rimg);
populate_publication(rimg);
}
std::shared_ptr<ignition::transport::Node> _ign_node;
};
} // namespace pub_component
#include "rclcpp_components/register_node_macro.hpp"
RCLCPP_COMPONENTS_REGISTER_NODE(camera_component::IgnCameraComponent)

View file

@ -6,7 +6,7 @@ if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
@ -31,7 +31,7 @@ find_package(rcutils REQUIRED)
find_package(glog 0.4.0 REQUIRED)
find_package(Lua 5.3 REQUIRED)
add_library(env_manager STATIC
add_library(env_manager SHARED
src/component_manager/component_manager.cpp
src/config/config_file_resolver.cpp
src/config/lua_file_resolver.cpp
@ -79,7 +79,7 @@ ament_target_dependencies(
rclcpp
glog
Lua
)
)
install(DIRECTORY config DESTINATION config)

View file

@ -9,7 +9,7 @@ include "environments/ground_true.lua"
-- env_manager configuration
ENV_MANAGER = {
environments = {
SIMULATOR, GROUND_TRUE
GROUND_TRUE
},
nodes = NODES
}

View file

@ -2,6 +2,7 @@
GROUND_TRUE = {
namespace = "ground_true",
components = {
--[[
talker_node = {
lib = "libpub_component.so",
class = "pub_component::Publisher",
@ -9,6 +10,10 @@ GROUND_TRUE = {
service_node = {
lib = "libsrv_component.so",
class = "srv_component::Service"
}
},]]--
camera_node = {
lib = "libign_camera_component.so",
class = "camera_component::IgnCameraComponent"
},
}
}

View file

@ -2,6 +2,7 @@
SIMULATOR = {
namespace = "simulator_env",
components = {
--[[
talker_node = {
lib = "libpub_component.so",
class = "pub_component::Publisher",
@ -9,6 +10,10 @@ SIMULATOR = {
service_node = {
lib = "libsrv_component.so",
class = "srv_component::Service"
}
},]]--
camera_node = {
lib = "libign_camera_component.so",
class = "camera_component::IgnCameraComponent"
},
}
}

View file

@ -1,4 +1,5 @@
NODES = {
--[[
talker_node = {
name = "talker",
type = "Publisher",
@ -8,5 +9,10 @@ NODES = {
name = "add_two_ints",
type = "Service",
msg_type = "example_interfaces/AddTwoInts"
}
},]]--
camera_node = {
name = "camera_node",
type = "Publisher",
msg_type = "sensor_msgs/Image"
},
}

View file

@ -14,4 +14,8 @@ repositories:
behavior_tree:
type: git
url: https://github.com/solid-sinusoid/behavior_tree.git
version: master
version: master
ros_gz:
type: git
url: https://github.com/gazebosim/ros_gz.git
version: humble