Commit edd467b4 authored by Bock's avatar Bock

Initial commit

parents
Pipeline #33 failed with stages
cmake_minimum_required(VERSION 2.8.3)
project(crs)
set(CMAKE_BUILD_MODE Release)
####################################### General #######################################
# disable ANY optimization in debug mode
IF(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Werror=return-type -fuse-ld=gold -lfreetype -lharfbuzz")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
# enforce c++ 17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
####################################### ROS & Catkin #######################################
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
visualization_msgs
sensor_msgs
message_generation
pcl_ros
cv_bridge
)
add_message_files(
FILES
ER1ControlMsg.msg
)
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES comon er1driver
CATKIN_DEPENDS roscpp std_msgs message_runtime
)
include_directories(
${CMAKE_CURRENT_LIST_DIR}/include
${catkin_INCLUDE_DIRS}
)
####################################### Boost #######################################
FIND_PACKAGE(Boost REQUIRED filesystem thread system graph)
include_directories(${Boost_INCLUDE_DIRS})
####################################### CGAL #######################################
find_package(CGAL REQUIRED COMPONENTS CORE )
include(${CGAL_USE_FILE})
####################################### PCL #######################################
find_package(PCL REQUIRED COMPONENTS common io)
include_directories({PCL_INCLUDE_DIRS})
####################################### OpenCV #######################################
find_package(OpenCV REQUIRED)
include_directories({OpenCV_INCLUDE_DIRS})
####################################### TBB #######################################
find_package(TBB REQUIRED)
include_directories(${TBB_INCLUDE_DIR})
####################################### SDL2 #######################################
# TODO: use a proper find cmake package file
set(SDL2_LIBRARY /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so)
set(SDL2_INCLUDE_DIR /usr/include/})
include_directories(${SDL2_INCLUDE_DIR})
####################################### Comon #######################################
set(comon_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/comon/)
file(GLOB_RECURSE comon_HEADERS ${comon_INCLUDE_DIR}/*.h*)
# the libraries "scopeguard", "better_enum" and "threadpool" are embedded directly into comon
set(scopeguard_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/scopeguard/)
file(GLOB_RECURSE scopeguard_HEADERS ${comon_INCLUDE_DIR}/*.h*)
set(threadpool_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/threadpool/)
file(GLOB_RECURSE threadpool_HEADERS ${threadpool_INCLUDE_DIR}/*.h*)
set(better_enum_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/better_enum/)
file(GLOB_RECURSE better_enum_HEADERS ${better_enum_INCLUDE_DIR}/*.h*)
set(comon_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/comon/)
file(GLOB comon_SOURCES ${comon_SOURCE_DIR}/*.c*)
add_library(comon ${comon_SOURCES} ${comon_HEADERS} ${threadpool_HEADERS} ${scopeguard_HEADERS} ${better_enum_HEADERS})
target_link_libraries(comon ${TBB_LIBRARIES})
add_dependencies(comon crs_generate_messages_cpp)
####################################### er1driver #######################################
set(er1driver_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/er1driver/)
file(GLOB er1driver_HEADERS ${er1driver_INCLUDE_DIR}/*.h*)
set(er1driver_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/er1driver/)
file(GLOB er1driver_SOURCES ${er1driver_SOURCE_DIR}/*.c*)
add_library(er1driver ${er1driver_SOURCES} ${er1driver_HEADERS})
add_dependencies(er1driver comon)
target_link_libraries(er1driver comon)
####################################### er1_driver_node #######################################
set(er1_driver_node_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/er1_driver_node/)
file(GLOB er1_driver_node_HEADERS ${er1_driver_node_INCLUDE_DIR}/*.h*)
set(er1_driver_node_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/er1_driver_node/)
file(GLOB er1_driver_node_SOURCES ${er1_driver_node_SOURCE_DIR}/*.c*)
add_executable(er1_driver_node ${er1_driver_node_SOURCES} ${er1_driver_node_HEADERS})
add_dependencies(er1_driver_node comon er1driver)
target_link_libraries(er1_driver_node comon er1driver ${catkin_LIBRARIES})
####################################### er1_control_node #######################################
set(er1_control_node_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/er1_control_node/)
file(GLOB er1_control_node_HEADERS ${er1_control_node_INCLUDE_DIR}/*.h*)
set(er1_control_node_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/er1_control_node/)
file(GLOB er1_control_node_SOURCES ${er1_control_node_SOURCE_DIR}/*.c*)
add_executable(er1_control_node ${er1_control_node_SOURCES} ${er1_control_node_HEADERS})
add_dependencies(er1_control_node er1driver)
target_link_libraries(er1_control_node er1driver ${SDL2_LIBRARY} ${catkin_LIBRARIES})
####################################### student_image_node #######################################
set(student_image_node_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/student_image_node/)
file(GLOB student_image_node_HEADERS ${student_image_node_INCLUDE_DIR}/*.h*)
set(student_image_node_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/student_image_node/)
file(GLOB student_image_node_SOURCES ${student_image_node_SOURCE_DIR}/*.c*)
add_executable(student_image_node ${student_image_node_SOURCES} ${student_image_node_HEADERS})
add_dependencies(student_image_node er1driver)
target_link_libraries(student_image_node
comon
${Boost_LIBRARIES}
${PCL_COMMON_LIBRARIES}
${OpenCV_LIBS}
)
####################################### student_pointcloud_node #######################################
set(student_pointcloud_node_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/student_pointcloud_node/)
file(GLOB student_pointcloud_node_HEADERS ${student_pointcloud_node_INCLUDE_DIR}/*.h*)
set(student_pointcloud_node_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/student_pointcloud_node/)
file(GLOB student_pointcloud_node_SOURCES ${student_pointcloud_node_SOURCE_DIR}/*.c*)
add_executable(student_pointcloud_node ${student_pointcloud_node_SOURCES} ${student_pointcloud_node_HEADERS})
target_link_libraries(student_pointcloud_node ${catkin_LIBRARIES}
comon
${Boost_LIBRARIES}
${PCL_COMMON_LIBRARIES}
${OpenCV_LIBS}
)
####################################### student_fun_node_a #######################################
set(student_fun_node_a_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/student_fun_node_a/)
file(GLOB student_fun_node_a_HEADERS ${student_fun_node_a_INCLUDE_DIR}/*.h*)
set(student_fun_node_a_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/student_fun_node_a/)
file(GLOB student_fun_node_a_SOURCES ${student_fun_node_a_SOURCE_DIR}/*.c*)
add_executable(student_fun_node_a ${student_fun_node_a_SOURCES} ${student_fun_node_a_HEADERS})
target_link_libraries(student_fun_node_a ${catkin_LIBRARIES}
comon
${Boost_LIBRARIES}
${PCL_COMMON_LIBRARIES}
${OpenCV_LIBS}
)
####################################### student_fun_node_b #######################################
set(student_fun_node_b_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/student_fun_node_b/)
file(GLOB student_fun_node_b_HEADERS ${student_fun_node_b_INCLUDE_DIR}/*.h*)
set(student_fun_node_b_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/student_fun_node_b/)
file(GLOB student_fun_node_b_SOURCES ${student_fun_node_b_SOURCE_DIR}/*.c*)
add_executable(student_fun_node_b ${student_fun_node_b_SOURCES} ${student_fun_node_b_HEADERS})
add_dependencies(student_fun_node_b er1driver)
target_link_libraries(student_fun_node_b ${catkin_LIBRARIES}
comon
${Boost_LIBRARIES}
${PCL_COMMON_LIBRARIES}
${OpenCV_LIBS}
)
Better Enums is distributed under the terms of the 2-clause BSD license. Its
text is given below.
Copyright (c) 2012-2016, Anton Bachin
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Better Enums uses the mistune library as part of its documentation generator.
Its web address and license are given below.
http://mistune.readthedocs.org/en/latest/
Copyright (c) 2014 - 2015, Hsiaoming Yang
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the creator nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This diff is collapsed.
#pragma once
#include <comon/stringify.hpp>
#ifdef ROS_ERROR
#define CO_ASSERT(pred) { bool result = pred; if (!(result)) { auto msg = co::stringify("Assertion failed: ", #pred, "\n File: ", __FILE__, "\n Line: ", __LINE__, "\n Function: ", __FUNCTION__); ROS_ERROR("%s", msg.c_str()); std::abort(); }}
#else
#define CO_ASSERT(pred) { bool result = pred; if (!(result)) { auto msg = co::stringify("Assertion failed: ", #pred, "\n File: ", __FILE__, "\n Line: ", __LINE__, "\n Function: ", __FUNCTION__); std::cout << msg.c_str() << std::endl; std::abort(); }}
#endif
#pragma once
// (C) Copyright 2015 Just Software Solutions Ltd
//
// Distributed under the Boost Software License, Version 1.0.
//
// Boost Software License - Version 1.0 - August 17th, 2003
//
// Permission is hereby granted, free of charge, to any person or
// organization obtaining a copy of the software and accompanying
// documentation covered by this license (the "Software") to use,
// reproduce, display, distribute, execute, and transmit the
// Software, and to prepare derivative works of the Software, and
// to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire
// statement, including the above license grant, this restriction
// and the following disclaimer, must be included in all copies
// of the Software, in whole or in part, and all derivative works
// of the Software, unless such copies or derivative works are
// solely in the form of machine-executable object code generated
// by a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE
// LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include<type_traits>
template<typename E>
struct enable_bitmask_operators {
static const bool enable = false;
};
template<typename E>
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type
operator|(E lhs, E rhs) {
typedef typename std::underlying_type<E>::type underlying;
return static_cast<E>(
static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
}
template<typename E>
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type
operator&(E lhs, E rhs) {
typedef typename std::underlying_type<E>::type underlying;
return static_cast<E>(
static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
}
template<typename E>
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type
operator^(E lhs, E rhs) {
typedef typename std::underlying_type<E>::type underlying;
return static_cast<E>(
static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs));
}
template<typename E>
typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type
operator~(E lhs) {
typedef typename std::underlying_type<E>::type underlying;
return static_cast<E>(
~static_cast<underlying>(lhs));
}
template<typename E>
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type
operator|=(E &lhs, E rhs) {
typedef typename std::underlying_type<E>::type underlying;
lhs = static_cast<E>(
static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
return lhs;
}
template<typename E>
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type
operator&=(E &lhs, E rhs) {
typedef typename std::underlying_type<E>::type underlying;
lhs = static_cast<E>(
static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
return lhs;
}
template<typename E>
typename std::enable_if<enable_bitmask_operators<E>::enable, E &>::type
operator^=(E &lhs, E rhs) {
typedef typename std::underlying_type<E>::type underlying;
lhs = static_cast<E>(
static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs));
return lhs;
}
#include <comon/result.hpp>
#include <comon/asserts.hpp>
#include <comon/stringify.hpp>
#include <comon/string_to_numerics.hpp>
#include <comon/bitmask_operators.hpp>
\ No newline at end of file
#pragma once
#include <string>
#define CO_RETURN_ON_ERROR(x) { const co::Result& result__123 = (x); if (!result__123) return result__123;}
#ifdef ROS_ERROR
#define CO_RETURN_AND_LOG_ON_ERROR_MAIN(pred) { const co::Result& result = pred; if (!(result)) { auto msg = co::stringify(result.msg(), "\n File: ", __FILE__, "\n Line: ", __LINE__, "\n Function: ", __FUNCTION__); ROS_ERROR("%s", msg.c_str()); return -1; }}
#else
#define CO_RETURN_AND_LOG_ON_ERROR_MAIN(pred) { const co::Result& result = pred; if (!(result)) { auto msg = co::stringify(result.msg(), "\n File: ", __FILE__, "\n Line: ", __LINE__, "\n Function: ", __FUNCTION__); std::cout << msg.c_str() << std::endl; return -1; }}
#endif
namespace co {
enum class ResultCode {
Success = 0,
Failure = 1,
};
class Result {
public:
Result() = default;
Result(const Result&) = default;
Result(ResultCode code);
Result(std::string msg);
Result(ResultCode code, std::string msg);
Result(const char* msg);
template<class T>
Result(const T& value);
void ingore();
ResultCode code() const;
const std::string& msg() const;
bool hasMsg() const;
operator bool() const;
private:
ResultCode code_ = ResultCode::Failure;
std::string msg_;
};
} // namespace co
#include <comon/result.imp.hpp>
\ No newline at end of file
namespace co {
template<class T>
Result::Result(const T& value) {
if (static_cast<bool>(value)) {
code_ = ResultCode::Success;
} else {
code_ = ResultCode::Failure;
}
}
} // namespace co
\ No newline at end of file
#pragma once
#include <string>
#include <optional>
#include <limits>
namespace co {
std::optional<int> stoi(const std::string &s,
int min = std::numeric_limits<int>::min(),
int max = std::numeric_limits<int>::max()) noexcept;
std::optional<std::int64_t> stoi64(const std::string &,
std::int64_t min = std::numeric_limits<std::int64_t>::min(),
std::int64_t max = std::numeric_limits<std::int64_t>::max()) noexcept;
std::optional<float> stof(const std::string &s) noexcept;
std::optional<double> stod(const std::string &s) noexcept;
} // namespace co
#pragma once
#include <string>
namespace co {
template<class... Args>
std::string stringify(Args... args);
} // namespace co
#include <comon/stringify.imp.hpp>
#pragma once
#include <sstream>
namespace co {
namespace detail {
template<class T>
std::string strcatHelper(std::stringstream &ss, const T &val) {
ss << val;
return ss.str();
}
template<class T, class... Args>
std::string strcatHelper(std::stringstream &ss, const T &val, Args... args) {
ss << std::fixed << val;
return strcatHelper(ss, args...);
}
} // namespace detail
template<class... Args>
std::string stringify(Args... args) {
std::stringstream ss;
return detail::strcatHelper(ss, args...);
}
} // namespace co
\ No newline at end of file
#include <string>
namespace comon {
int getUniqueID();
std::string getUniqueStringID(std::string prefix);
} // namespace comon
\ No newline at end of file
#pragma once
#include <er1driver/misc.hpp>
#include <cstdint>
namespace er1driver {
class CommandQuery {
public:
void init(Motor motor, MCUCommand cmd, PayloadSize size);
void setByteValue(Word word, BytePosition position, std::uint8_t byte);
void setWordValue(Word word, std::uint16_t value);
void setIntAsPayload(std::int32_t value);
Bytes getFinalCommandBytes();
private:
Bytes cmd_;
};
} // namespace er1driver
\ No newline at end of file
#pragma once
#include <er1driver/misc.hpp>
namespace er1driver {
class CommandResponse {
public:
void init(Bytes data);
Byte getPayloadByte(Word word, BytePosition position);
std::uint16_t getPayloadWord(Word word);
Byte getPayloadBits(Word word, BytePosition position, int start, int stop);
Byte getPayloadBit(Word word, BytePosition position, int start);
std::int32_t getPayloadInt();
private:
Bytes bytes_;
};
} // namespace er1driver
\ No newline at end of file
#pragma once
#include <comon/result.hpp>
#include <er1driver/misc.hpp>
namespace er1driver {
class ControlModule {
public:
co::Result connect(std::string deviceName);
bool isConnected() const;
void disconnect();
co::Result getVersion(CMDGetVersionResult* dest, Motor motor);
co::Result getEventStatus(CMDGetEventStatusResult* dest, Motor motor);
co::Result getProfileMode(ProfileMode* mode, Motor motor);
co::Result setProfileMode(Motor motor, ProfileMode mode);
co::Result reset(Motor motor);
co::Result update(Motor motor);
co::Result getAck();