Skip to content

Commit

Permalink
feat: add support of displaying TrackedObjects (#39)
Browse files Browse the repository at this point in the history
Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 authored Aug 16, 2024
1 parent 35f8f96 commit 6304214
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2024 Kotaro Uetake.
//
// 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 AWVIZ_PLUGIN__AUTOWARE_PERCEPTION__TRACKED_OBJECTS_DISPLAY_HPP_
#define AWVIZ_PLUGIN__AUTOWARE_PERCEPTION__TRACKED_OBJECTS_DISPLAY_HPP_

#include <awviz_common/display.hpp>

#include <autoware_perception_msgs/msg/tracked_objects.hpp>

namespace awviz_plugin
{
class TrackedObjectsDisplay
: public awviz_common::RosTopicDisplay<autoware_perception_msgs::msg::TrackedObjects>
{
public:
/**
* @brief Construct a new object.
*/
TrackedObjectsDisplay();

protected:
/**
* @todo Add support of logging shortened uuids of approximately length 8.
*/
void log_message(autoware_perception_msgs::msg::TrackedObjects::ConstSharedPtr msg) override;
};
} // namespace awviz_plugin

#endif // AWVIZ_PLUGIN__AUTOWARE_PERCEPTION__TRACKED_OBJECTS_DISPLAY_HPP_
5 changes: 5 additions & 0 deletions awviz_plugin/plugin_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@
<description>Display from autoware_perception_msgs/msg/DetectedObjects message.</description>
<message_type>autoware_perception_msgs/msg/DetectedObjects</message_type>
</class>
<class name="awviz_plugin/TrackedObjectsDisplay" type="awviz_plugin::TrackedObjectsDisplay"
base_class_type="awviz_common::Display">
<description>Display from autoware_perception_msgs/msg/TrackedObjects message.</description>
<message_type>autoware_perception_msgs/msg/TrackedObjects</message_type>
</class>
</library>
60 changes: 60 additions & 0 deletions awviz_plugin/src/autoware_perception/tracked_objects_display.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2024 Kotaro Uetake.
//
// 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 "awviz_plugin/autoware_perception/tracked_objects_display.hpp"

#include <rerun.hpp>

namespace awviz_plugin
{
TrackedObjectsDisplay::TrackedObjectsDisplay()
: awviz_common::RosTopicDisplay<autoware_perception_msgs::msg::TrackedObjects>()
{
}

void TrackedObjectsDisplay::log_message(
autoware_perception_msgs::msg::TrackedObjects::ConstSharedPtr msg)
{
stream_->set_time_seconds(
TIMELINE_NAME, rclcpp::Time(msg->header.stamp.sec, msg->header.stamp.nanosec).seconds());

const auto entity_path = property_.entity(msg->header.frame_id);
if (!entity_path) {
stream_->log(property_.topic(), rerun::TextLog("There is no corresponding entity path"));
return;
}

std::vector<rerun::Position3D> centers;
std::vector<rerun::HalfSize3D> sizes;
std::vector<rerun::Rotation3D> rotations;
std::vector<rerun::components::ClassId> class_ids;
for (const auto & object : msg->objects) {
const auto & pose = object.kinematics.pose_with_covariance.pose;
const auto & dimensions = object.shape.dimensions;
centers.emplace_back(pose.position.x, pose.position.y, pose.position.z);
sizes.emplace_back(dimensions.x, dimensions.y, dimensions.z);
rotations.emplace_back(rerun::Quaternion::from_wxyz(
pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z));
class_ids.emplace_back(static_cast<uint16_t>(object.classification.front().label));
}

stream_->log(
entity_path.value(), rerun::Boxes3D::from_centers_and_half_sizes(centers, sizes)
.with_rotations(rotations)
.with_class_ids(class_ids));
}
} // namespace awviz_plugin

#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(awviz_plugin::TrackedObjectsDisplay, awviz_common::Display);
1 change: 1 addition & 0 deletions docs/PLUGIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Even if there are ROS messages that are not supported by built-in plugins, we ca
| ROS Package | Message Type | Plugin Type |
| :------------------------- | :---------------- | :----------------------- |
| `autoware_perception_msgs` | `DetectedObjects` | `DetectedObjectsDisplay` |
| | `TrackedObjects` | `TrackedObjectsDisplay` |

## Custom Plugin Definition

Expand Down

0 comments on commit 6304214

Please sign in to comment.