diff --git a/common/tier4_planning_rviz_plugin/CMakeLists.txt b/common/tier4_planning_rviz_plugin/CMakeLists.txt index 53cb313572b3c..a9cceee573c2d 100644 --- a/common/tier4_planning_rviz_plugin/CMakeLists.txt +++ b/common/tier4_planning_rviz_plugin/CMakeLists.txt @@ -29,6 +29,8 @@ ament_auto_add_library(tier4_planning_rviz_plugin SHARED src/path_footprint/display.cpp include/path_with_lane_id/display.hpp src/path_with_lane_id/display.cpp + include/path_with_lane_id_footprint/display.hpp + src/path_with_lane_id_footprint/display.cpp include/trajectory/display.hpp src/trajectory/display.cpp include/trajectory_footprint/display.hpp diff --git a/common/tier4_planning_rviz_plugin/icons/classes/PathWithLaneIdFootprint.png b/common/tier4_planning_rviz_plugin/icons/classes/PathWithLaneIdFootprint.png new file mode 100644 index 0000000000000..6a67573717ae1 Binary files /dev/null and b/common/tier4_planning_rviz_plugin/icons/classes/PathWithLaneIdFootprint.png differ diff --git a/common/tier4_planning_rviz_plugin/include/path_with_lane_id_footprint/display.hpp b/common/tier4_planning_rviz_plugin/include/path_with_lane_id_footprint/display.hpp new file mode 100644 index 0000000000000..19c7146ee92af --- /dev/null +++ b/common/tier4_planning_rviz_plugin/include/path_with_lane_id_footprint/display.hpp @@ -0,0 +1,85 @@ +// Copyright 2021 Tier IV, Inc. All rights reserved. +// +// 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 PATH_WITH_LANE_ID_FOOTPRINT__DISPLAY_HPP_ +#define PATH_WITH_LANE_ID_FOOTPRINT__DISPLAY_HPP_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include + +namespace rviz_plugins +{ +class AutowarePathWithLaneIdFootprintDisplay +: public rviz_common::MessageFilterDisplay +{ + Q_OBJECT + +public: + AutowarePathWithLaneIdFootprintDisplay(); + virtual ~AutowarePathWithLaneIdFootprintDisplay(); + + void onInitialize() override; + void reset() override; + +private Q_SLOTS: + void updateVisualization(); + void updateVehicleInfo(); + +protected: + void processMessage( + const autoware_auto_planning_msgs::msg::PathWithLaneId::ConstSharedPtr msg_ptr) override; + Ogre::ManualObject * path_footprint_manual_object_; + rviz_common::properties::BoolProperty * property_path_footprint_view_; + rviz_common::properties::ColorProperty * property_path_footprint_color_; + rviz_common::properties::FloatProperty * property_path_footprint_alpha_; + rviz_common::properties::FloatProperty * property_vehicle_length_; + rviz_common::properties::FloatProperty * property_vehicle_width_; + rviz_common::properties::FloatProperty * property_rear_overhang_; + + struct VehicleFootprintInfo + { + VehicleFootprintInfo(const float l, const float w, const float r) + : length(l), width(w), rear_overhang(r) + { + } + float length, width, rear_overhang; + }; + std::shared_ptr vehicle_footprint_info_; + +private: + autoware_auto_planning_msgs::msg::PathWithLaneId::ConstSharedPtr last_msg_ptr_; + bool validateFloats( + const autoware_auto_planning_msgs::msg::PathWithLaneId::ConstSharedPtr & msg_ptr); +}; + +} // namespace rviz_plugins + +#endif // PATH_WITH_LANE_ID_FOOTPRINT__DISPLAY_HPP_ diff --git a/common/tier4_planning_rviz_plugin/plugins/plugin_description.xml b/common/tier4_planning_rviz_plugin/plugins/plugin_description.xml index efe127437917e..b61b79ba35d3f 100644 --- a/common/tier4_planning_rviz_plugin/plugins/plugin_description.xml +++ b/common/tier4_planning_rviz_plugin/plugins/plugin_description.xml @@ -19,6 +19,11 @@ base_class_type="rviz_common::Display"> Display path_with_lane_id of autoware_auto_planning_msg::PathWithLaneId + + Display footprint of autoware_auto_planning_msg::PathWithLaneId + diff --git a/common/tier4_planning_rviz_plugin/src/path_with_lane_id_footprint/display.cpp b/common/tier4_planning_rviz_plugin/src/path_with_lane_id_footprint/display.cpp new file mode 100644 index 0000000000000..31463d40896fc --- /dev/null +++ b/common/tier4_planning_rviz_plugin/src/path_with_lane_id_footprint/display.cpp @@ -0,0 +1,187 @@ +// Copyright 2021 Tier IV, Inc. All rights reserved. +// +// 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 + +#define EIGEN_MPL2_ONLY +#include +#include +#include + +namespace rviz_plugins +{ +AutowarePathWithLaneIdFootprintDisplay::AutowarePathWithLaneIdFootprintDisplay() +{ + property_path_footprint_view_ = new rviz_common::properties::BoolProperty( + "View PathWithLaneId Footprint", true, "", this, SLOT(updateVisualization()), this); + property_path_footprint_alpha_ = new rviz_common::properties::FloatProperty( + "Alpha", 1.0, "", property_path_footprint_view_, SLOT(updateVisualization()), this); + property_path_footprint_alpha_->setMin(0.0); + property_path_footprint_alpha_->setMax(1.0); + property_path_footprint_color_ = new rviz_common::properties::ColorProperty( + "Color", QColor(230, 230, 50), "", property_path_footprint_view_, SLOT(updateVisualization()), + this); + property_vehicle_length_ = new rviz_common::properties::FloatProperty( + "Vehicle Length", 4.77, "", property_path_footprint_view_, SLOT(updateVehicleInfo()), this); + property_vehicle_width_ = new rviz_common::properties::FloatProperty( + "Vehicle Width", 1.83, "", property_path_footprint_view_, SLOT(updateVehicleInfo()), this); + property_rear_overhang_ = new rviz_common::properties::FloatProperty( + "Rear Overhang", 1.03, "", property_path_footprint_view_, SLOT(updateVehicleInfo()), this); + property_vehicle_length_->setMin(0.0); + property_vehicle_width_->setMin(0.0); + property_rear_overhang_->setMin(0.0); + + updateVehicleInfo(); +} + +AutowarePathWithLaneIdFootprintDisplay::~AutowarePathWithLaneIdFootprintDisplay() +{ + if (initialized()) { + scene_manager_->destroyManualObject(path_footprint_manual_object_); + } +} + +void AutowarePathWithLaneIdFootprintDisplay::onInitialize() +{ + MFDClass::onInitialize(); + + path_footprint_manual_object_ = scene_manager_->createManualObject(); + path_footprint_manual_object_->setDynamic(true); + scene_node_->attachObject(path_footprint_manual_object_); +} + +void AutowarePathWithLaneIdFootprintDisplay::reset() +{ + MFDClass::reset(); + path_footprint_manual_object_->clear(); +} + +bool AutowarePathWithLaneIdFootprintDisplay::validateFloats( + const autoware_auto_planning_msgs::msg::PathWithLaneId::ConstSharedPtr & msg_ptr) +{ + for (auto && path_point : msg_ptr->points) { + if (!rviz_common::validateFloats(path_point.point.pose)) { + return false; + } + } + return true; +} + +void AutowarePathWithLaneIdFootprintDisplay::processMessage( + const autoware_auto_planning_msgs::msg::PathWithLaneId::ConstSharedPtr msg_ptr) +{ + if (!validateFloats(msg_ptr)) { + setStatus( + rviz_common::properties::StatusProperty::Error, "Topic", + "Message contained invalid floating point values (nans or infs)"); + return; + } + + Ogre::Vector3 position; + Ogre::Quaternion orientation; + if (!context_->getFrameManager()->getTransform(msg_ptr->header, position, orientation)) { + RCLCPP_DEBUG( + rviz_ros_node_.lock()->get_raw_node()->get_logger(), + "Error transforming from frame '%s' to frame '%s'", msg_ptr->header.frame_id.c_str(), + qPrintable(fixed_frame_)); + } + + scene_node_->setPosition(position); + scene_node_->setOrientation(orientation); + + path_footprint_manual_object_->clear(); + + Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName( + "BaseWhiteNoLighting", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); + material->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); + material->setDepthWriteEnabled(false); + + if (!msg_ptr->points.empty()) { + path_footprint_manual_object_->estimateVertexCount(msg_ptr->points.size() * 4 * 2); + path_footprint_manual_object_->begin( + "BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST); + + for (size_t point_idx = 0; point_idx < msg_ptr->points.size(); point_idx++) { + const auto & path_point = msg_ptr->points.at(point_idx); + /* + * Footprint + */ + if (property_path_footprint_view_->getBool()) { + Ogre::ColourValue color; + color = rviz_common::properties::qtToOgre(property_path_footprint_color_->getColor()); + color.a = property_path_footprint_alpha_->getFloat(); + + const auto info = vehicle_footprint_info_; + const float top = info->length - info->rear_overhang; + const float bottom = -info->rear_overhang; + const float left = -info->width / 2.0; + const float right = info->width / 2.0; + + const std::array lon_offset_vec{top, top, bottom, bottom}; + const std::array lat_offset_vec{left, right, right, left}; + + for (int f_idx = 0; f_idx < 4; ++f_idx) { + const Eigen::Quaternionf quat( + path_point.point.pose.orientation.w, path_point.point.pose.orientation.x, + path_point.point.pose.orientation.y, path_point.point.pose.orientation.z); + + { + const Eigen::Vector3f offset_vec{ + lon_offset_vec.at(f_idx), lat_offset_vec.at(f_idx), 0.0}; + const auto offset_to_edge = quat * offset_vec; + path_footprint_manual_object_->position( + path_point.point.pose.position.x + offset_to_edge.x(), + path_point.point.pose.position.y + offset_to_edge.y(), + path_point.point.pose.position.z); + path_footprint_manual_object_->colour(color); + } + { + const Eigen::Vector3f offset_vec{ + lon_offset_vec.at((f_idx + 1) % 4), lat_offset_vec.at((f_idx + 1) % 4), 0.0}; + const auto offset_to_edge = quat * offset_vec; + path_footprint_manual_object_->position( + path_point.point.pose.position.x + offset_to_edge.x(), + path_point.point.pose.position.y + offset_to_edge.y(), + path_point.point.pose.position.z); + path_footprint_manual_object_->colour(color); + } + } + } + } + + path_footprint_manual_object_->end(); + } + last_msg_ptr_ = msg_ptr; +} + +void AutowarePathWithLaneIdFootprintDisplay::updateVisualization() +{ + if (last_msg_ptr_ != nullptr) { + processMessage(last_msg_ptr_); + } +} + +void AutowarePathWithLaneIdFootprintDisplay::updateVehicleInfo() +{ + float length{property_vehicle_length_->getFloat()}; + float width{property_vehicle_width_->getFloat()}; + float rear_overhang{property_rear_overhang_->getFloat()}; + + vehicle_footprint_info_ = std::make_shared(length, width, rear_overhang); +} + +} // namespace rviz_plugins + +#include +PLUGINLIB_EXPORT_CLASS(rviz_plugins::AutowarePathWithLaneIdFootprintDisplay, rviz_common::Display)