The toolchain is a set of libraries and programs that you must compile on your computer in order to build Orocos applications. In case you are on a Linux system, you can use the bootstrap.sh script, which does this for you.
After installation, these libraries are available:
These programs are available:
Orocos component libraries are living in packages. You need to understand the concept of packages in Orocos in order to be able to create and use components. See more about Component Packages
Your primary reading material for creating components is the Orocos Components Manual. A component is compiled into a shared library (.so or .dll).
Use the orocreate-pkg script to create a new package that contains a ready-to-compile Orocos component, which you can extend or play with. See Using orocreate-pkg for all details. (Script available from Toolchain version 2.1.1 on).
Alternatively, the oroGen tool allows you to create components with a minimum knowledge of the RTT API.
The DeploymentComponent loads XML files or scripts and dynamically creates, configures and starts components in a single process. See the Orocos Deployment Manual
The TaskBrowser is our primary interface with a running application. See the Orocos TaskBrowser Manual
$ cd ~/orocos $ orocreate-pkg myrobot component Using templates at /home/kaltan/src/git/orocos-toolchain/ocl/scripts/pkg/templates... Package myrobot created in directory /home/kaltan/src/git/orocos-toolchain/myproject/myrobot $ cd myrobot $ ls CMakeLists.txt Makefile manifest.xml src # Standard build (installs in the same directory as Orocos Toolchain): $ mkdir build ; cd build $ cmake .. -DCMAKE_INSTALL_PREFIX=orocos $ make install # OR: ROS build: $ make
You can modify the .cpp/.hpp files and the CMakeLists.txt file to adapt them to your needs. See orocreate-pkg --help for other options which allow you to generate other files.
All files that are generated may be modified by you, except for all files in the typekit directory. That directory is generated during a build and under the control of the Orocos typegen tool, from the orogen package.
After the 'make install' step, make sure that your RTT_COMPONENT_PATH includes the installation directory (or that you used -DCMAKE_INSTALL_PREFIX=orocos) and then start the deployer for your platform:
$ deployer-gnulinux Switched to : Deployer This console reader allows you to browse and manipulate TaskContexts. You can type in an operation, expression, create or change variables. (type 'help' for instructions and 'ls' for context info) TAB completion and HISTORY is available ('bash' like) Deployer [S]> import("myrobot") = true Deployer [S]> displayComponentTypes I can create the following component types: Myrobot OCL::ConsoleReporting OCL::FileReporting OCL::HMIConsoleOutput OCL::HelloWorld OCL::TcpReporting OCL::TimerComponent = (void) Deployer [S]> loadComponent("TheRobot","Myrobot") Myrobot constructed ! = true Deployer [S]> cd TheRobot Switched to : TheRobot TheRobot [S]> ls Listing TaskContext TheRobot[S] : Configuration Properties: (none) Provided Interface: Attributes : (none) Operations : activate cleanup configure error getPeriod inFatalError inRunTimeError isActive isConfigured isRunning setPeriod start stop trigger update Data Flow Ports: (none) Services: (none) Requires Operations : (none) Requests Services : (none) Peers : (none)
You now need to consult the Component Builder's Manual for instructions on how to use and extend your Orocos component. All relevant documentation is available on the Toolchain Reference Manuals page.
The generated package contains a manifest.xml file and the CMakeLists.txt file will call ros_buildinit() if ROS_ROOT has been set and also sets the LIBRARY_OUTPUT_PATH to packagename/lib/orocos such that the ROS tools can find the libraries and the package itself. The ROS integration is mediated in the UseOrocos-RTT.cmake file, which gets included on top of the generated CMakeLists.txt file and is installed as part of the RTT. The Makefile file is rosmake compatible.
The OCL deployer knows about ROS packages and can import Orocos components (and their dependencies) from them once your ROS_PACKAGE_PATH has been correctly set.
Extracted from the instructions on http://www.ros.org/wiki/groovy/Installation/OSX/MacPorts/Repository
echo 'export PATH=/opt/local/bin:/opt/local/sbin:$PATH' >> ~/.bash_profile
echo 'export LIBRARY_PATH=/opt/local/lib:$LIBRARY_PATH' >> ~/.bash_profile
cd ~ git clone https://github.com/smits/ros-macports.git
sudo sh -c 'echo file:///Users/user/ros-macports >> /opt/local/etc/macports/sources.conf'
sudo port sync
sudo port install python27 sudo port select --set python python27 sudo port install boost libxslt lua51 ncurses pkgconfig readline netcdf netcdf-cxx omniORB p5-xml-xpath ros-hydro-catkin py27-sip ros-hydro-cmake_modules eigen3 dyncall ruby20 sudo port select --set nosetests nosetests27 sudo port select --set ruby ruby20
ruby --version
which gem sudo gem install facets nokogiri
lua -v
sudo port uninstall lua
git clone https://github.com/gccxml/gccxml cd gccxml mkdir build cd build cmake .. -DCMAKE_INSTALL_PREFIX=/opt/local make sudo make install
mkdir -p ~/orocos_ws/src cd ~/orocos_ws/src sudo port install py27-wstool wstool init . curl https://gist.githubusercontent.com/smits/9950798/raw | wstool merge - wstool update cd orocos_toolchain git submodule foreach git checkout toolchain-2.8
cd ~/orocos_ws source /opt/local/setup.bash sudo /opt/local/env.sh catkin_make_isolated --install-space /opt/orocos --install --cmake-args -DENABLE_CORBA=TRUE -DCORBA_IMPLEMENTATION=OMNIORB - DRUBY_INCLUDE_DIR=/opt/local/include/ruby-2.0.0 -DRUBY_CONFIG_INCLUDE_DIR=/opt/local/include/ruby-2.0.0/x86_64-darwin13 -DRUBY_LIBRARY=/opt/local/lib/libruby2.0.dylib -DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH;/opt/local"
source /opt/orocos/setup.bash
echo ‘export GCCXML_COMPILER=g++-mp-4.3’ >> ~/.bash_profile
These exercises are hosted on Github .
You need to have the Component Builder's Manual (see Toolchain Reference Manuals) at hand to complete these exercises.
Take also at the Toolchain Reference Manuals for in-depth explanations of the deployment XML format and the different transports (CORBA, MQueue)
You'll need to have the Scripting Chapter of the Component Builder's Manual at hand for clarifications on syntax and execution semantics.
path("/opt/orocos/lib/orocos") // Path to where components are located [1] import("myproject") // imports a specific project in the path [2] import("ocl") // imports ocl from the path require("print") // loads the 'print' service globally. [3] loadComponent("HMI1","OCL::HMIComponent") // create a new HMI component [4] loadComponent("Controller1","MyProjectController") // create a new controller loadComponent("Test1","TaskContext") // creates an empty test component
You can test this code by doing:
deployer-gnulinux -s startup.ops
deployer-gnulinux ... Deployer [S]> help runScript runScript( string const& File ) : bool Runs a script. File : An Orocos program script. Deployer[S]> runScript("startup.ops")
The first line of startup.ops ([1]) extends the standard search path for components. Every component library directly in a path will be discovered using this statement, but the paths are not recursively searched. For loading components in subdirectories of a path directory, use the import statement. In our example, it will look for the myproject directory in the component paths and the ocl directory. All libraries and plugins in these directories will be loaded as well.
After importing, we can create components using loadComponent ([4]). The first argument is the name of the component instance, the second argument is the class type of the component. When these lines are executed, 3 new components have been created: HMI1, Controller1 and Test1.
Finally, the line require("print") loads the printing service globally such that your script can use the 'print.ln("text")' function. See help print in the TaskBrowser after you typed require("print").
Now extend the script to include the lines below. The create connection policy objects and connect ports between components.
// See the Doxygen API documentation of RTT for the fields of this struct: var ConnPolicy cp_1 // set the fields of cp_1 to an application-specific value: cp_1.type = BUFFER // Use ''BUFFER'' or ''DATA'' cp_1.size = 10 // size of the buffer cp_1.lock_policy = LOCKED // Use ''LOCKED'', ''LOCK_FREE'' or ''UNSYNC'' // other fields exist too... // Start connecting ports: connect("HMI1.positions","Controller1.positions", cp_1) cp_1 = ConnPolicy() // reset to defaults (DATA, LOCK_FREE) connect("HMI1.commands","Controller1.commands", cp_1) // etc...
Connecting data ports is done using ConnPolicy structs that describe the properties of the connection to be formed. You may re-use the ConnPolicy variable, or create new ones for each connection you form. The Component Builder's Manual has more details on how the ConnPolicy struct influences how connections are configured.
Finally, we configure and start our components:
if ( HMI1.configure() == false ) print.ln("HMI1 configuration failed!") else { if ( Controller1.configure() == false ) print.ln("Controller1 configuration failed!") else { HMI1.start() Controller1.start() } }
StateMachine SetupShutdown { var bool do_cleanup = false, could_config = false; initial state setup { entry { // Configure components could_config = HMI1.configure() && Controller1.configure(); if (could_config) { HMI1.start(); Controller1.start(); } } transitions { if do_cleanup then select shutdown; if could_config == false then select failure; } } state failure { entry { print.ln("Failed to configure a component!") } } final state shutdown { entry { // Cleanup B group HMI1.stop() ; Controller1.stop(); HMI1.cleanup() ; Controller1.cleanup(); } } } RootMachine SetupShutdown deployApp; deployApp.activate() deployApp.start()
State machines are explained in detail in the Scripting Chapter of the Component Builder's Manual.
Connecting an output port of one component with an input port of another component, where both components are distributed using the CORBA deployer application, deployer-corba.
This is your first XML file for component A. We tell that it runs as a Server and that it registers its name in the Naming Service. (See also Using CORBA and the CORBA transport reference manual for setting up naming services)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "cpf.dtd"> <properties> <struct name="ComponentA" type="HMI"> <simple name="Server" type="boolean"><value>1</value></simple> <simple name="UseNamingService" type="boolean"><value>1</value></simple> </struct> </properties>
Save this in component-a.xml and start it with: deployer-corba -s component-a.xml
This is your second XML file for component B. It has one port, cartesianPosition_desi. We add it to a connection, named cartesianPosition_desi_conn. Next, we declare a 'proxy' to Component A we created above, and we do the same for it's port, add it to the connection named cartesianPosition_desi_conn.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "cpf.dtd"> <properties> <struct name="ComponentB" type="Controller"> <struct name="Ports" type="PropertyBag"> <simple name="cartesianPosition_desi" type="string"> <value>cartesianPosition_desi_conn</value></simple> </struct> </struct> <!-- ComponentA is looked up using the 'CORBA' naming service --> <struct name="ComponentA" type="CORBA"> <!-- We add ports of A to the connection --> <struct name="Ports" type="PropertyBag"> <simple name="cartesianPosition" type="string"> <value>cartesianPosition_desi_conn</value></simple> </struct> </struct> </properties>
Save this file as component-b.xml and start it with deployer-corba -s component-b.xml
When component-b.xml is started, the port connections will be created. When ComponentA exits and re-starts, ComponentB will not notice this, and you'll need to restart the component-b xml file as well. Use a streaming based protocol (ROS, POSIX MQueue) in case you want to be more robust against such situations.
You can also form the connections in a third xml file, and make both components servers like this:
Starting ComponentA:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "cpf.dtd"> <properties> <struct name="ComponentA" type="HMI"> <simple name="Server" type="boolean"><value>1</value></simple> <simple name="UseNamingService" type="boolean"><value>1</value></simple> </struct> </properties>
Save this in component-a.xml and start it with: cdeployer -s component-a.xml
Starting ComponentB:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "cpf.dtd"> <properties> <struct name="ComponentB" type="Controller"> <simple name="Server" type="boolean"><value>1</value></simple> <simple name="UseNamingService" type="boolean"><value>1</value></simple> </struct> </properties>
Save this in component-b.xml and start it with: cdeployer -s component-b.xml
Creating two proxies, and the connection:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "cpf.dtd"> <properties> <!-- ComponentA is looked up using the 'CORBA' naming service --> <struct name="ComponentA" type="CORBA"> <!-- We add ports of A to the connection --> <struct name="Ports" type="PropertyBag"> <simple name="cartesianPosition" type="string"> <value>cartesianPosition_desi_conn</value></simple> </struct> </struct> <!-- ComponentB is looked up using the 'CORBA' naming service --> <struct name="ComponentB" type="CORBA"> <!-- We add ports of B to the connection --> <struct name="Ports" type="PropertyBag"> <simple name="cartesianPosition_desi" type="string"> <value>cartesianPosition_desi_conn</value></simple> </struct> </struct> </properties>
Save this in connect-components.xml and start it with: deployer-corba -s connect-components.xml
See deployer and CORBA related Toolchain Reference Manuals.
These instructions are meant for the Orocos Toolchain version 2.4.0 or later.
mkdir ~/training
export ROS_PACKAGE_PATH=~/training:$ROS_PACKAGE_PATH
sudo apt-get install python-setuptools sudo easy_install -U rosinstall
rosinstall ~/training orocos_exercises.rosinstall /opt/ros/electric
source ~/training/setup.bash
rosdep install youbot_common rosdep install rFSM
rosmake youbot_common rtt_dot_service rttlua_completion
useOrocos(){ source $HOME/training/setup.bash; source $HOME/training/setup.sh; source /opt/ros/electric/stacks/orocos_toolchain/env.sh; setLUA; } setLUA(){ if [ "x$LUA_PATH" == "x" ]; then LUA_PATH=";;"; fi if [ "x$LUA_CPATH" == "x" ]; then LUA_CPATH=";;"; fi export LUA_PATH="$LUA_PATH;`rospack find rFSM`/?.lua" export LUA_PATH="$LUA_PATH;`rospack find ocl`/lua/modules/?.lua" export LUA_PATH="$LUA_PATH;`rospack find rttlua_completion`/?.lua" export LUA_CPATH="$LUA_CPATH;`rospack find rttlua_completion`/?.so" export PATH="$PATH:`rosstack find orocos_toolchain`/install/bin" } useOrocos
roscd hello-1-task-execution make rosrun ocl deployer-gnulinux -s start.ops
var double a a=1.1
var float64[] b(2) b[0]=4.4
find_package(OROCOS-RTT REQUIRED rtt-marshalling) # Defines: ${OROCOS-RTT_RTT-MARSHALLING_LIBRARY} and ${OROCOS-RTT_RTT-MARSHALLING_FOUND}
pre-2.3.2: You may only call find_package(OROCOS-RTT ... ) once. Next calls to this macro will return immediately, so you need to specify all plugins up-front. RTT versions from 2.3.2 on don't have this limitation.
After find_package found the RTT and its plugins, you must explicitly use the created CMake variables in order to have them in effect. This looks typically like:
# Link all targets AFTER THIS LINE with 'rtt-scripting' COMPONENT: if ( OROCOS-RTT_RTT-SCRIPTING_FOUND ) link_libraries( ${OROCOS-RTT_RTT-SCRIPTING_LIBRARY} ) else( OROCOS-RTT_RTT-SCRIPTING_FOUND ) message(SEND_ERROR "'rtt-scripting' not found !") endif( OROCOS-RTT_RTT-SCRIPTING_FOUND ) # now define your components, libraries etc... # ... #Prefered way to link instead of the above method: target_link_libraries( mycomponent ${OROCOS-RTT_RTT-SCRIPTING_LIBRARY})
Or for linking with the standard provided CORBA transport:
# Link all targets AFTER THIS LINE with the CORBA transport (detected by default!) : if ( OROCOS-RTT_CORBA_FOUND ) link_libraries( ${OROCOS-RTT_CORBA_LIBRARIES} ) else( OROCOS-RTT_CORBA_FOUND ) message(SEND_ERROR "'CORBA' transport not found !") endif( OROCOS-RTT_CORBA_FOUND ) # now define your components, libraries etc... # ... #Prefered way to link instead of the above method: target_link_libraries( mycomponent ${OROCOS-RTT_RTT_CORBA_LIBRARIES})
Orocos has a system which lets you specify which packages you want to use for including headers and linking with their libraries. Orocos will always get these flags from a pkg-config .pc file, so in order to use this system, check that the package you want to depend on provides such a .pc file.
If the package or library you want to use has a .pc file, you can directly use this macro:
# The CORBA transport provides a .pc file 'orocos-rtt-corba-<target>.pc': orocos_use_package( orocos-rtt-corba ) # Link with the OCL Deployment component: orocos_use_package( ocl-deployment ) # now define your components, libraries etc...
This macro has a similar effect as putting this dependency in your manifest.xml file, it sets the include paths and links your libraries if OROCOS_NO_AUTO_LINKING is not defined in CMake (the default). Some packages (like OCL) define multiple .pc files, in which case you can put the ocl dependency in the manifest.xml file and use orocos_use_package() to use a specific ocl .pc file.
If the argument to orocos_use_package() is a real package, it is advised to put the dependency in the manifest.xml file, such that the build system can use that information for dependency tracking. In case it is a library as a part of a package (in this case: CORBA is a sub-library of the 'rtt' package), you should put rtt as a dependency in the manifest.xml file, and orocos-rtt-corba with the orocos_use_package macro as shown above.
################################################################################## # # CMake package configuration file for the OROCOS-RTT package. # This script imports targets and sets up the variables needed to use the package. # In case this file is installed in a nonstandard location, its location can be # specified using the OROCOS-RTT_DIR cache # entry. # # find_package COMPONENTS represent OROCOS-RTT plugins such as scripting, # marshalling or corba-transport. # The default search path for them is: # /path/to/OROCOS-RTTinstallation/lib/orocos/plugins # /path/to/OROCOS-RTTinstallation/lib/orocos/types # # For this script to find user-defined OROCOS-RTT plugins, the RTT_COMPONENT_PATH # environment variable should be appropriately set. E.g., if the plugin is located # at /path/to/plugins/libfoo-plugin.so, then add /path/to to RTT_COMPONENT_PATH # # This script sets the following variables: # OROCOS-RTT_FOUND: Boolean that indicates if OROCOS-RTT was found # OROCOS-RTT_INCLUDE_DIRS: Paths to the necessary header files # OROCOS-RTT_LIBRARIES: Libraries to link against to use OROCOS-RTT # OROCOS-RTT_DEFINITIONS: Definitions to use when compiling code that uses OROCOS-RTT # # OROCOS-RTT_PATH: Path of the RTT installation directory (its CMAKE_INSTALL_PREFIX). # OROCOS-RTT_COMPONENT_PATH: The component path of the installation # <prefix>/lib/orocos + RTT_COMPONENT_PATH # OROCOS-RTT_PLUGIN_PATH: OROCOS-RTT_PLUGINS_PATH + OROCOS-RTT_TYPES_PATH # OROCOS-RTT_PLUGINS_PATH: The plugins path of the installation # <prefix>/lib/orocos/plugins + RTT_COMPONENT_PATH * /plugins # OROCOS-RTT_TYPES_PATH: The types path of the installation # <prefix>/lib/orocos/types + RTT_COMPONENT_PATH * /types # # OROCOS-RTT_CORBA_FOUND: Defined if corba transport support is available # OROCOS-RTT_CORBA_LIBRARIES: Libraries to link against to use the corba transport # # OROCOS-RTT_MQUEUE_FOUND: Defined if mqueue transport support is available # OROCOS-RTT_MQUEUE_LIBRARIES: Libraries to link against to use the mqueue transport # # OROCOS-RTT_VERSION: Package version # OROCOS-RTT_VERSION_MAJOR: Package major version # OROCOS-RTT_VERSION_MINOR: Package minor version # OROCOS-RTT_VERSION_PATCH: Package patch version # # OROCOS-RTT_USE_FILE_PATH: Path to package use file, so it can be included like so # include(${OROCOS-RTT_USE_FILE_PATH}/UseOROCOS-RTT.cmake) # OROCOS-RTT_USE_FILE : Allows you to write: include( ${OROCOS-RTT_USE_FILE} ) # # This script additionally sets variables for each requested # find_package COMPONENTS (OROCOS-RTT plugins). # For example, for the ''rtt-scripting'' plugin this would be: # OROCOS-RTT_RTT-SCRIPTING_FOUND: Boolean that indicates if the component was found # OROCOS-RTT_RTT-SCRIPTING_LIBRARY: Libraries to link against to use this component # (Notice singular _LIBRARY suffix !) # # Note for advanced users: Apart from the OROCOS-RTT_*_LIBRARIES variables, # non-COMPONENTS targets can be accessed by their imported name, e.g., # target_link_libraries(bar @IMPORTED_TARGET_PREFIX@orocos-rtt-gnulinux_dynamic). # This of course requires knowing the name of the desired target, which is why using # the OROCOS-RTT_*_LIBRARIES variables is recommended. # # Example usage: # find_package(OROCOS-RTT 2.0.5 EXACT REQUIRED rtt-scripting foo) # # Defines OROCOS-RTT_RTT-SCRIPTING_* # find_package(OROCOS-RTT QUIET COMPONENTS rtt-transport-mqueue foo) # # Defines OROCOS-RTT_RTT-TRANSPORT-MQUEUE_* # ##################################################################################
orocreate-pkg example
You may remove most of the code/statements that you don't use. We only left the most common CMake macros not commented, which tells you which ones you should use most certainly when building a component:
# # The find_package macro for Orocos-RTT works best with # cmake >= 2.6.3 # cmake_minimum_required(VERSION 2.6.3) # # This creates a standard cmake project. You may extend this file with # any cmake macro you see fit. # project(example) # Set the CMAKE_PREFIX_PATH in case you're not using Orocos through ROS # for helping these find commands find RTT. find_package(OROCOS-RTT REQUIRED ${RTT_HINTS}) # Defines the orocos_* cmake macros. See that file for additional # documentation. include(${OROCOS-RTT_USE_FILE_PATH}/UseOROCOS-RTT.cmake) # # Components, types and plugins. # # The CMake 'target' names are identical to the first argument of the # macros below, except for orocos_typegen_headers, where the target is fully # controlled by generated code of 'typegen'. # # Creates a component library libexample-<target>.so # and installs in the directory lib/orocos/example/ # orocos_component(example example-component.hpp example-component.cpp) # ...you may add multiple source files # # You may add multiple orocos_component statements. # # Building a typekit (recommended): # # Creates a typekit library libexample-types-<target>.so # and installs in the directory lib/orocos/example/types/ # #orocos_typegen_headers(example-types.hpp) # ...you may add multiple header files # # You may only have *ONE* orocos_typegen_headers statement ! # # Building a normal library (optional): # # Creates a library libsupport-<target>.so and installs it in # lib/ # #orocos_library(support support.cpp) # ...you may add multiple source files # # You may add multiple orocos_library statements. # # Building a Plugin or Service (optional): # # Creates a plugin library libexample-service-<target>.so or libexample-plugin-<target>.so # and installs in the directory lib/orocos/example/plugins/ # # Be aware that a plugin may only have the loadRTTPlugin() function once defined in a .cpp file. # This function is defined by the plugin and service CPP macros. # #orocos_service(example-service example-service.cpp) # ...only one service per library ! #orocos_plugin(example-plugin example-plugin.cpp) # ...only one plugin function per library ! # # You may add multiple orocos_plugin/orocos_service statements. # # Additional headers (not in typekit): # # Installs in the include/orocos/example/ directory # orocos_install_headers( example-component.hpp ) # ...you may add multiple header files # # You may add multiple orocos_install_headers statements. # # Generates and installs our package. Must be the last statement such # that it can pick up all above settings. # orocos_generate_package()