Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions .github/workflows/industrial-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ jobs:
strategy:
matrix:
env:
- ROS_DISTRO: kinetic
ROS_REPO: main
IMMEDIATE_TEST_OUTPUT: true
- ROS_DISTRO: melodic
ROS_REPO: main
IMMEDIATE_TEST_OUTPUT: true
Expand Down
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()

find_package(Boost REQUIRED)


##
## Check C++11 support / enable global pedantic and Wall
##
include(DefineCXX11CompilerFlag)
DEFINE_CXX_11_COMPILER_FLAG(CXX11_FLAG)
include(DefineCXX17CompilerFlag)
DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")

add_library(urcl SHARED
Expand Down Expand Up @@ -44,11 +42,10 @@ add_library(urcl SHARED
)
add_library(ur_client_library::urcl ALIAS urcl)
target_compile_options(urcl PRIVATE -Wall -Wextra -Wno-unused-parameter)
target_compile_options(urcl PUBLIC ${CXX11_FLAG})
target_compile_options(urcl PUBLIC ${CXX17_FLAG})
target_include_directories( urcl PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${Boost_INCLUDE_DIRS}
)

find_package(Threads REQUIRED)
Expand Down Expand Up @@ -82,8 +79,6 @@ else()
endif()


target_link_libraries(urcl INTERFACE ${Boost_Libraries})

add_subdirectory(examples)

include(GNUInstallDirs)
Expand Down
10 changes: 5 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ project(ur_driver_examples)
##
## Check C++11 support / enable global pedantic and Wall
##
include(DefineCXX11CompilerFlag)
DEFINE_CXX_11_COMPILER_FLAG(CXX11_FLAG)
include(DefineCXX17CompilerFlag)
DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")

add_executable(driver_example
full_driver.cpp)
target_compile_options(driver_example PUBLIC ${CXX11_FLAG})
target_compile_options(driver_example PUBLIC ${CXX17_FLAG})
target_link_libraries(driver_example ur_client_library::urcl)

add_executable(primary_pipeline_example
primary_pipeline.cpp)
target_compile_options(primary_pipeline_example PUBLIC ${CXX11_FLAG})
target_compile_options(primary_pipeline_example PUBLIC ${CXX17_FLAG})
target_link_libraries(primary_pipeline_example ur_client_library::urcl)

add_executable(rtde_client_example
rtde_client.cpp)
target_compile_options(rtde_client_example PUBLIC ${CXX11_FLAG})
target_compile_options(rtde_client_example PUBLIC ${CXX17_FLAG})
target_link_libraries(rtde_client_example ur_client_library::urcl)
47 changes: 5 additions & 42 deletions include/ur_client_library/rtde/data_package.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
#define UR_CLIENT_LIBRARY_DATA_PACKAGE_H_INCLUDED

#include <unordered_map>
#include <variant>
#include <vector>

#include "ur_client_library/types.h"
#include "ur_client_library/rtde/rtde_package.h"
#include <boost/variant.hpp>

namespace urcl
{
Expand All @@ -59,8 +59,8 @@ enum class RUNTIME_STATE : uint32_t
class DataPackage : public RTDEPackage
{
public:
using _rtde_type_variant = boost::variant<bool, uint8_t, uint32_t, uint64_t, int32_t, double, vector3d_t, vector6d_t,
vector6int32_t, vector6uint32_t, std::string>;
using _rtde_type_variant = std::variant<bool, uint8_t, uint32_t, uint64_t, int32_t, double, vector3d_t, vector6d_t,
vector6int32_t, vector6uint32_t, std::string>;

DataPackage() = delete;

Expand Down Expand Up @@ -116,7 +116,6 @@ class DataPackage : public RTDEPackage
*
* \param name The string identifier for the data field as used in the documentation.
* \param val Target variable. Make sure, it's the correct type.
* \exception boost::bad_get if the type under given \p name does not match the template type T.
*
* \returns True on success, false if the field cannot be found inside the package.
*/
Expand All @@ -125,7 +124,7 @@ class DataPackage : public RTDEPackage
{
if (data_.find(name) != data_.end())
{
val = boost::strict_get<T>(data_[name]);
val = std::get<T>(data_[name]);
}
else
{
Expand All @@ -141,7 +140,6 @@ class DataPackage : public RTDEPackage
*
* \param name The string identifier for the data field as used in the documentation.
* \param val Target variable. Make sure, it's the correct type.
* \exception boost::bad_get if the type under given \p name does not match the template type T.
*
* \returns True on success, false if the field cannot be found inside the package.
*/
Expand All @@ -152,7 +150,7 @@ class DataPackage : public RTDEPackage

if (data_.find(name) != data_.end())
{
val = std::bitset<N>(boost::strict_get<T>(data_[name]));
val = std::bitset<N>(std::get<T>(data_[name]));
}
else
{
Expand Down Expand Up @@ -201,41 +199,6 @@ class DataPackage : public RTDEPackage
uint8_t recipe_id_;
std::unordered_map<std::string, _rtde_type_variant> data_;
std::vector<std::string> recipe_;

struct ParseVisitor : public boost::static_visitor<>
{
template <typename T>
void operator()(T& d, comm::BinParser& bp) const
{
bp.parse(d);
}
};
struct StringVisitor : public boost::static_visitor<std::string>
{
template <typename T>
std::string operator()(T& d) const
{
std::stringstream ss;
ss << d;
return ss.str();
}
};
struct SizeVisitor : public boost::static_visitor<uint16_t>
{
template <typename T>
uint16_t operator()(T& d) const
{
return sizeof(d);
}
};
struct SerializeVisitor : public boost::static_visitor<size_t>
{
template <typename T>
size_t operator()(T& d, uint8_t* buffer) const
{
return comm::PackageSerializer::serialize(buffer, d);
}
};
};

} // namespace rtde_interface
Expand Down
1 change: 0 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

<buildtool_depend>cmake</buildtool_depend>

<build_depend>boost</build_depend>
<depend>libconsole-bridge-dev</depend>

<export>
Expand Down
13 changes: 7 additions & 6 deletions src/rtde/data_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,7 @@ bool rtde_interface::DataPackage::parseWith(comm::BinParser& bp)
if (g_type_list.find(item) != g_type_list.end())
{
_rtde_type_variant entry = g_type_list[item];
auto bound_visitor = std::bind(ParseVisitor(), std::placeholders::_1, bp);
boost::apply_visitor(bound_visitor, entry);
std::visit([&bp](auto&& arg) { bp.parse(arg); }, entry);
data_[item] = entry;
}
else
Expand All @@ -592,7 +591,8 @@ std::string rtde_interface::DataPackage::toString() const
for (auto& item : data_)
{
ss << item.first << ": ";
ss << boost::apply_visitor(StringVisitor{}, item.second) << std::endl;
std::visit([&ss](auto&& arg) { ss << arg; }, item.second);
ss << std::endl;
}
return ss.str();
}
Expand All @@ -603,15 +603,16 @@ size_t rtde_interface::DataPackage::serializePackage(uint8_t* buffer)

for (auto& item : data_)
{
payload_size += boost::apply_visitor(SizeVisitor{}, item.second);
payload_size += std::visit([](auto&& arg) -> uint16_t { return sizeof(arg); }, item.second);
}
size_t size = 0;
size += PackageHeader::serializeHeader(buffer, PackageType::RTDE_DATA_PACKAGE, payload_size);
size += comm::PackageSerializer::serialize(buffer + size, recipe_id_);
for (auto& item : recipe_)
{
auto bound_visitor = std::bind(SerializeVisitor(), std::placeholders::_1, buffer + size);
size += boost::apply_visitor(bound_visitor, data_[item]);
size += std::visit(
[&buffer, &size](auto&& arg) -> size_t { return comm::PackageSerializer::serialize(buffer + size, arg); },
data_[item]);
}

return size;
Expand Down
17 changes: 12 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ if (NOT TARGET ur_client_library::urcl)
endif()

# Check C++11 support
include(DefineCXX11CompilerFlag)
DEFINE_CXX_11_COMPILER_FLAG(CXX11_FLAG)
include(DefineCXX17CompilerFlag)
DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG)


# Build Tests
if (INTEGRATION_TESTS)
# Integration tests require a robot reachable at 192.168.56.101. Therefore, they have to be
# activated separately.
add_executable(rtde_tests test_rtde_client.cpp)
target_compile_options(rtde_tests PRIVATE ${CXX11_FLAG})
target_compile_options(rtde_tests PRIVATE ${CXX17_FLAG})
target_include_directories(rtde_tests PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(rtde_tests PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
gtest_add_tests(TARGET rtde_tests
Expand All @@ -42,14 +42,21 @@ else()
endif()

add_executable(primary_parser_tests test_primary_parser.cpp)
target_compile_options(primary_parser_tests PRIVATE ${CXX11_FLAG})
target_compile_options(primary_parser_tests PRIVATE ${CXX17_FLAG})
target_include_directories(primary_parser_tests PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(primary_parser_tests PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
gtest_add_tests(TARGET primary_parser_tests
)

add_executable(rtde_data_package test_rtde_data_package.cpp)
target_compile_options(rtde_data_package PRIVATE ${CXX17_FLAG})
target_include_directories(rtde_data_package PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(rtde_data_package PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
gtest_add_tests(TARGET rtde_data_package
)

add_executable(rtde_parser_tests test_rtde_parser.cpp)
target_compile_options(rtde_parser_tests PRIVATE ${CXX11_FLAG})
target_compile_options(rtde_parser_tests PRIVATE ${CXX17_FLAG})
target_include_directories(rtde_parser_tests PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(rtde_parser_tests PRIVATE ur_client_library::urcl ${GTEST_LIBRARIES})
gtest_add_tests(TARGET rtde_parser_tests
Expand Down
63 changes: 63 additions & 0 deletions tests/test_rtde_data_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-

// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2020 FZI Forschungszentrum Informatik
//
// 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.
// -- END LICENSE BLOCK ------------------------------------------------

//----------------------------------------------------------------------
/*!\file
*
* \author Felix Exner mauch@fzi.de
* \date 2020-09-11
*
*/
//----------------------------------------------------------------------

#include <gtest/gtest.h>

#include <ur_client_library/rtde/data_package.h>

using namespace urcl;

TEST(rtde_data_package, serialize_pkg)
{
std::vector<std::string> recipe{ "speed_slider_mask" };
rtde_interface::DataPackage package(recipe);
package.initEmpty();

uint32_t value = 1;
package.setData("speed_slider_mask", value);

uint8_t buffer[4096];
package.setRecipeID(1);
size_t size = package.serializePackage(buffer);

EXPECT_EQ(size, 8);

uint8_t expected[] = { 0x0, 0x08, 0x55, 0x01, 0x00, 0x00, 0x00, 0x01 };
std::cout << "Serialized buffer: " << std::endl;
for (size_t i = 0; i < size; ++i)
{
EXPECT_EQ(buffer[i], expected[i]);
}
std::cout << std::endl;
}

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}