Rosbotran with ROS2 ------------------- This tutorial explain how to create a robotran project compatible with `ROS 2 `__. NOTE: This tutorial has not been extensively tested. Contact us for more information info@robotran.be. - 1) Make sure that Robotran is installed - 2) Make sure that ROS 2 is installed - 3) Create or go to the ``src`` folder of your ROS workspace - 4) Create a new ROS 2 project in this folder with the following command: ``ros2 pkg create --build-type ament_cmake --license Apache-2.0 `` - 5) Create a new Robotran project with the same name as your ros project and save it - 6) Move all the folders from the Robotran project inside ``/src``. The architecture of your project should look like this: `` ├── CMakeLists.txt ├── include │   └── ├── package.xml ├── README.md └── src ├── animationR │   └── vrml ├── dataR │   └── .mbs ├── resultsR ├── symbolicR ├── userfctR └── workR ├── CMakeLists.txt └── src └── main.c`` - 7) Edit the main file ``CMakeLists.txt`` and : - a) Add the rclcpp package with the other packages: :: find_package(rclcpp REQUIRED) - b) Copy and paste after the ``find_package(...)`` lines all the lines from the ``src/workR/CMakeLists.txt`` between the lines: :: set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) ... target_link_libraries(exe_${PROJECT_NAME} ${MBSYSC_LIBRARIES}) - c) Change the paths in the ``file(...)`` to be relative from this ``CMakeLists.txt``: - Change from ``../`` to ``src/`` - Change from ``src/`` to ``src/workR/src/`` - d) Change the extension from ``file(GLOB MAIN_SRC ...)`` from ``c`` to ``cpp``. Be advised, the c function must be defined in a *extern c {}* block. - e) Change the ``include_directories`` commands to (add other include directories in the list if needed) :: include_directories( include src src/symbolicR src/userfctR src/workR/src ) - f) Remove the ``exe`` from the name of the executable: :: add_executable (exe_${PROJECT_NAME} ${MAIN_SRC}) add_dependencies(exe_${PROJECT_NAME} Project_user Project_symbolic) target_link_libraries(exe_${PROJECT_NAME} ${MBSYSC_LIBRARIES}) become :: add_executable (${PROJECT_NAME} ${MAIN_SRC}) add_dependencies(${PROJECT_NAME} Project_user Project_symbolic) target_link_libraries(${PROJECT_NAME} ${MBSYSC_LIBRARIES}) - g) Add below (at the bottom of the file) those commands: :: ament_target_dependencies( ament_index_cpp ) install(TARGETS Project_user DESTINATION lib/${PROJECT_NAME}) install(TARGETS Project_symbolic DESTINATION lib/${PROJECT_NAME}) install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME}) # To be able to find the non-compiled files install(DIRECTORY src DESTINATION share/${PROJECT_NAME}) - 8) Remove the file ``src/workR/CMakeLists.txt`` - 9) Change the extension of the file ``src/workR/src/main.c`` to ``cpp`` - 10) Update the ``main.cpp`` file of the robotran project - a) Add the header: :: #include - b) Allow the compatibility between ``C`` and ``CPP`` of the header files with the ``extern "C"``: :: extern "C" { #include "mbs_data.h" #include "mbs_part.h" #include "mbs_equil.h" #include "mbs_modal.h" #include "mbs_dirdyn.h" #include "integrator.h" #include "mbs_invdyn.h" #include "mbs_solvekin.h" #include "mbs_message.h" #include "mbs_loader.h" #include "mbs_set.h" } - c) Change the loading code of the project: :: // Project name of ROS + robotran std::string project_name = "rosbotran"; // Find package path std::string package_path = ament_index_cpp::get_package_share_directory(project_name); // Specify path for the libraries std::string project_path = package_path + "/src/dataR/" + project_name + ".mbs"; // previous code was this but I (ST) modified it 25/2/25: std::string lib_path = "install/" + project_name + "/lib/" + project_name + "/"; std::string lib_path = package_path + "/../../lib/" + project_name + "/"; // Load the project with the libraries MbsData *mbs_data; // if not already declared MbsLoader * mbs_loader = mbs_new_loader(); mbs_loader->opts->symbolicLib_path = (char*) lib_path.c_str(); mbs_loader->opts->userfctLib_path= (char*) lib_path.c_str(); mbs_data = mbs_load_with_loader(project_path.c_str(), mbs_loader); - d) Change the path of the output of robotran (respath and animpath) as they are relative to the location of the executable (this step is not clear, you perhaps need to test by trial and error): :: "../../src//resultsR/dirdyn_q.res" - 11) Generate all the files for Robotran - 12) Build the project with command ``colcon build`` in the root directory of your ros workspace. You can use "colcoon build --packages-select " to only rebuild your package. - 13) Test your code by running your node ``ros2 run ``