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

feat(tier4_autoware_utils): add quaternion operation #2244

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions common/tier4_autoware_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ find_package(Boost REQUIRED)
ament_auto_add_library(tier4_autoware_utils SHARED
src/tier4_autoware_utils.cpp
src/geometry/boost_polygon_utils.cpp
src/ros/operation.cpp
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
)

if(BUILD_TESTING)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2022 TIER IV, Inc.
//
// 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 TIER4_AUTOWARE_UTILS__ROS__OPERATION_HPP_
#define TIER4_AUTOWARE_UTILS__ROS__OPERATION_HPP_

#include "geometry_msgs/msg/quaternion.hpp"

// NOTE: Do not use tier4_autoware_utils namespace
namespace geometry_msgs
{
namespace msg
{
Quaternion operator+(Quaternion a, Quaternion b) noexcept;
Quaternion operator-(Quaternion a) noexcept;
Quaternion operator-(Quaternion a, Quaternion b) noexcept;
} // namespace msg
} // namespace geometry_msgs

#endif // TIER4_AUTOWARE_UTILS__ROS__OPERATION_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "tier4_autoware_utils/ros/debug_traits.hpp"
#include "tier4_autoware_utils/ros/marker_helper.hpp"
#include "tier4_autoware_utils/ros/msg_covariance.hpp"
#include "tier4_autoware_utils/ros/operation.hpp"
#include "tier4_autoware_utils/ros/processing_time_publisher.hpp"
#include "tier4_autoware_utils/ros/self_pose_listener.hpp"
#include "tier4_autoware_utils/ros/transform_listener.hpp"
Expand Down
55 changes: 55 additions & 0 deletions common/tier4_autoware_utils/src/ros/operation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2022 TIER IV, Inc.
//
// 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 "tier4_autoware_utils/ros/operation.hpp"

#include <tf2/utils.h>

#ifdef ROS_DISTRO_GALACTIC
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
#else
#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
#endif

// NOTE: Do not use tier4_autoware_utils namespace
namespace geometry_msgs
{
namespace msg
{
Quaternion operator+(Quaternion a, Quaternion b) noexcept
{
tf2::Quaternion quat_a;
tf2::Quaternion quat_b;
tf2::fromMsg(a, quat_a);
tf2::fromMsg(b, quat_b);
return tf2::toMsg(quat_a + quat_b);
}

Quaternion operator-(Quaternion a) noexcept
{
tf2::Quaternion quat_a;
tf2::fromMsg(a, quat_a);
return tf2::toMsg(quat_a * -1.0);
}

Quaternion operator-(Quaternion a, Quaternion b) noexcept
{
tf2::Quaternion quat_a;
tf2::Quaternion quat_b;
tf2::fromMsg(a, quat_a);
tf2::fromMsg(b, quat_b);
return tf2::toMsg(quat_a * quat_b.inverse());
}
} // namespace msg
} // namespace geometry_msgs