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 <./src_rob>`__. 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 <./src_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 <./ROS_ROB.html#installation-and-configuration-of-ros>`__ and `Installation and configuration of Robotran <./ROS_ROB.html#compilation-and-run-instructions>`__ sections. 1) Download this `ros\_rob <./src_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_)(); .. 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. 7) Go to the *catkin\_ws* folder et compile/build it with:\ ``~/catkin_ws$ catkin_make`` 8) Run ``$ roscore`` on a terminal. 9) 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. 10) 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.