forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tier4_planning_rviz_plugin): support backward driving in path/tra…
…j plugin (autowarefoundation#1335) * fix(tier4_planning_rviz_plugin): support backward driving in path_with_lane_id/path/trajectory plugin Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * add utils.hpp Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
- Loading branch information
1 parent
5e9fd5d
commit faa71f3
Showing
5 changed files
with
79 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2020 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 UTILS_HPP_ | ||
#define UTILS_HPP_ | ||
|
||
#include <tier4_autoware_utils/geometry/geometry.hpp> | ||
#include <tier4_autoware_utils/geometry/path_with_lane_id_geometry.hpp> | ||
#include <tier4_autoware_utils/math/normalization.hpp> | ||
|
||
#include <tf2/utils.h> | ||
|
||
namespace rviz_plugins | ||
{ | ||
template <class T> | ||
bool isDrivingForward(const T points_with_twist, size_t target_idx) | ||
{ | ||
constexpr double epsilon = 1e-6; | ||
|
||
// 1. check velocity | ||
const double target_velocity = | ||
tier4_autoware_utils::getLongitudinalVelocity(points_with_twist.at(target_idx)); | ||
if (epsilon < target_velocity) { | ||
return true; | ||
} else if (target_velocity < -epsilon) { | ||
return false; | ||
} | ||
|
||
// 2. check points size is enough | ||
if (points_with_twist.size() < 2) { | ||
return true; | ||
} | ||
|
||
// 3. check points direction | ||
const bool is_last_point = target_idx == points_with_twist.size() - 1; | ||
const size_t first_idx = is_last_point ? target_idx - 1 : target_idx; | ||
const size_t second_idx = is_last_point ? target_idx : target_idx + 1; | ||
|
||
const auto first_pose = tier4_autoware_utils::getPose(points_with_twist.at(first_idx)); | ||
const auto second_pose = tier4_autoware_utils::getPose(points_with_twist.at(second_idx)); | ||
const double first_traj_yaw = tf2::getYaw(first_pose.orientation); | ||
const double driving_direction_yaw = | ||
tier4_autoware_utils::calcAzimuthAngle(first_pose.position, second_pose.position); | ||
if ( | ||
std::abs(tier4_autoware_utils::normalizeRadian(first_traj_yaw - driving_direction_yaw)) < | ||
M_PI_2) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} // namespace rviz_plugins | ||
|
||
#endif // UTILS_HPP_ |
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