Skip to content

Commit acfa505

Browse files
authored
feat(autoware_perception_rviz_plugin): add traffic light display (#15)
* feat(autoware_traffic_light_rviz_plugin): add traffic light display Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> * update README.md Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> * fix copyright Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> * support without buble Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> --------- Signed-off-by: Y.Hisaki <yhisaki31@gmail.com>
1 parent c5f0baa commit acfa505

7 files changed

Lines changed: 728 additions & 0 deletions

File tree

autoware_perception_rviz_plugin/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(OD_PLUGIN_LIB_SRC
1010
src/object_detection/detected_objects_display.cpp
1111
src/object_detection/tracked_objects_display.cpp
1212
src/object_detection/predicted_objects_display.cpp
13+
src/traffic_light/traffic_light_display.cpp
1314
)
1415

1516
set(OD_PLUGIN_LIB_HEADERS
@@ -19,6 +20,7 @@ set(OD_PLUGIN_LIB_HEADERS_TO_WRAP
1920
include/autoware_perception_rviz_plugin/object_detection/detected_objects_display.hpp
2021
include/autoware_perception_rviz_plugin/object_detection/tracked_objects_display.hpp
2122
include/autoware_perception_rviz_plugin/object_detection/predicted_objects_display.hpp
23+
include/autoware_perception_rviz_plugin/traffic_light/traffic_light_display.hpp
2224
)
2325

2426
set(COMMON_HEADERS
@@ -53,6 +55,12 @@ target_include_directories(${PROJECT_NAME} PRIVATE include)
5355
target_compile_definitions(${PROJECT_NAME} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
5456
target_compile_definitions(${PROJECT_NAME} PRIVATE "OBJECT_DETECTION_PLUGINS_BUILDING_LIBRARY")
5557

58+
if(TARGET rviz_ogre_vendor::OgreMain)
59+
get_target_property(OGRE_INCLUDE_DIRS rviz_ogre_vendor::OgreMain INTERFACE_INCLUDE_DIRECTORIES)
60+
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${OGRE_INCLUDE_DIRS})
61+
endif()
62+
63+
5664
# Export the plugin to be imported by rviz2
5765
pluginlib_export_plugin_description_file(rviz_common plugins_description.xml)
5866

autoware_perception_rviz_plugin/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,34 @@ Overwrite prediction results with tracking results.
5555

5656
![predicted-object-visualization-description](./images/predicted-object-visualization-description.jpg)
5757

58+
### TrafficLight
59+
60+
#### Input Types
61+
62+
| Name | Type | Description |
63+
| ------------------- | ------------------------------------------------------- | ------------------------------------------- |
64+
| Lanelet Map | `autoware_map_msgs::msg::LaneletMapBin` | Map data containing traffic light positions |
65+
| Traffic Light State | `autoware_perception_msgs::msg::TrafficLightGroupArray` | Traffic light recognition results |
66+
67+
#### Visualization Result
68+
69+
The plugin visualizes traffic light states in two ways:
70+
71+
1. Text display showing the current state (RED, AMBER, GREEN, directional arrows)
72+
2. 3D spheres representing the light bulbs, colored according to their state
73+
74+
![traffic-light-visualization-description](./images/traffic-light-visualization-description.jpg)
75+
76+
##### Customizable Features
77+
78+
- Text position offset (X, Y, Z)
79+
- Text font size and color
80+
- Text prefix
81+
- Show/hide text display
82+
- Show/hide bulb visualization
83+
- Timeout for stale data
84+
- Topic names for both input types
85+
5886
## References/External links
5987

6088
[1] <https://gitlab.com/autowarefoundation/autoware.auto/AutowareAuto/-/tree/master/src/tools/visualization/autoware_rviz_plugins>
76.3 KB
Loading
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
//
2+
// Copyright 2025 TIER IV, Inc. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#ifndef AUTOWARE_PERCEPTION_RVIZ_PLUGIN__TRAFFIC_LIGHT__TRAFFIC_LIGHT_DISPLAY_HPP_
17+
#define AUTOWARE_PERCEPTION_RVIZ_PLUGIN__TRAFFIC_LIGHT__TRAFFIC_LIGHT_DISPLAY_HPP_
18+
19+
#include "rviz_common/properties/ros_topic_property.hpp"
20+
#include "rviz_rendering/objects/shape.hpp"
21+
22+
#include <rclcpp/rclcpp.hpp>
23+
#include <rviz_common/display.hpp>
24+
#include <rviz_common/properties/bool_property.hpp>
25+
#include <rviz_common/properties/color_property.hpp>
26+
#include <rviz_common/properties/float_property.hpp>
27+
#include <rviz_common/properties/string_property.hpp>
28+
#include <rviz_rendering/objects/movable_text.hpp>
29+
30+
#include <autoware_map_msgs/msg/lanelet_map_bin.hpp>
31+
#include <autoware_perception_msgs/msg/traffic_light_group_array.hpp>
32+
33+
#include <boost/optional/optional.hpp>
34+
35+
#include <OgreSceneNode.h>
36+
#include <lanelet2_core/LaneletMap.h>
37+
#include <lanelet2_core/primitives/Lanelet.h>
38+
39+
#include <memory>
40+
#include <optional>
41+
#include <string>
42+
#include <unordered_map>
43+
#include <vector>
44+
45+
namespace autoware_perception_rviz_plugin::traffic_light
46+
{
47+
48+
struct Point3d
49+
{
50+
double x;
51+
double y;
52+
double z;
53+
};
54+
55+
struct TrafficLightBulbInfo
56+
{
57+
lanelet::Id id;
58+
std::string color;
59+
std::string shape;
60+
Point3d position;
61+
};
62+
63+
struct TrafficLightInfo
64+
{
65+
lanelet::Id id;
66+
lanelet::ConstLineString3d linestring;
67+
boost::optional<double> height;
68+
std::vector<TrafficLightBulbInfo> bulbs;
69+
70+
[[nodiscard]] TrafficLightBulbInfo getEstimatedBulb(const std::string & color) const;
71+
72+
[[nodiscard]] Point3d getLinestringCenter() const;
73+
74+
[[nodiscard]] std::vector<TrafficLightBulbInfo> getBlightBulbs(
75+
const std::vector<autoware_perception_msgs::msg::TrafficLightElement> & current_elements) const;
76+
};
77+
78+
class TrafficLightDisplay : public rviz_common::Display
79+
{
80+
Q_OBJECT
81+
82+
public:
83+
TrafficLightDisplay();
84+
~TrafficLightDisplay() override;
85+
86+
protected:
87+
void onInitialize() override;
88+
void reset() override;
89+
void update(float wall_dt, float ros_dt) override;
90+
void onEnable() override;
91+
void onDisable() override;
92+
93+
private Q_SLOTS:
94+
void topic_updated_lanelet_map();
95+
void topic_updated_traffic_light();
96+
97+
private: // NOLINT
98+
// Display methods
99+
void hideAllDisplays();
100+
void updateTrafficLightText(const TrafficLightInfo & info, const std::string & state_text);
101+
void updateTrafficLightBulbs(
102+
const TrafficLightInfo & info,
103+
const std::vector<autoware_perception_msgs::msg::TrafficLightElement> & elements);
104+
bool checkTimeout() const;
105+
106+
// Properties
107+
std::unique_ptr<rviz_common::properties::RosTopicProperty> lanelet_map_topic_property_;
108+
std::unique_ptr<rviz_common::properties::RosTopicProperty> traffic_light_topic_property_;
109+
std::unique_ptr<rviz_common::properties::FloatProperty> timeout_property_;
110+
std::unique_ptr<rviz_common::properties::FloatProperty> text_z_offset_property_;
111+
std::unique_ptr<rviz_common::properties::FloatProperty> text_x_offset_property_;
112+
std::unique_ptr<rviz_common::properties::FloatProperty> text_y_offset_property_;
113+
std::unique_ptr<rviz_common::properties::BoolProperty> show_text_property_;
114+
std::unique_ptr<rviz_common::properties::BoolProperty> show_bulb_property_;
115+
std::unique_ptr<rviz_common::properties::StringProperty> text_prefix_property_;
116+
std::unique_ptr<rviz_common::properties::FloatProperty> font_size_property_;
117+
std::unique_ptr<rviz_common::properties::ColorProperty> text_color_property_;
118+
std::unique_ptr<rviz_common::properties::FloatProperty> bulb_radius_property_;
119+
120+
// Subscribers
121+
rclcpp::Subscription<autoware_map_msgs::msg::LaneletMapBin>::SharedPtr lanelet_map_sub_;
122+
rclcpp::Subscription<autoware_perception_msgs::msg::TrafficLightGroupArray>::SharedPtr
123+
traffic_light_group_array_sub_;
124+
125+
// Callback functions
126+
void onLaneletMapReceived(const autoware_map_msgs::msg::LaneletMapBin::ConstSharedPtr msg);
127+
void onTrafficLightGroupArrayReceived(
128+
const autoware_perception_msgs::msg::TrafficLightGroupArray::ConstSharedPtr msg);
129+
130+
std::mutex property_mutex_;
131+
std::mutex lanelet_map_mutex_;
132+
std::mutex traffic_light_mutex_;
133+
void setupRosSubscriptions();
134+
135+
// Data storage
136+
lanelet::LaneletMapPtr lanelet_map_;
137+
autoware_perception_msgs::msg::TrafficLightGroupArray::ConstSharedPtr traffic_light_groups_;
138+
rclcpp::Time last_traffic_light_received_time_;
139+
140+
// Root node for text and shape visualization
141+
Ogre::SceneNode * root_node_{nullptr};
142+
143+
// Text visualization
144+
std::unordered_map<lanelet::Id, Ogre::SceneNode *> traffic_light_text_nodes_;
145+
std::unordered_map<lanelet::Id, std::unique_ptr<rviz_rendering::MovableText>>
146+
traffic_light_text_displays_;
147+
148+
// Shape visualization
149+
std::unordered_map<lanelet::Id, std::unique_ptr<rviz_rendering::Shape>>
150+
traffic_light_bulb_displays_;
151+
};
152+
153+
} // namespace autoware_perception_rviz_plugin::traffic_light
154+
155+
#endif // AUTOWARE_PERCEPTION_RVIZ_PLUGIN__TRAFFIC_LIGHT__TRAFFIC_LIGHT_DISPLAY_HPP_

autoware_perception_rviz_plugin/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<build_depend>libboost-dev</build_depend>
1717
<build_depend>qtbase5-dev</build_depend>
1818

19+
<depend>autoware_lanelet2_extension</depend>
20+
<depend>autoware_map_msgs</depend>
1921
<depend>autoware_perception_msgs</depend>
2022
<depend>rviz_common</depend>
2123
<depend>rviz_default_plugins</depend>

autoware_perception_rviz_plugin/plugins_description.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@
2323
<message_type>autoware_perception_msgs/msg/DetectedObjects</message_type>
2424
</class>
2525

26+
<class name="autoware_perception_rviz_plugin/TrafficLight"
27+
type="autoware_perception_rviz_plugin::traffic_light::TrafficLightDisplay"
28+
base_class_type="rviz_common::Display">
29+
<description>Traffic light display plugin for Autoware</description>
30+
</class>
31+
2632
</library>

0 commit comments

Comments
 (0)