Skip to content

Commit 6304214

Browse files
authored
feat: add support of displaying TrackedObjects (#39)
Signed-off-by: ktro2828 <[email protected]>
1 parent 35f8f96 commit 6304214

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2024 Kotaro Uetake.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef AWVIZ_PLUGIN__AUTOWARE_PERCEPTION__TRACKED_OBJECTS_DISPLAY_HPP_
16+
#define AWVIZ_PLUGIN__AUTOWARE_PERCEPTION__TRACKED_OBJECTS_DISPLAY_HPP_
17+
18+
#include <awviz_common/display.hpp>
19+
20+
#include <autoware_perception_msgs/msg/tracked_objects.hpp>
21+
22+
namespace awviz_plugin
23+
{
24+
class TrackedObjectsDisplay
25+
: public awviz_common::RosTopicDisplay<autoware_perception_msgs::msg::TrackedObjects>
26+
{
27+
public:
28+
/**
29+
* @brief Construct a new object.
30+
*/
31+
TrackedObjectsDisplay();
32+
33+
protected:
34+
/**
35+
* @todo Add support of logging shortened uuids of approximately length 8.
36+
*/
37+
void log_message(autoware_perception_msgs::msg::TrackedObjects::ConstSharedPtr msg) override;
38+
};
39+
} // namespace awviz_plugin
40+
41+
#endif // AWVIZ_PLUGIN__AUTOWARE_PERCEPTION__TRACKED_OBJECTS_DISPLAY_HPP_

awviz_plugin/plugin_description.xml

+5
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@
2626
<description>Display from autoware_perception_msgs/msg/DetectedObjects message.</description>
2727
<message_type>autoware_perception_msgs/msg/DetectedObjects</message_type>
2828
</class>
29+
<class name="awviz_plugin/TrackedObjectsDisplay" type="awviz_plugin::TrackedObjectsDisplay"
30+
base_class_type="awviz_common::Display">
31+
<description>Display from autoware_perception_msgs/msg/TrackedObjects message.</description>
32+
<message_type>autoware_perception_msgs/msg/TrackedObjects</message_type>
33+
</class>
2934
</library>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2024 Kotaro Uetake.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "awviz_plugin/autoware_perception/tracked_objects_display.hpp"
16+
17+
#include <rerun.hpp>
18+
19+
namespace awviz_plugin
20+
{
21+
TrackedObjectsDisplay::TrackedObjectsDisplay()
22+
: awviz_common::RosTopicDisplay<autoware_perception_msgs::msg::TrackedObjects>()
23+
{
24+
}
25+
26+
void TrackedObjectsDisplay::log_message(
27+
autoware_perception_msgs::msg::TrackedObjects::ConstSharedPtr msg)
28+
{
29+
stream_->set_time_seconds(
30+
TIMELINE_NAME, rclcpp::Time(msg->header.stamp.sec, msg->header.stamp.nanosec).seconds());
31+
32+
const auto entity_path = property_.entity(msg->header.frame_id);
33+
if (!entity_path) {
34+
stream_->log(property_.topic(), rerun::TextLog("There is no corresponding entity path"));
35+
return;
36+
}
37+
38+
std::vector<rerun::Position3D> centers;
39+
std::vector<rerun::HalfSize3D> sizes;
40+
std::vector<rerun::Rotation3D> rotations;
41+
std::vector<rerun::components::ClassId> class_ids;
42+
for (const auto & object : msg->objects) {
43+
const auto & pose = object.kinematics.pose_with_covariance.pose;
44+
const auto & dimensions = object.shape.dimensions;
45+
centers.emplace_back(pose.position.x, pose.position.y, pose.position.z);
46+
sizes.emplace_back(dimensions.x, dimensions.y, dimensions.z);
47+
rotations.emplace_back(rerun::Quaternion::from_wxyz(
48+
pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z));
49+
class_ids.emplace_back(static_cast<uint16_t>(object.classification.front().label));
50+
}
51+
52+
stream_->log(
53+
entity_path.value(), rerun::Boxes3D::from_centers_and_half_sizes(centers, sizes)
54+
.with_rotations(rotations)
55+
.with_class_ids(class_ids));
56+
}
57+
} // namespace awviz_plugin
58+
59+
#include <pluginlib/class_list_macros.hpp>
60+
PLUGINLIB_EXPORT_CLASS(awviz_plugin::TrackedObjectsDisplay, awviz_common::Display);

docs/PLUGIN.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Even if there are ROS messages that are not supported by built-in plugins, we ca
2020
| ROS Package | Message Type | Plugin Type |
2121
| :------------------------- | :---------------- | :----------------------- |
2222
| `autoware_perception_msgs` | `DetectedObjects` | `DetectedObjectsDisplay` |
23+
| | `TrackedObjects` | `TrackedObjectsDisplay` |
2324

2425
## Custom Plugin Definition
2526

0 commit comments

Comments
 (0)