0
$\begingroup$

Rosanswers logo

Hi,

I am trying to communicate ROS1 (Melodic) and ROS2 (Dashing), but I am not able after several attempts ... My ROS2 package is called new_msgs, the same name that in ROS1 workspace, with the same .msg:

YoloList.msg
YoloObstacle.msg

Now I describe the package.xml and CMakeLists.txt of ROS2 workspace:

package.xml:

<?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>new_msgs</name>
  <version>0.0.1</version>
  <description>New message defined for ROS2</description>
  <maintainer email="[email protected]">root</maintainer>
  <license>Apache License 2.0</license>

  <author>CGH</author>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <build_depend>rosidl_default_generators</build_depend>
  <exec_depend>rosidl_default_runtime</exec_depend>

  <member_of_group>rosidl_interface_packages</member_of_group>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
project(new_msgs)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

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

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

rosidl_generate_interfaces(new_msgs
  "msg/YoloObstacle.msg"
  "msg/YoloList.msg"
  "msg/Header.msg"
  DEPENDENCIES builtin_interfaces std_msgs
)

ament_package()

Now I describe the package.xml and CMakeLists.txt of ROS1 workspace:

<?xml version="1.0"?>
<package format="2">
  <name>new_msgs</name>
  <version>0.0.0</version>
  <description>The new_msgs package</description>
  <maintainer email="[email protected]">root</maintainer>
  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_export_depend>roscpp</build_export_depend>
  <build_export_depend>rospy</build_export_depend>
  <build_export_depend>sensor_msgs</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>
  <exec_depend>roscpp</exec_depend>
  <exec_depend>rospy</exec_depend>
  <exec_depend>sensor_msgs</exec_depend>
  <exec_depend>std_msgs</exec_depend>
  <!-- <exec_depend>message_runtime</exec_depend> -->

</package>

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(new_msgs)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  sensor_msgs
  std_msgs
  message_generation
)

add_message_files(
   FILES
   Header.msg
   YoloList.msg
   YoloObstacle.msg
 )

generate_messages(
   DEPENDENCIES
   sensor_msgs
   std_msgs
 )

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES new_msgs
CATKIN_DEPENDS roscpp rospy sensor_msgs std_msgs
#CATKIN DEPENDS message_runtime
#  DEPENDS system_lib
)

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

In both cases the content of the messages is exactly the same:

Header.msg

#Common Header for ROS2-ROS1 communication

uint32 seq
int32 sec
uint32 nanosec
string frame_id

YoloObstacle.msg

string type
float64 probability
float64 x1
float64 y1
float64 x2
float64 y2
float64 h
float64 w
float64 l
float64 tx
float64 ty
float64 tz
int8 object_id

YoloList.msg

new_msgs/Header header
YoloObstacle[] yololist # Cannot write the name file with the same msg name (YoloList in this case)

Then, when I try to compile by using:

colcon build --merge-install --symlink-install --packages-select ros1_bridge --cmake-force-configure

I get the following error:

root@robesafe-GT62VR-7RE:~/ros1_bridge_ws# colcon build --merge-install --symlink-install --packages-select ros1_bridge --cmake-force-configure
Starting >>> ros1_bridge
--- stderr: ros1_bridge                               
libros1_bridge.so: undefined reference to `ros1_bridge::get_factory_new_msgs__msg__YoloList(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
libros1_bridge.so: undefined reference to `ros1_bridge::get_factory_new_msgs__msg__Header(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
libros1_bridge.so: undefined reference to `ros1_bridge::get_factory_new_msgs__msg__YoloObstacle(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [parameter_bridge] Error 1
make[1]: *** [CMakeFiles/parameter_bridge.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
libros1_bridge.so: undefined reference to `ros1_bridge::get_factory_new_msgs__msg__YoloList(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
libros1_bridge.so: undefined reference to `ros1_bridge::get_factory_new_msgs__msg__Header(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
libros1_bridge.so: undefined reference to `ros1_bridge::get_factory_new_msgs__msg__YoloObstacle(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [dynamic_bridge] Error 1
make[1]: *** [CMakeFiles/dynamic_bridge.dir/all] Error 2
libros1_bridge.so: undefined reference to `ros1_bridge::get_factory_new_msgs__msg__YoloList(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
libros1_bridge.so: undefined reference to `ros1_bridge::get_factory_new_msgs__msg__Header(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
libros1_bridge.so: undefined reference to `ros1_bridge::get_factory_new_msgs__msg__YoloObstacle(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [static_bridge] Error 1
make[1]: *** [CMakeFiles/static_bridge.dir/all] Error 2

Any idea :( ??

Carlos


Originally posted by Cram3r95 on ROS Answers with karma: 11 on 2019-08-22

Post score: 0


Original comments

Comment by Dirk Thomas on 2019-08-22:
You don't have to modify the code of the ros1_bridge. You only have to rebuild it from source following its README.

If that doesn't pickup your custom message package than something is wrong in that package. You might want to share the content of both your ROS 1 and ROS 2 messsage packages in that case.

Comment by Cram3r95 on 2019-08-22:
Yeah sure:

ros2_ws: src: new_msgs: CMakeLists.txt package.xml msg include (not used) src (not used)

The content of msg is: Header.msg YoloList.msg YoloObstacle.msg

In both new_msgs packages (both ROS1 and ROS2) the content is identical (same fields in the messages).

Comment by Dirk Thomas on 2019-08-22:
You need to share the actual content of your message packages if you would like help, e.g. the package.xml.

Comment by Cram3r95 on 2019-08-22:
Ok, it is already done. I have shared the content of both packages and the fields of their messages.

Comment by Dirk Thomas on 2019-08-23:
Please include all your steps to build the bridge including what you have sourced in that shell. Also what version of the ros1_bridge repo have you cloned? The full logs (either using --event-handlers console_direct+ or from the log/latest_build directory might also contain valuable information.

Comment by pavel92 on 2019-08-24:
I edited your question to apply proper code formatting and removed the comments in your files to make it shorter and improve readability

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I will take the liberty to guess that your ROS1 and ROS2 new_msgs packages are used only for message generation (do not contain any headers and src files). In that case you can try the following:

ROS2 package.xml:

<?xml version="1.0"?>
<package format="3">
  <name>new_msgs</name>
  <version>0.0.1</version>
  <description>New message defined for ROS2</description>
  <maintainer email="[email protected]">root</maintainer>
  <license>Apache License 2.0</license>
  <author>CGH</author>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>std_msgs</depend>
  <depend>builtin_interfaces</depend>

  <build_depend>rosidl_default_generators</build_depend>
  <exec_depend>rosidl_default_runtime</exec_depend>

  <member_of_group>rosidl_interface_packages</member_of_group>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

ROS2 CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project(new_msgs)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)
find_package(builtin_interfaces REQUIRED)

rosidl_generate_interfaces(new_msgs
  "msg/YoloObstacle.msg"
  "msg/YoloList.msg"
  "msg/Header.msg"
  DEPENDENCIES std_msgs builtin_interfaces
)

ament_export_dependencies(rosidl_default_runtime)

ament_package()

ROS1 package.xml:

<?xml version="1.0"?>
<package format="2">
  <name>new_msgs</name>
  <version>0.0.0</version>
  <description>The new_msgs package</description>
  <maintainer email="[email protected]">root</maintainer>

  <buildtool_depend>catkin</buildtool_depend>

  <depend>std_msgs</depend>
  <depend>sensor_msgs</depend>

  <build_depend>message_generation</build_depend>
  <exec_depend>message_runtime</exec_depend>

</package>

ROS1 CMakeLists.txt: cmake_minimum_required(VERSION 2.8.3) project(new_msgs)

find_package(catkin REQUIRED COMPONENTS
  sensor_msgs
  std_msgs
  message_generation
)

add_message_files(
   FILES
   Header.msg
   YoloList.msg
   YoloObstacle.msg
 )

generate_messages(
   DEPENDENCIES
   sensor_msgs
   std_msgs
 )

catkin_package(
CATKIN_DEPENDS message_runtime sensor_msgs std_msgs
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

Building the ros1_bridge from source is the more tricky part. Refer to the package documentation for that.


Originally posted by pavel92 with karma: 1655 on 2019-08-23

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Cram3r95 on 2019-08-24:
It is almost working, I have no errors now, but the bridge does not recognize the ROS1 package, since it does not find the specialization for ROS1

Created 2 to 1 bridge for service /play_1566674240702462381/pause_playback failed to create 2to1 bridge for topic '/yolov3_tracking_list' with ROS 2 type 'new_msgs/msg/YoloList' and ROS 1 type '': No template specialization for the pair

What can I do?

Note that I modified my ROS1 and ROS2 package.xml and CMakeLists.txt and built the ros1_bridge from source by using:

colcon build --symlink-install --packages-select ros1_bridge --cmake-force-configure

But still now working...

Comment by pavel92 on 2019-08-24:
Do you get this error when you try to run ros1_bridge? If yes, then this is another issue and I would advise you to create another question and accept this one as correct (by clicking the tick mark above) if it helped you with your initial problem. My guess is that you have not sourced your ROS environments properly. Please write the the step by step commands that you are executing (including environment sourcing). Basically you need to source your ROS1 env first, then your ROS2 env and run the colcon build command. Then export the ROS_MASTER_URI and run the ros1_bridge. Also note that in another terminal you will need to have a ROS1 roscore running

Comment by Cram3r95 on 2019-08-24:
My exact steps are:

  1. When trying to recompile the bridge from source:

source /opt/ros/melodic/setup.bash source /root/ros_ws/devel/setup.bash (due to my custom messages) source /root/ros2_ws/install/local_setup.bash

Then: colcon build --symlink-install --packages-select ros1_bridge --cmake-force-configure

All is perfect

  1. When trying to run the ros1_bridge:

source /opt/ros/melodic/setup.bash source /root/ros_ws/devel/setup.bash source /root/ros2_ws/install/local_setup.bash source /ros1_bridge_ws/install/setup.bash

ros2 run ros1_bridge dynamic_bridge --bridge-all-topics

But still not working .... :(

I do not what more can I do ....

Comment by Dirk Thomas on 2019-08-24:
As mentioned above already please share the full logs in order to see what is happening when you build the bridge.

Comment by Cram3r95 on 2019-08-25:
Dirk, how can I do this? I have seen the logs but the content is huge (for the latest build). Is there any way to share these files here?

Comment by Dirk Thomas on 2019-08-25:
E.g. create a Gist and share the link here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.