User Tools

Site Tools


getting_started:ros

Interfacing with ROS

ROS is a flexible framework for writing robot software. It is great collection of tools, libraries, and conventions. You can make use of ROS within EEROS in the following two ways.

Using Publisher and Subscriber Blocks in the Control System

You can insert blocks into the control system which publish or subscribe a given type of ROS message.

Dedicated blocks in the control system for interfacing with ROS

Special blocks in EEROS take care of sending signals to and receiving signals from ROS. These signals must be packed into ROS messages. Each topic transmits messages of a certain type. Depending on the message type you have to use certain blocks in your control system, see Blocks for Interfacing with ROS

Using ROS through EEROS HAL

EEROS can communicate with the underlying hardware through its Hardware Abstraction Layer. When using this, you need a special wrapper library (see Hardware Libraries).

Connect with ROS topics through the HAL

The EEROS HAL signals can be comprised of digital or analog inputs or outputs. They are specified in a JSON file.
If you want to test your application with a Gazebo simulation, you can define your inputs and outputs as ROS topics to connect your application with the simulation. For this no hardware is necessary. To use your application with hardware, you can use any of the available Hardware Libraries. By choosing the proper JSON file, you can easily switch between real hardware and simulation.
It is also possible to use ROS-topics alongside real hardware. You could determine a motor position by reading an encoder and set a control value for a motor. In parallel, you could publish the same values to ROS topics to visualize the state of the robot with rviz (if you have a model of your robot) or you could monitor the values with a ROS tool like rqt.

Preparations and Building

ROS needs to be installed on the developer machine as well as on the target machine. Before a ROS application can be started, you need to run the setup.bash script of ROS. The same applies for building the EEROS library with ROS support and for building an EEROS application with ROS support.
IMPORTANT If an integrated development environment such as kdevelop or Qt Creator is used, the IDE has to be started from a terminal after the setup.bash script has run.

Building the EEROS library with ROS

If you build the library with cmake, make sure you use the -DUSE_ROS=TRUE switch. An example of a cmake call could look like this:
cmake -DCMAKE_INSTALL_PREFIX=“$install_dir” -DUSE_ROS=TRUE ..

Building an EEROS application with ROS functionality

The CMAKE file for the EEROS application using ROS has to be expanded as follows:

cmake_minimum_required(VERSION 2.8)
project(testProject)
 
## ROS
message(STATUS "looking for package 'ROS'")
find_package( roslib REQUIRED )
if (roslib_FOUND)
	message( STATUS "-> ROS found")
	add_definitions(-DROS_FOUND)
	include_directories( "${roslib_INCLUDE_DIRS}" )
	message( STATUS "roslib_INCLUDE_DIRS: " ${roslib_INCLUDE_DIRS} )
	list(APPEND ROS_LIBRARIES "${roslib_LIBRARIES}")
	find_package( rosconsole REQUIRED)
	list(APPEND ROS_LIBRARIES "${rosconsole_LIBRARIES}")
	find_package( roscpp REQUIRED )
	list(APPEND ROS_LIBRARIES "${roscpp_LIBRARIES}")
else()
	message( STATUS "-> ROS NOT found")
endif()

find_package(EEROS REQUIRED)
include_directories(${EEROS_INCLUDE_DIR};${EEROS_LIBUCL_INCLUDE_DIR})
link_directories(${EEROS_LIB_DIR};${EEROS_LIBUCL_LINK_DIR})
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 
add_executable(testProject main.cpp)
target_link_libraries(testProject eeros ucl ${CMAKE_DL_LIBS} ${ROS_LIBRARIES})

Make your EEROS Application a ROS Node

Initialize the ROS node in your main function and give it a name.

  #include <ros/ros.h>
 
  int main(int argc, char **argv) {
	...
	rosTools::initNode("rosTest");
	log.trace() << "ROS node initialized.";
	...

All ROS tools such as rqt will list your EEROS application under this name.

If you want to register a signal handler, e.g. for shutting down a system (see Shutting down a System Properly), you have to register it after the ROS node is initialized. The ROS node will properly shut down as soon as the last node handler is destroyed when going out of scope.

Running your Application

An EEROS application using ROS needs to be started with super user privileges. Further, ROS needs some system variables, like ROS_MASTER_URI, which are defined by the setup.bash script of ROS. To forward these variables to the super user process, the option -E has to be used.

$ sudo -E ./application
getting_started/ros.txt · Last modified: 2018/08/31 14:46 (external edit)