Compare commits
5 Commits
03a8fa3a80
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 004dd7f0ff | |||
| d7eed928fb | |||
| 594f0fe49e | |||
| b1aaa1a946 | |||
| 8b22de38ac |
152
CMakeLists.txt
152
CMakeLists.txt
@@ -1,30 +1,142 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.0.2)
|
||||||
project(data_convert)
|
project(data_convert VERSION 1.0.0 LANGUAGES CXX)
|
||||||
|
|
||||||
|
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
|
||||||
|
set(BUILDING_WITH_CATKIN TRUE)
|
||||||
|
message(STATUS "Building data_convert with Catkin")
|
||||||
|
|
||||||
|
else()
|
||||||
|
set(BUILDING_WITH_CATKIN FALSE)
|
||||||
|
message(STATUS "Building data_convert with Standalone CMake")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# C++ Standard - must be set before find_package
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
add_library(data_convert INTERFACE)
|
if (NOT BUILDING_WITH_CATKIN)
|
||||||
|
|
||||||
target_include_directories(data_convert
|
# Enable Position Independent Code
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
|
# Cấu hình RPATH để tránh cycle trong runtime search path
|
||||||
|
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
|
||||||
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
set(CMAKE_BUILD_RPATH "${CMAKE_BINARY_DIR}")
|
||||||
|
|
||||||
|
set(PACKAGES_DIR
|
||||||
|
robot_geometry_msgs
|
||||||
|
)
|
||||||
|
|
||||||
|
else()
|
||||||
|
|
||||||
|
# ========================================================
|
||||||
|
# Catkin specific configuration
|
||||||
|
# ========================================================
|
||||||
|
find_package(catkin REQUIRED COMPONENTS
|
||||||
|
robot_geometry_msgs
|
||||||
|
)
|
||||||
|
|
||||||
|
catkin_package(
|
||||||
|
INCLUDE_DIRS include
|
||||||
|
# LIBRARIES không cần vì đây là header-only library
|
||||||
|
CATKIN_DEPENDS robot_geometry_msgs
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
include
|
||||||
|
${catkin_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Tìm tất cả header files
|
||||||
|
file(GLOB_RECURSE HEADERS "include/data_convert/*.h")
|
||||||
|
|
||||||
|
# Tạo INTERFACE library (header-only)
|
||||||
|
add_library(${PROJECT_NAME} INTERFACE)
|
||||||
|
|
||||||
|
if(BUILDING_WITH_CATKIN)
|
||||||
|
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
|
||||||
|
|
||||||
|
# Set include directories
|
||||||
|
target_include_directories(${PROJECT_NAME}
|
||||||
INTERFACE
|
INTERFACE
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
$<INSTALL_INTERFACE:include>
|
$<INSTALL_INTERFACE:include>
|
||||||
)
|
)
|
||||||
|
|
||||||
# --- Cài đặt thư viện vào hệ thống khi chạy make install ---
|
# Link dependencies (header-only, chỉ cần include paths)
|
||||||
install(TARGETS data_convert
|
target_link_libraries(${PROJECT_NAME}
|
||||||
EXPORT data_convert-targets
|
INTERFACE
|
||||||
INCLUDES DESTINATION include # Cài đặt include
|
${catkin_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
# --- Xuất export set data_convert-targets thành file CMake module ---
|
else()
|
||||||
# --- Tạo file lib/cmake/data_convert/data_convert-targets.cmake ---
|
|
||||||
# --- File này chứa cấu hình giúp project khác có thể dùng ---
|
|
||||||
# --- Find_package(data_convert REQUIRED) ---
|
|
||||||
# --- Target_link_libraries(my_app PRIVATE data_convert::data_convert) ---
|
|
||||||
install(EXPORT data_convert-targets
|
|
||||||
FILE data_convert-targets.cmake
|
|
||||||
NAMESPACE data_convert::
|
|
||||||
DESTINATION lib/cmake/data_convert
|
|
||||||
)
|
|
||||||
|
|
||||||
|
# Set include directories
|
||||||
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
)
|
||||||
|
|
||||||
|
# Link dependencies (header-only, chỉ cần include paths)
|
||||||
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
INTERFACE
|
||||||
|
${PACKAGES_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(BUILDING_WITH_CATKIN)
|
||||||
|
## Mark libraries for installation
|
||||||
|
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
|
||||||
|
install(TARGETS ${PROJECT_NAME}
|
||||||
|
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||||
|
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||||
|
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
|
||||||
|
)
|
||||||
|
|
||||||
|
## Mark cpp header files for installation
|
||||||
|
install(DIRECTORY include/${PROJECT_NAME}/
|
||||||
|
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
|
||||||
|
FILES_MATCHING PATTERN "*.h"
|
||||||
|
PATTERN ".svn" EXCLUDE
|
||||||
|
)
|
||||||
|
|
||||||
|
else()
|
||||||
|
|
||||||
|
install(TARGETS ${PROJECT_NAME}
|
||||||
|
EXPORT ${PROJECT_NAME}-targets
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
)
|
||||||
|
|
||||||
|
# Export targets
|
||||||
|
install(EXPORT ${PROJECT_NAME}-targets
|
||||||
|
FILE ${PROJECT_NAME}-targets.cmake
|
||||||
|
NAMESPACE ${PROJECT_NAME}::
|
||||||
|
DESTINATION lib/cmake/${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
## Mark cpp header files for installation
|
||||||
|
install(DIRECTORY include/${PROJECT_NAME}/
|
||||||
|
DESTINATION include
|
||||||
|
FILES_MATCHING PATTERN "*.h"
|
||||||
|
PATTERN ".svn" EXCLUDE
|
||||||
|
)
|
||||||
|
|
||||||
|
# Print configuration info
|
||||||
|
message(STATUS "=================================")
|
||||||
|
message(STATUS "Project: ${PROJECT_NAME} (Header-Only)")
|
||||||
|
message(STATUS "Version: ${PROJECT_VERSION}")
|
||||||
|
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
|
||||||
|
message(STATUS "Headers found:")
|
||||||
|
foreach(hdr ${HEADERS})
|
||||||
|
message(STATUS " - ${hdr}")
|
||||||
|
endforeach()
|
||||||
|
message(STATUS "Dependencies: robot_geometry_msgs")
|
||||||
|
message(STATUS "=================================")
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -1,55 +1,27 @@
|
|||||||
#ifndef COSTMAP_2D_DATA_CONVERT_H
|
#ifndef COSTMAP_2D_DATA_CONVERT_H
|
||||||
#define COSTMAP_2D_DATA_CONVERT_H
|
#define COSTMAP_2D_DATA_CONVERT_H
|
||||||
|
|
||||||
#include <geometry_msgs/TransformStamped.h>
|
#include <robot_geometry_msgs/TransformStamped.h>
|
||||||
#include <geometry_msgs/Quaternion.h>
|
#include <robot_geometry_msgs/Quaternion.h>
|
||||||
#include <geometry_msgs/Pose.h>
|
#include <robot_geometry_msgs/Pose.h>
|
||||||
#include <geometry_msgs/PoseStamped.h>
|
#include <robot_geometry_msgs/PoseStamped.h>
|
||||||
#include <tf3/utils.h>
|
#include <tf3/utils.h>
|
||||||
#include <tf3/compat.h>
|
#include <tf3/compat.h>
|
||||||
#include <robot/time.h>
|
#include <robot/time.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
// template <typename T>
|
|
||||||
// bool isEqual(const T& a, const T& b, double eps = 1e-5)
|
|
||||||
// {
|
|
||||||
// return std::fabs(a - b) < eps;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// inline bool operator==(const geometry_msgs::Quaternion& a, const geometry_msgs::Quaternion& b)
|
|
||||||
// {
|
|
||||||
// return isEqual(a.x, b.x) && isEqual(a.y, b.y) && isEqual(a.z, b.z) && isEqual(a.w, b.w);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// inline bool operator==(const geometry_msgs::Point& a, const geometry_msgs::Point& b)
|
|
||||||
// {
|
|
||||||
// return isEqual(a.x, b.x) && isEqual(a.y, b.y) && isEqual(a.z, b.z);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// inline bool operator==(const geometry_msgs::Pose& a, const geometry_msgs::Pose& b)
|
|
||||||
// {
|
|
||||||
// return (a.position == b.position) && (a.orientation == b.orientation);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// inline bool operator==(const geometry_msgs::PoseStamped& a, const geometry_msgs::PoseStamped& b)
|
|
||||||
// {
|
|
||||||
// return (a.header.frame_id == b.header.frame_id) &&
|
|
||||||
// (a.pose == b.pose);
|
|
||||||
// }
|
|
||||||
namespace data_convert
|
namespace data_convert
|
||||||
{
|
{
|
||||||
|
inline double getYaw(const robot_geometry_msgs::Quaternion& q)
|
||||||
|
|
||||||
inline double getYaw(const geometry_msgs::Quaternion& q)
|
|
||||||
{
|
{
|
||||||
double siny_cosp = 2.0 * (q.w * q.z + q.x * q.y);
|
double siny_cosp = 2.0 * (q.w * q.z + q.x * q.y);
|
||||||
double cosy_cosp = 1.0 - 2.0 * (q.y * q.y + q.z * q.z);
|
double cosy_cosp = 1.0 - 2.0 * (q.y * q.y + q.z * q.z);
|
||||||
return std::atan2(siny_cosp, cosy_cosp);
|
return std::atan2(siny_cosp, cosy_cosp);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline geometry_msgs::Quaternion getQuaternion(const double& yaw)
|
inline robot_geometry_msgs::Quaternion getQuaternion(const double& yaw)
|
||||||
{
|
{
|
||||||
geometry_msgs::Quaternion q;
|
robot_geometry_msgs::Quaternion q;
|
||||||
q.x = 0.0;
|
q.x = 0.0;
|
||||||
q.y = 0.0;
|
q.y = 0.0;
|
||||||
q.z = std::sin(yaw / 2.0);
|
q.z = std::sin(yaw / 2.0);
|
||||||
@@ -73,15 +45,15 @@ namespace data_convert
|
|||||||
return time_tmp;
|
return time_tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline tf3::Quaternion convertQuaternion(const geometry_msgs::Quaternion& q)
|
inline tf3::Quaternion convertQuaternion(const robot_geometry_msgs::Quaternion& q)
|
||||||
{
|
{
|
||||||
tf3::Quaternion out(q.x,q.y,q.z,q.w);
|
tf3::Quaternion out(q.x,q.y,q.z,q.w);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline geometry_msgs::Quaternion convertQuaternion(const tf3::Quaternion& q)
|
inline robot_geometry_msgs::Quaternion convertQuaternion(const tf3::Quaternion& q)
|
||||||
{
|
{
|
||||||
geometry_msgs::Quaternion out;
|
robot_geometry_msgs::Quaternion out;
|
||||||
out.x = q.x();
|
out.x = q.x();
|
||||||
out.y = q.y();
|
out.y = q.y();
|
||||||
out.z = q.z();
|
out.z = q.z();
|
||||||
@@ -89,7 +61,21 @@ namespace data_convert
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline tf3::Transform convertTotf3Transform(const geometry_msgs::Transform& msg)
|
inline robot_geometry_msgs::Quaternion createQuaternionMsgFromYaw(const double& yaw)
|
||||||
|
{
|
||||||
|
tf3::Quaternion q;
|
||||||
|
q.setRPY(0.0, 0.0, yaw);
|
||||||
|
|
||||||
|
robot_geometry_msgs::Quaternion q_msg;
|
||||||
|
q_msg.x = q.x();
|
||||||
|
q_msg.y = q.y();
|
||||||
|
q_msg.z = q.z();
|
||||||
|
q_msg.w = q.w();
|
||||||
|
|
||||||
|
return q_msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline tf3::Transform convertTotf3Transform(const robot_geometry_msgs::Transform& msg)
|
||||||
{
|
{
|
||||||
tf3::Quaternion q(
|
tf3::Quaternion q(
|
||||||
msg.rotation.x,
|
msg.rotation.x,
|
||||||
@@ -148,7 +134,7 @@ namespace data_convert
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline tf3::Transform convertTotf3Transform(const geometry_msgs::TransformStamped& msg)
|
inline tf3::Transform convertTotf3Transform(const robot_geometry_msgs::TransformStamped& msg)
|
||||||
{
|
{
|
||||||
tf3::Transform out;
|
tf3::Transform out;
|
||||||
|
|
||||||
@@ -169,7 +155,7 @@ namespace data_convert
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline tf3::TransformStampedMsg convertToTransformStampedMsg(const geometry_msgs::TransformStamped& msg)
|
inline tf3::TransformStampedMsg convertToTransformStampedMsg(const robot_geometry_msgs::TransformStamped& msg)
|
||||||
{
|
{
|
||||||
tf3::TransformStampedMsg out;
|
tf3::TransformStampedMsg out;
|
||||||
out.header.seq = msg.header.seq;
|
out.header.seq = msg.header.seq;
|
||||||
@@ -186,9 +172,9 @@ namespace data_convert
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline geometry_msgs::TransformStamped convertToTransformStamped(const tf3::TransformStampedMsg& msg)
|
inline robot_geometry_msgs::TransformStamped convertToTransformStamped(const tf3::TransformStampedMsg& msg)
|
||||||
{
|
{
|
||||||
geometry_msgs::TransformStamped out;
|
robot_geometry_msgs::TransformStamped out;
|
||||||
out.header.seq = msg.header.seq;
|
out.header.seq = msg.header.seq;
|
||||||
out.header.stamp = convertTime(msg.header.stamp);
|
out.header.stamp = convertTime(msg.header.stamp);
|
||||||
out.header.frame_id = msg.header.frame_id;
|
out.header.frame_id = msg.header.frame_id;
|
||||||
|
|||||||
25
package.xml
Normal file
25
package.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<package>
|
||||||
|
<name>data_convert</name>
|
||||||
|
<version>0.7.10</version>
|
||||||
|
<description>
|
||||||
|
data_convert is the second generation of the transform library, which lets
|
||||||
|
the user keep track of multiple coordinate frames over time. data_convert
|
||||||
|
maintains the relationship between coordinate frames in a tree
|
||||||
|
structure buffered in time, and lets the user transform points,
|
||||||
|
vectors, etc between any two coordinate frames at any desired
|
||||||
|
point in time.
|
||||||
|
</description>
|
||||||
|
<author>Tully Foote</author>
|
||||||
|
<author>Eitan Marder-Eppstein</author>
|
||||||
|
<author>Wim Meeussen</author>
|
||||||
|
<maintainer email="tfoote@osrfoundation.org">Tully Foote</maintainer>
|
||||||
|
<license>BSD</license>
|
||||||
|
|
||||||
|
<url type="website">http://www.ros.org/wiki/data_convert</url>
|
||||||
|
|
||||||
|
<buildtool_depend version_gte="0.5.68">catkin</buildtool_depend>
|
||||||
|
|
||||||
|
<build_depend>robot_geometry_msgs</build_depend>
|
||||||
|
<run_depend>robot_geometry_msgs</run_depend>
|
||||||
|
|
||||||
|
</package>
|
||||||
Reference in New Issue
Block a user