-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd39297
commit 975ba97
Showing
15 changed files
with
217 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(navyu_utils) | ||
|
||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
endif() | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
find_package(ament_cmake_auto REQUIRED) | ||
ament_auto_find_build_dependencies() | ||
|
||
ament_auto_add_library(navyu_utils SHARED | ||
src/navyu_utils.cpp | ||
) | ||
|
||
ament_auto_add_library(quaternion_utils SHARED | ||
src/quaternion_utils.cpp | ||
) | ||
|
||
if(BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
ament_lint_auto_find_test_dependencies() | ||
endif() | ||
|
||
ament_auto_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2024 RyuYamamoto. | ||
// | ||
// 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 NAVYU_UTIULS__NAVYU_UTILS_HPP_ | ||
#define NAVYU_UTIULS__NAVYU_UTILS_HPP_ | ||
|
||
#include <Eigen/Core> | ||
#include <rclcpp/logger.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <geometry_msgs/msg/pose.hpp> | ||
#include <std_msgs/msg/color_rgba.hpp> | ||
#include <visualization_msgs/msg/marker.hpp> | ||
|
||
#include <tf2_ros/buffer.h> | ||
#include <tf2_ros/transform_broadcaster.h> | ||
#include <tf2_ros/transform_listener.h> | ||
|
||
namespace navyu_utils | ||
{ | ||
|
||
bool get_robot_pose( | ||
const std::string global_frame, const std::string robot_frame, tf2_ros::Buffer & tf_buffer, | ||
geometry_msgs::msg::Pose & robot_pose); | ||
|
||
double calculation_distance(const geometry_msgs::msg::Pose p1, const geometry_msgs::msg::Pose p2); | ||
|
||
double normalized_radian(const double radian); | ||
|
||
} // namespace navyu_utils | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2024 RyuYamamoto. | ||
// | ||
// 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 NAVYU_UTILS__QUATERNION_UTILS_HPP_ | ||
#define NAVYU_UTILS__QUATERNION_UTILS_HPP_ | ||
|
||
#include <Eigen/Core> | ||
#include <tf2_eigen/tf2_eigen.hpp> | ||
|
||
#include <geometry_msgs/msg/quaternion.hpp> | ||
#include <geometry_msgs/msg/vector3.hpp> | ||
#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp> | ||
|
||
#include <tf2/LinearMath/Quaternion.h> | ||
|
||
namespace quaternion_utils | ||
{ | ||
|
||
geometry_msgs::msg::Quaternion convert_euler_to_quaternion(const geometry_msgs::msg::Vector3 euler); | ||
|
||
geometry_msgs::msg::Vector3 convert_quaternion_to_euler( | ||
const geometry_msgs::msg::Quaternion quaternion); | ||
|
||
geometry_msgs::msg::Quaternion rotation( | ||
const geometry_msgs::msg::Quaternion quat1, const geometry_msgs::msg::Quaternion quat2); | ||
|
||
Eigen::Matrix3f get_rotation_matrix_from_euler(const geometry_msgs::msg::Vector3 euler); | ||
|
||
} // namespace quaternion_utils | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0"?> | ||
<package format="3"> | ||
<name>navyu_utils</name> | ||
<version>0.1.0</version> | ||
<description>The navyu_utils package</description> | ||
<maintainer email="[email protected]">RyuYamamoto</maintainer> | ||
<license>Apache License 2.0</license> | ||
|
||
<buildtool_depend>ament_cmake_auto</buildtool_depend> | ||
|
||
<depend>rclcpp</depend> | ||
<depend>geometry_msgs</depend> | ||
<depend>visualization_msgs</depend> | ||
<depend>tf2</depend> | ||
<depend>tf2_ros</depend> | ||
<depend>tf2_geometry_msgs</depend> | ||
<depend>tf2_eigen</depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
<test_depend>ament_lint_common</test_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2024 RyuYamamoto. | ||
// | ||
// 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 | ||
|
||
#include "navyu_utils/navyu_utils.hpp" | ||
|
||
namespace navyu_utils | ||
{ | ||
|
||
bool get_robot_pose( | ||
const std::string global_frame, const std::string robot_frame, tf2_ros::Buffer & tf_buffer, | ||
geometry_msgs::msg::Pose & robot_pose) | ||
{ | ||
static rclcpp::Logger logger = rclcpp::get_logger("get_robot_pose"); | ||
|
||
geometry_msgs::msg::TransformStamped robot_pose_frame; | ||
|
||
try { | ||
robot_pose_frame = tf_buffer.lookupTransform( | ||
global_frame, robot_frame, tf2::TimePointZero, tf2::durationFromSec(0.5)); | ||
} catch (tf2::TransformException & ex) { | ||
RCLCPP_ERROR_STREAM(logger, "Can not get Transform " << global_frame << " to " << robot_frame); | ||
return false; | ||
} | ||
|
||
robot_pose.position.x = robot_pose_frame.transform.translation.x; | ||
robot_pose.position.y = robot_pose_frame.transform.translation.y; | ||
robot_pose.position.z = robot_pose_frame.transform.translation.z; | ||
robot_pose.orientation = robot_pose_frame.transform.rotation; | ||
|
||
return true; | ||
} | ||
|
||
double calculation_distance(const geometry_msgs::msg::Pose p1, const geometry_msgs::msg::Pose p2) | ||
{ | ||
const double dx = p1.position.x - p2.position.x; | ||
const double dy = p1.position.y - p2.position.y; | ||
return std::hypot(dx, dy); | ||
} | ||
|
||
double normalized_radian(const double radian) | ||
{ | ||
double normalized_radian = radian; | ||
if (M_PI < radian) | ||
normalized_radian -= 2.0 * M_PI; | ||
else if (radian < -M_PI) | ||
normalized_radian += 2.0 * M_PI; | ||
return normalized_radian; | ||
} | ||
|
||
} // namespace navyu_utils |
Oops, something went wrong.