0
$\begingroup$

Rosanswers logo

Hey y'all, pointcloud here again getting into more trouble.

I'm trying to create a tutorial on converting a ROS1 package to ROS2, as I need it for my project and it would be possibly helpful for other people as well to have an example on an actual package, rather than a "tutorial built custom package".

In order to make it more applicable to a wider range of packages.

including a ROS1 package in my micro-ros project fails to build, likely because the conversion is incomplete. So here are the steps I have taken..

I have been following a tutorial regarding porting ROS1 to ROS2. It can be found here: https://industrial-training-master.readthedocs.io/en/melodic/_source/session7/ROS1-to-ROS2-porting.html

1. <micro-ros_ws>/extra_packages git clone https://github.com/TFmini/TFmini-ROS.git
2. modified the CMakeLists.txt (see below before / after)
3. modified the package.xml (see below before / after)
4. modified TFmini.cpp, replacing #include <ros/ros.h> with #include <rclcpp/rclcpp.hpp>
5. <--- This is where my understanding of converting ROS1 package to ROS2 stops --->
6. build of course fails, as I'm likely missing some steps

I believe the issue is with my understanding of converting the ROS1 package properly. I can see the tutorial I'm following converts it straight into ROS2 using cpp as base language, whereas I'm writing a tutorial converting into a micro-ros environment. And that is a quite different task.

Starting to wonder if it would be best to just start writing my whole entire package from the beginning?! Rather than converting an old ROS1 package..

ORIGINAL CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(tfmini_ros)

find_package(catkin REQUIRED COMPONENTS
  sensor_msgs
  roscpp
)
find_package(Boost REQUIRED COMPONENTS system)

catkin_package(
  INCLUDE_DIRS include
)

include_directories(${catkin_INCLUDE_DIRS} include)


add_executable(tfmini_ros_node 
   src/TFmini_ros_node.cpp
   src/TFmini.cpp
)

target_link_libraries(tfmini_ros_node
   ${catkin_LIBRARIES}
)
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -std=gnu++11")

install(TARGETS tfmini_ros_node tfmini_ros_node
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY include
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
)

install(FILES
 launch/tfmini.launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

Modified CMakeLists.txt

cmake_minimum_required(VERSION 3.8)
project(tfmini_ros)

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

find_package(sensor_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Range.msg"
  DEPENDENCIES sensor_msgs
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  set(ament_cmake_copyright_FOUND TRUE)
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()

The original package.xml

<?xml version="1.0"?>
<package>
  <name>tfmini_ros</name>
  <version>0.0.1</version>
  <description>The TFmini_ros package</description>

  <maintainer email="[email protected]">wenquan</maintainer>

  <license>TODO</license>
  <author >TAN</author>
  
  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>roscpp</build_depend>
  <run_depend>boost</run_depend>

  <export>
  </export>
</package>

My modifed 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>tfmini_ros</name>
  <version>0.0.1</version>
  <description>The TFmini_ros2 package</description>
  <maintainer email="[email protected]">administrator</maintainer>
  <license>License declaration</license>

  <!-- Unsure if sensor_msgs needs to be "depend" or "build_depend" -->
  <depend>sensor_msgs</build_depend>
  <!--<build_depend>sensor_msgs</build_depend>-->
  <build_depend>roscpp</build_depend>
  <exec_depend>rosidl_default_runtime</exec_depend>
  <member_of_group>rosidl_interface_packages</member_of_group>
  <!-- -->
  
  <buildtool_depend>ament_cmake</buildtool_depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

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

Any ideas what exactly is missing? Do I need to install a version of ros1 first to enable usage of ros1 packages?

Thanks team


Originally posted by PointCloud on ROS Answers with karma: 120 on 2022-10-23

Post score: 0


Original comments

Comment by gvdhoorn on 2022-10-23:
Could I ask you to please update the title of your question to better reflect your actual question?

"severely fails" doesn't really convey they fact you're trying to build a ROS 1 Catkin package in a ROS 2 workspace with Colcon.

Comment by PointCloud on 2022-10-23:
Hey dude, updated not only the title, but rather the entire question to make more sense. It was probably too early when I wrote that initial post :-/

However, I almost certainly believe it is better to start from scratch creating a package and using the existing ROS1 version as a template, than trying to convert....

Especially for beginners, I believe that is the better approach, as it teaches not only interpreting older packages, but also gets newcomers into building and creating own packages. On top of that using a template (even if it's an older version) it does give some guidance.

Thanks, I will leave this as official and add an answer.

Comment by gvdhoorn on 2022-10-24:
I'm not sure I understand what you did.

TFmini/TFmini-ROS.git doesn't seem to build any messages itself.

The Range message is already provided by the sensor_msgs package. Why are you building it in the package you converted? You also don't appear to be building any of the source files of the original package any more.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

If you're just starting out: do not try to build ROS 1 packages with Colcon.

And yes (or "no", depending on how you look at it): you cannot build ROS 1 packages with only a ROS 2 installation.

ROS 1 and ROS 2 are only compatible at the conceptual level. There are almost no shared bits of infrastructure, code or development environments.

Looking through the documentation, i found out ros2 doesn't care if a package is ros1 or ros2 and will attempt the build.

I don't know what you mean by this.

Pedantic, but: "ros2" isn't a (single) thing. It's a collection of software projects. Colcon is technically not even a part of it. "ros2" does not build anything, only a build tool would do that. Colcon can build ROS 1 workspaces, but it isn't really intended to do so. And even if you'd build a ROS 1 package with Colcon in a ROS 2 workspace, it wouldn't really work, as ROS 1 packages cannot really meaningfully be integrated into a ROS 2 application (yes, there is a bridge, but it comes with all sorts limitations of its own).


Originally posted by gvdhoorn with karma: 86574 on 2022-10-23

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

In almost all cases (especially for beginners) it is better to build a package from ground up, than converting it from ROS1 to ROS2. Especially, as it will be easier when following the ROS2 tutorials, and having an example ROS1 package as template. It will provide guidance on two levels.

  1. The workflow
  2. The logic needed for your package (conversion required tho)

So my advice, start fresh forget copy&paste. It ain't gonna do you any favs!


Originally posted by PointCloud with karma: 120 on 2022-10-23

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

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