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

[Msg] Define a custom ROS/ROS2 message #50

Merged
merged 1 commit into from
Oct 22, 2020
Merged
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ SET(ROS_ROOT "${CMAKE_PREFIX_PATH}/ros")
SET(ROS_INSTALL_LIBDIR "lib")
SET(ROS_INSTALL_BINDIR "bin")
SET(ROS_INSTALL_INCLUDEDIR "include")
SET(ROS_INSTALL_DATAROOTDIR "share")

## Override CMake Variables
SET(CMAKE_PREFIX_PATH "${ROS_BASE_PREFIX}")
Expand All @@ -53,6 +54,7 @@ ENDIF(BUILD_IN_WORKSPACE EQUAL -1)
SET(CMAKE_INSTALL_LIBDIR "${ROS_INSTALL_LIBDIR}")
SET(CMAKE_INSTALL_BINDIR "${ROS_INSTALL_BINDIR}")
SET(CMAKE_INSTALL_INCLUDEDIR "${ROS_INSTALL_INCLUDEDIR}")
SET(CMAKE_INSTALL_DATAROOTDIR "${ROS_INSTALL_DATAROOTDIR}")

## Configure variables to use in build
SET(ENV{LD_LIBRARY_PATH} "${CMAKE_PREFIX_PATH}/lib:$ENV{LD_LIBRARY_PATH}")
Expand Down Expand Up @@ -91,6 +93,7 @@ IF(NOT CMAKE_CXX_STANDARD)
SET(CMAKE_CXX_STANDARD 14)
ENDIF()

SET(NNS_ROS_COMMON_DIR ${PROJECT_SOURCE_DIR}/common)
SET(EXTRA_CFLAGS -Wall -Werror -fPIC -g)
SET(EXTRA_CXXFLAGS -Wall -Werror -fPIC -g)

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions debian/install
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
/opt/ros/*/share/gennodejs/ros/nns_ros_bridge/msg/*.js
/opt/ros/*/share/roseus/ros/nns_ros_bridge/msg/*.l
/opt/ros/*/share/nns_ros_bridge/cmake/*.cmake
/opt/ros/*/share/nns_ros_bridge/msg/tensors.msg
/opt/ros/*/share/nns_ros_bridge/msg/Tensors.msg
/opt/ros/*/share/nns_ros_bridge/package.xml
/opt/ros/*/share/common-lisp/ros/nns_ros_bridge/msg/*
/opt/ros/*/include/nns_ros_bridge/tensors.h
/opt/ros/*/include/nns_ros_bridge/Tensors.h
/opt/ros/*/lib/gstreamer-1.0/*
/opt/ros/*/etc/catkin/*

2 changes: 1 addition & 1 deletion packaging/nnstreamer-ros.spec
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ cp -r result %{buildroot}%{_datadir}/%{name}/unittest
%{__ros_install_path}/share/nns_ros_bridge/msg/*
%{__ros_install_path}/share/nns_ros_bridge/package.xml
%{__ros_install_path}/share/nns_ros_bridge/catkin_env_hook/20.gst_plugin_path.sh
%{__ros_install_path}/include/nns_ros_bridge/tensors.h
%{__ros_install_path}/include/nns_ros_bridge/Tensors.h
%{__ros_install_path}/lib/pkgconfig/nns_ros_bridge.pc
# pyc
%exclude %{__ros_install_path}/lib/python2.7/site-packages/nns_ros_bridge/*.pyc
Expand Down
149 changes: 12 additions & 137 deletions ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,84 +36,22 @@ FIND_PACKAGE(catkin REQUIRED COMPONENTS
genmsg
)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
add_message_files(FILES
tensors.msg
ADD_MESSAGE_FILES(
NOINSTALL
DIRECTORY ${NNS_ROS_COMMON_DIR}/msg
FILES Tensors.msg
)

## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )

## Generate added messages and services with any dependencies listed here
generate_messages(
GENERATE_MESSAGES(
DEPENDENCIES
std_msgs
)

################################################
## Declare ROS dynamic reconfigure parameters ##
################################################

## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed

## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
# cfg/DynReconf1.cfg
# cfg/DynReconf2.cfg
# )

###################################
## catkin specific configuration ##
###################################
Expand All @@ -123,7 +61,7 @@ generate_messages(
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
CATKIN_PACKAGE(
LIBRARIES nns_ros_bridge
CATKIN_DEPENDS roscpp rosbag std_msgs message_runtime
DEPENDS ${PKGS_COMMON}
Expand All @@ -141,37 +79,12 @@ SET(CXX_SRC_FILES_NNS_ROS_SRC
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
INCLUDE_DIRECTORIES(
${catkin_INCLUDE_DIRS}
)

## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/my_first_ros_pkg.cpp
# )

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide

ADD_LIBRARY(${PROJECT_NAME} ${CXX_SRC_FILES_NNS_ROS_PUBLISHER} ${CXX_SRC_FILES_NNS_ROS_SRC})
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
ADD_DEPENDENCIES(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
Expand All @@ -187,49 +100,11 @@ ENDIF()
## Install ##
#############

# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables and/or libraries for installation
# install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_node
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )

## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )

#############
## Testing ##
#############

## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_my_first_ros_pkg.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()

## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
INSTALL(
DIRECTORY ${NNS_ROS_COMMON_DIR}/msg
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
FILES_MATCHING PATTERN "*.msg"
)

INSTALL(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}
Expand Down
6 changes: 3 additions & 3 deletions ros/node/nns_roscpp_publisher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <std_msgs/MultiArrayLayout.h>
#include <time.h>

#include "nns_ros_bridge/tensors.h"
#include "nns_ros_publisher.h"
#include "nns_ros_bridge/Tensors.h"

const char BASE_NODE_NAME[] = "tensor_ros_sink";

Expand Down Expand Up @@ -85,7 +85,7 @@ NnsRosCppPublisher::NnsRosCppPublisher (const char *node_name,
* The name of published topic would be
* /tensor_ros_sink/PID_${PID}/${ElementNameOfTensorRosSink}
*/
this->ros_sink_pub = this->nh_child->advertise<nns_ros_bridge::tensors> (
this->ros_sink_pub = this->nh_child->advertise<nns_ros_bridge::Tensors> (
this->str_pub_topic_name, default_q_size);
}
}
Expand All @@ -111,7 +111,7 @@ NnsRosCppPublisher::~NnsRosCppPublisher ()
gboolean NnsRosCppPublisher::publish (const guint num_tensors,
const GstTensorMemory *tensors_mem, void *bag)
{
nns_ros_bridge::tensors tensors_msg;
nns_ros_bridge::Tensors tensors_msg;

g_return_val_if_fail (this->ready_to_pub, FALSE);
g_return_val_if_fail (num_tensors == this->num_of_tensors_pub, FALSE);
Expand Down
13 changes: 10 additions & 3 deletions ros2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ FIND_PACKAGE(ament_cmake REQUIRED)
FIND_PACKAGE(rclcpp REQUIRED)
FIND_PACKAGE(std_msgs REQUIRED)

FIND_PACKAGE(rosidl_default_generators REQUIRED)

ROSIDL_GENERATE_INTERFACES(
${PROJECT_NAME}
"${NNS_ROS_COMMON_DIR}/msg:Tensors.msg"
)

ADD_EXECUTABLE(publisher_member_function node/member_function.cpp)
AMENT_TARGET_DEPENDENCIES(publisher_member_function rclcpp std_msgs)

INSTALL(TARGETS
publisher_member_function
RUNTIME DESTINATION ${ROS_INSTALL_BINDIR}
LIBRARY DESTINATION ${ROS_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${ROS_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
)

IF(BUILD_TESTING)
Expand Down
5 changes: 5 additions & 0 deletions ros2/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
<build_depend>rclcpp</build_depend>
<build_depend>std_msgs</build_depend>

<build_depend>rosidl_default_generators</build_depend>

<exec_depend>rclcpp</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>rosidl_default_runtime</exec_depend>

<member_of_group>rosidl_interface_packages</member_of_group>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down