Ros_rob

This is a ROS package that allows you to run a Robotran project and publishes/receives data on ROS topics. It can be downloaded here. Here especially is an example where you can drive a car with the left and right keyboard arrows and, thanks to a ROS topic, publish the torque which will be applied in the steering wheel. This can be done with the ros_rasp package running on a Raspberry Pi.

Installation and configuration of ROS

To install ROS, follow this link. To configure your ROS environment, follow the Installation and Configuration with one constraint, you must create your catkin workspace (catkin_ws) in your /home/user_name/ folder (in order to allow Robotran to find the correct path to an executable open_gl_exe, mandatory for the real-time simulation). After that, in order to have a better comprehension and management of ROS, you can follow all the beginner level from official ROS Tutorials and Writing a simple publisher/subscriber.

REMARK:

Note that this ROS package has only been written and tested on a Linux distribution (Ubuntu 20.04).

The ROS version used here is Melodic and the ROS compiler is catkin. The nodes are written in C++ except one in Python.

REMARK:

If you use an other/newer version of ROS like Noetic, you should update the ROS version names in the CmakeLists.txt. See the ROS support on that matter.

Installation and configuration of Robotran

For using Robotran on Linux you need to install MBsysC in order to use the C/C++ version of Robotran. You can also install MBsysPad if you want 3D visualisation and project manipulation.

To understand the multibody system dynamics used here you can read the Robotran Basics.

In order to have a better understanding and management of Robotran you can follow the Getting Started Tutorial in C/C++. If you want to go further you can also follow the Equilibirum and Modal modules of Robotran Tutorial (note that these modules are not used here in a real-time application).

This package also uses the real-time features of Robotran so please follow this tutorial. ..

REMARK:

You have to use the correct version of mbsysc. It should work for all releases after September 2020 (v1.18.0). If not, please contact us !

Finally, in order to link Robotran and ROS, we need to use multithreading. Update the package index $ sudo apt-get update and install the pthread library $ sudo apt-get install libpthread-stubs0-dev.

REMARK:

If lpthread is not found, adding cmake_policy(SET CMP0079 NEW) just before target_link_libraries (${LIB_MBSYSC_REALTIME} ${CMAKE_THREAD_LIBS_INIT}) in the CMakeList.txt of your project should help.

Compilation and run instructions

  1. Download the ros_rob package in your catkin_ws/src folder.
  2. Go to the CMakeLists of each Robotran project (for example: /home/user_name/catkin_ws/src/ros_rob/src/Car/workR/CMakeLists.txt) and set the correct path to the MBsysC folder with /home/user_name/.robotran/mbsysc-dev/MBsysC/.
  3. Go to the catkin_ws folder et compile/build it with:~/catkin_ws$ catkin_make
  4. Run $ roscore on a terminal.
  5. Run $ rosrun ros_rob exe_Car on a new terminal. It starts the ROS node which runs the real-time simulation in Robotran and publishes the torque on a topic for a listener node. The node closes automatically at the end of the simulation. You can steer the car with the right and left arrows of your keyboard.
  6. Close roscore by pressing ctrl+C in the terminal when the simulation is finished.

Add your own Robotran Project

The example here is made with a Robotran Project which simulates the dynamics of a car. But you can also add your own Robotran project (other type of vehicles, other multibody system, …).

This tutorial assumes you followed the Installation and configuration of ROS and Installation and configuration of Robotran sections.

  1. Download this ros_rob package in your catkin_ws/src folder.

  2. Copy all the files and folders of your Robotran project (userfctR, workR, ect) without build folder in ros_rob/src/name_of_your_project.

  3. Then add the CMakeList of Robotran to the one of ROS by modifying this line in the ROS CMakeList

    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/name_of_your_project/workR)
    
  4. Include the ROS and Pthread libraries in the Robotran CMakeList

    include_directories(/opt/ros/melodic/include /opt/ros/melodic/lib)
    
    target_link_libraries(${Executable} -I/opt/ros/melodic/include -L/opt/ros/melodic/lib -lroscpp -lrostime -lrosconsole -lroscpp_serialization)
    
    target_link_libraries(${Executable} -lpthread)
    
  5. Change the extension of the Robotran main.c by main.cpp. Change the content of the main with the template .main_robotran_template.cpp and follow the change instructions inside the template.

  6. As you can see at point 5) and 6) we need to use a user model structure from Robotran. Follow the user model tutorial for structures in order to initialize it in MBSysPad and create an header file (also see thread_struct.h in ros_rob package for an example of declaration of the structure). This structure contains pointer to function like give_torque_access which allows ROS publisher and subscriber to have access to mbs_data without segmentation fault due to the multithreading. After that you can give the access to the ROS publisher and subscriber in all the user functions with:

    (*mbs_data->user_model->thread.thread_struct->pointeur_<name_of_access_function>)();
    

NOTE:

The main of Robotran is now in C++ but the user functions that you will write are usually in C and called by this C++ function. You can have a look on Name Mangling and extern “C” in C++ to ensure that the C++ compiler behaves like a C compiler for these functions.

  1. Go to the catkin_ws folder et compile/build it with:~/catkin_ws$ catkin_make
  2. Run $ roscore on a terminal.
  3. Run $ rosrun ros_rob exe_your_project_name on a new terminal. It starts the ROS node which runs the real-time simulation in Robotran and publishes the torque on a topic for the listener node. The node closes automatically at the end of the simulation.
  4. Close roscore by pressing ctrl+C in the terminal.

Deal with multiple Robotran projects

If you need to deal with several Robotran projects, just follow the above instructions one more time with two exceptions:

  • At the point 3 you can have only one link with a Robotran CMakeLists (only one add_subdirectory).
  • At the point 7, before compile/build your workspace you need to delete the ros_rob folder in the build folder.

This means that you can compile and build only one Robotran project at a time. But once the new ROS executable is created (here the exe_your_project_name) you can run whichever one you want.

Use your own ROS message

The ROS messages here are used to vehicle data for the torque, position and velocity of a steering wheel which are floating point values. It could be useful to create your own ROS messages in order to deal with the values provided and needed by your Robotran project. You can consult this tutorial and this ROS wiki for more informations.