Using the geometric relations semantics in your own application

Here we will explain how you can use the geometric relations semantics in your application, in particular using the Orocos Kinematics and Dynamics library as a geometry library, supplemented with the semantic support.

Preparing your own application using the ROS-build system

  • Create a new ROS package (in this case with name myApplication), with a dependency on the geometric_semantics_kdl:

roscreate-pkg myApplication geometric_semantics_kdl

This will automatically create a directory with name myApplication and a basic build infrastructure (see the roscreate-pkg documentation)

  • Add the newly created directory to your ROS_PACKAGE_PATH environment variable:

cd myApplication
export ROS_PACKAGE_PATH=$PWD:$ROS_PACKAGE_PATH

Writing your own application

  • Go to the application directory:

roscd myApplication

  • Create a main C++ file

touch myApplication.cpp

  • Edit the C++ file with your favorite editor
    • Include the necessary headers. For instance:

#include <Pose/Pose.h>
#include <Pose/PoseCoordinatesKDL.h>

    • It can be convenient to use the geometric_semantics namespace and for instance the one of your geometry library (in this case KDL):

using namespace geometric_semantics;                                                                                                                                                                                                    using namespace KDL;

    • In your main you should create the necessary geometric relations. For instance for a pose, first create the KDL coordinates:

Rotation coordinatesRotB2_B1=Rotation::EulerZYX(M_PI,0,0);
Vector coordinatesPosB2_B1(2.2,0,0);
KDL::Frame coordinatesFrameB2_B1(coordinatesRotB2_B1,coordinatesPosB2_B1)

Then use this KDL coordinates to create a PoseCoordinates object:

PoseCoordinates<KDL::Frame> poseCoordB2_B1(coordinatesFrameB2_B1);

Then create a Pose object using both the semantic information and the PoseCoordinates:

Pose<KDL::Frame> poseB2_B1("b2","b2","B2","b1","b1","B1","b1",poseCoordB2_B1);

    • Now you are ready to do actual calculations using semantic checking. For instance to take the inverse:

Pose<KDL::Frame> poseB1_B2 = poseB2_B1.inverse()

Building your own application

  • To build you application you should edit the CMakeLists.txt file created in you application directory. Add the your C++ main file to be build as an executable adding the following line:

rosbuild_add_executable(myApplication myApplication.cpp)

  • Now you are ready to build, so type

rosmake myApplication

and the executable will be created in the bin directory.

  • To run the executable do:

bin/myApplication

You will get the semantic output on your screen.