Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new package rtt_ros2_tf2 support for ROS2 TF2 #19

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
252ea30
rtt_ros2_tf2: create the skeleton of new package rtt_ros2_tf2
spd-intermodalics Jul 15, 2020
fdc20c1
rtt_ros2_tf2: implement basic functionality
spd-intermodalics Jul 16, 2020
10a39ce
rtt_ros2_tf2: add more functionality
spd-intermodalics Jul 17, 2020
43d26e5
rtt_ros2_tf2: refactor to use composition instead of inheritance
spd-intermodalics Jul 17, 2020
0febc6b
rtt_ros2_tf2: add the service as an Orocos plugin
spd-intermodalics Jul 17, 2020
7cb3c9a
rtt_ros2_tf2: use tf2_ros::TransformBroadcaster and other tf2_ros
spd-intermodalics Jul 20, 2020
604a24e
rtt_ros2_tf2 comply with linting and other sanity checks
spd-intermodalics Jul 20, 2020
4947a72
rtt_ros2_tf2: adapt travis to include rtt_ros2_integration
spd-intermodalics Jul 20, 2020
351316f
rtt_ros2_tf2: test tarvis with rtt_ros2_common_interfaces
spd-intermodalics Jul 20, 2020
32ca0a5
rtt_ros2_tf2: remove internal dependency on typekit
spd-intermodalics Jul 20, 2020
8988130
rtt_ros2_tf2: link target agains typekits specifically
spd-intermodalics Jul 20, 2020
6032213
rtt_ros2_tf2: fix eloquent dashing dependencies
spd-intermodalics Jul 22, 2020
d5e87aa
rtt_ros2_tf2: rename main class to Tf2Service
spd-intermodalics Jul 22, 2020
ad77c00
rtt_ros2_tf2: add unitest in rtt_ros2_tf2_tests
spd-intermodalics Jul 22, 2020
4a29fc6
rtt_ros2_tf2_tests: remove rtt_ros2_geometry_msgs dependency
spd-intermodalics Jul 22, 2020
3d0d6ee
rtt_ros2_tf2: add documentation
spd-intermodalics Jul 24, 2020
ded7b4b
Merge branch 'master' into feature/add-rtt_tf2
meyerj Jul 28, 2020
a3da067
rtt_ros2_tf2: fix ament_export_include_directories() and use new macr…
meyerj Jul 28, 2020
b89d2e9
rtt_ros2_tf2_tests: match CMakeLists.txt with other unit test package…
meyerj Jul 28, 2020
f41ca47
rtt_ros2_tf2: cleanup CMakeLists.txt and dependencies in package.xml,…
meyerj Jul 28, 2020
b94ffcd
rtt_ros2_tf2_tests: fix loading of renamed service rosnode in test_ro…
meyerj Jul 28, 2020
30adf61
rtt_ros2_tf2_tests: remove import of package rtt_ros2_geometry_msgs
meyerj Jul 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions rtt_ros2_tf2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
cmake_minimum_required(VERSION 3.5)
project(rtt_ros2_tf2)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rtt_ros2 REQUIRED)
find_package(rtt_ros2_node REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_msgs REQUIRED)
find_package(tf2_ros REQUIRED)

# setup targets
include_directories(include/orocos)

# Target: library
# message(AUTHOR_WARNING "The tf2 includes are in: ${tf2_INCLUDE_DIRS}")
# message(AUTHOR_WARNING "The rclcpp includes are in: ${rclcpp_INCLUDE_DIRS}")
# message(AUTHOR_WARNING "The tf2_msgs includes are in: ${tf2_msgs_INCLUDE_DIRS}")
orocos_library(rtt_ros2_tf2
src/rtt_ros2_tf2.cpp
EXPORT ${PROJECT_NAME}
INCLUDES DESTINATION include/orocos/${PROJECT_NAME}
)
# target_link_libraries(rtt_ros2_tf2 tf2)
# target_include_directories(rtt_ros2_tf2 tf2)
ament_target_dependencies(rtt_ros2_tf2
geometry_msgs
rclcpp
rtt_ros2
rtt_ros2_node
tf2
tf2_msgs
tf2_ros
)
target_link_libraries(rtt_ros2_tf2
rtt_ros2_node::rtt_ros2_node
)

# Target: orocos plugin
orocos_plugin(rtt_ros2_tf2_service
src/rtt_ros2_tf2_service.cpp
)
target_link_libraries(rtt_ros2_tf2_service rtt_ros2_tf2)

# Target: orocos component
orocos_component(rtt_ros2_tf2_component
src/rtt_ros2_tf2_component.cpp
)
target_link_libraries(rtt_ros2_tf2_component rtt_ros2_tf2)

# install
install(
DIRECTORY include/
DESTINATION include
)

# linters
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

# export information to downstream packages
# ament_export_dependencies(rtt_ros2)
ament_export_dependencies(
geometry_msgs
rclcpp
tf2_msgs
tf2_ros
tf2
)
ament_export_include_directories(include/orocos)
if(COMMAND ament_export_targets)
ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET)
else()
ament_export_interfaces(${PROJECT_NAME} HAS_LIBRARY_TARGET)
endif()
rtt_ros2_export_plugin_depend(rtt_ros2_node)

# orocos_generate_package(
# INCLUDE_DIRS include
# DEPENDS tf2
# DEPENDS_TARGETS rtt_geometry_msgs rtt_tf2_msgs
# )

# Legacy from rtt_tf
# Tests
# if(CATKIN_ENABLE_TESTING)
# orocos_use_package(ocl-taskbrowser REQUIRED)
# orocos_use_package(ocl-deployment REQUIRED)

# add_definitions(-DRTT_COMPONENT)
# orocos_executable(broadcaster_test tests/broadcaster_test.cpp)
# target_link_libraries(broadcaster_test ${catkin_LIBRARIES} ${USE_OROCOS_LIBRARIES})
# orocos_executable(lookup_test tests/lookup_test.cpp)
# target_link_libraries(lookup_test ${catkin_LIBRARIES} ${USE_OROCOS_LIBRARIES})
# endif()

# must be called *after* the targets to check exported libraries etc.
ament_package()

# orocos_generate_package() is deprecated for ROS 2.
# Prefer cmake target export and import instead, in combination with
# ament_export_interfaces() or ament_export_targets() when building with
# ament_cmake.
orocos_generate_package()
49 changes: 49 additions & 0 deletions rtt_ros2_tf2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
RTT ROS2 TF2
============

This package provides an Orocos RTT service for utilizing the [TF2 rigid body
transform library](https://index.ros.org/doc/ros2/Tutorials/tf2) from within
Orocos.
This service has operations for requesting and broadcasting sing and
batch transforms.

## Service description

The service provided by the library exposes some operations to interact with TF.
The operations available are:
* `sendTransform()`:
* `sendTransforms()`:
* `sendStaticTransform()`:
* `sendStaticTransforms()`:
* `lookupTransform()`:
* `clear()`:


### Usage

#### Scripting API (*.ops)

The package can be loaded independently form other related `ros` packages, but it requires the `rosnode` service
to work.

The service can be loaded globally by importing the package:

```
import("rtt_ros2")
ros.import("rtt_ros2_tf2")
```
This will create a global service under the `ros` namespace. The operations run by this
service will be executed in the `ClientThread` and are NOT real-time safe.

To load the service into a component, after importing the package, it can be loaded with:

```
loadService("<component-name>", "tf2")
```

The component version will run the calls in the `OwnThread`. The component should not be
real time.

### C++ API

*ToDo*
124 changes: 124 additions & 0 deletions rtt_ros2_tf2/include/orocos/rtt_ros2_tf2/rtt_ros2_tf2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright 2020 Intermodalics BVBA
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef OROCOS__RTT_ROS2_TF2__RTT_ROS2_TF2_HPP_
#define OROCOS__RTT_ROS2_TF2__RTT_ROS2_TF2_HPP_

#include <map>
#include <string>
#include <vector>

#include "geometry_msgs/msg/transform_stamped.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp/time.hpp"
#include "rtt/InputPort.hpp"
#include "rtt/Service.hpp"
#include "tf2_msgs/msg/tf_message.hpp"
#include "tf2_ros/static_transform_broadcaster.h"
#include "tf2_ros/transform_broadcaster.h"
#include "tf2_ros/transform_listener.h"
#include "tf2/buffer_core.h"

namespace rtt_ros2_tf2
{

class Tf2Service : public RTT::Service
{
public:
typedef boost::shared_ptr<Tf2Service> shared_ptr;

explicit Tf2Service(RTT::TaskContext * owner);
virtual ~Tf2Service();

protected:
///! Operations
// rclcpp::Time getLatestCommonTime(
// const std::string & target,
// const std::string & source) const;

bool canTransform(
const std::string & target,
const std::string & source) const;

geometry_msgs::msg::TransformStamped lookupTransform(
const std::string & target,
const std::string & source) const;

// geometry_msgs::msg::TransformStamped lookupTransformAtTime(
// const std::string & target,
// const std::string & source,
// const rclcpp::Time& common_time) const;

void broadcastTransform(
const geometry_msgs::msg::TransformStamped & transform);

void broadcastTransforms(
const std::vector<geometry_msgs::msg::TransformStamped> & transforms);

void broadcastStaticTransform(
const geometry_msgs::msg::TransformStamped & transform);

void broadcastStaticTransforms(
const std::vector<geometry_msgs::msg::TransformStamped> & transforms);

void clear();

void addTf2Interface(RTT::Service::shared_ptr service);

protected:
///! Communication ports
// Input ports
RTT::InputPort<geometry_msgs::msg::TransformStamped> ip_stamped_transform_;
RTT::InputPort<geometry_msgs::msg::TransformStamped> ip_stamped_transform_static_;
// RTT::InputPort<tf2_msgs::msg::TFMessage> ip_tf_port_;

private:
// Constant
static constexpr int kDefaultBufferSize = 100;

// Clock
rclcpp::Node::SharedPtr rosnode;
boost::shared_ptr<rclcpp::Clock> clock_;
boost::shared_ptr<tf2::BufferCore> buffer_core_;
// boost::shared_ptr<tf2_ros::BufferClient> buffer_client_;
boost::shared_ptr<tf2_ros::TransformBroadcaster> transform_broadcaster_;
boost::shared_ptr<tf2_ros::TransformListener> transform_listener_;
boost::shared_ptr<tf2_ros::StaticTransformBroadcaster>
static_transform_broadcaster_;

// Example members

int private_int_ = 42;
// tf2::BufferCore buffer_core_;

// Deprecated?
std::string prop_tf_prefix_;
double prop_cache_time_;
double prop_buffer_size_;

private:
// void internalUpdate(
// tf2_msgs::TFMessage & msg,
// RTT::InputPort<tf2_msgs::TFMessage> & port,
// bool is_static);
tf2_msgs::msg::TFMessage tf_msgs_;
void stamped_message_callback(RTT::base::PortInterface * port);
void stamped_message_static_callback(RTT::base::PortInterface * port);

bool rosReady();
}; // class Tf2Service

} // namespace rtt_ros2_tf2

#endif // OROCOS__RTT_ROS2_TF2__RTT_ROS2_TF2_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2020 Intermodalics BVBA
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef OROCOS__RTT_ROS2_TF2__RTT_ROS2_TF2_COMPONENT_HPP_
#define OROCOS__RTT_ROS2_TF2__RTT_ROS2_TF2_COMPONENT_HPP_

#include <string>

#include "rtt/RTT.hpp"
// #include "tf2_msgs/TFMessage.h"
// #include "tf2/buffer_core.h"

namespace rtt_ros2_tf2
{
// Inherit from TaskContext
class TF2_Component : public RTT::TaskContext
{
public:
explicit TF2_Component(std::string const & name);

bool configureHook();

void updateHook();

void cleanupHook();
};

} // namespace rtt_ros2_tf2

#endif // OROCOS__RTT_ROS2_TF2__RTT_ROS2_TF2_COMPONENT_HPP_
29 changes: 29 additions & 0 deletions rtt_ros2_tf2/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rtt_ros2_tf2</name>
<version>0.0.0</version>
<description>
This package provides an interface to use TF2 in Orocos context.
</description>
<maintainer email="[email protected]">Orocos Developers</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>geometry_msgs</depend>
<depend>rclcpp</depend>
<depend>rtt_ros2_node</depend>
<depend>rtt_ros2</depend>
<depend>tf2_msgs</depend>
<depend>tf2_ros</depend>
<depend>tf2</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>

Loading