Skip to content

Commit f3cd639

Browse files
authored
fix(autoware_perception_rviz_plugin): improve traffic light visualization transform handling (#17)
Signed-off-by: Y.Hisaki <yhisaki31@gmail.com>
1 parent acfa505 commit f3cd639

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

autoware_perception_rviz_plugin/include/autoware_perception_rviz_plugin/traffic_light/traffic_light_display.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,11 @@ private Q_SLOTS:
134134

135135
// Data storage
136136
lanelet::LaneletMapPtr lanelet_map_;
137+
std_msgs::msg::Header lanelet_map_header_;
138+
137139
autoware_perception_msgs::msg::TrafficLightGroupArray::ConstSharedPtr traffic_light_groups_;
138140
rclcpp::Time last_traffic_light_received_time_;
139141

140-
// Root node for text and shape visualization
141-
Ogre::SceneNode * root_node_{nullptr};
142-
143142
// Text visualization
144143
std::unordered_map<lanelet::Id, Ogre::SceneNode *> traffic_light_text_nodes_;
145144
std::unordered_map<lanelet::Id, std::unique_ptr<rviz_rendering::MovableText>>

autoware_perception_rviz_plugin/src/traffic_light/traffic_light_display.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,9 @@ TrafficLightDisplay::~TrafficLightDisplay() = default;
249249

250250
void TrafficLightDisplay::onInitialize()
251251
{
252-
auto rviz_ros_node = context_->getRosNodeAbstraction();
252+
rviz_common::Display::onInitialize();
253253

254-
// Create scene node for text displays
255-
root_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
254+
auto rviz_ros_node = context_->getRosNodeAbstraction();
256255

257256
lanelet_map_topic_property_ = std::make_unique<rviz_common::properties::RosTopicProperty>(
258257
"Lanelet Map Topic", QString("/map/vector_map"), QString("autoware_map_msgs/msg/LaneletMapBin"),
@@ -307,9 +306,9 @@ void TrafficLightDisplay::setupRosSubscriptions()
307306

308307
void TrafficLightDisplay::onEnable()
309308
{
309+
rviz_common::Display::onEnable();
310310
std::lock_guard<std::mutex> lock_property(property_mutex_);
311311
setupRosSubscriptions();
312-
root_node_->setVisible(true);
313312
for (const auto & [id, text_node] : traffic_light_text_nodes_) {
314313
text_node->setVisible(show_text_property_->getBool());
315314
}
@@ -320,10 +319,10 @@ void TrafficLightDisplay::onEnable()
320319

321320
void TrafficLightDisplay::onDisable()
322321
{
322+
rviz_common::Display::onDisable();
323323
std::lock_guard<std::mutex> lock_property(property_mutex_);
324324
lanelet_map_sub_.reset();
325325
traffic_light_group_array_sub_.reset();
326-
root_node_->setVisible(false);
327326
for (const auto & [id, text_node] : traffic_light_text_nodes_) {
328327
text_node->setVisible(false);
329328
}
@@ -353,10 +352,6 @@ void TrafficLightDisplay::reset()
353352
// Reset subscriptions
354353
lanelet_map_sub_.reset();
355354
traffic_light_group_array_sub_.reset();
356-
357-
if (root_node_) {
358-
root_node_->removeAndDestroyAllChildren();
359-
}
360355
}
361356

362357
void TrafficLightDisplay::hideAllDisplays()
@@ -398,7 +393,7 @@ void TrafficLightDisplay::updateTrafficLightText(
398393
}
399394

400395
if (traffic_light_text_nodes_.find(info.id) == traffic_light_text_nodes_.end()) {
401-
traffic_light_text_nodes_[info.id] = root_node_->createChildSceneNode();
396+
traffic_light_text_nodes_[info.id] = scene_node_->createChildSceneNode();
402397
traffic_light_text_nodes_[info.id]->attachObject(traffic_light_text_displays_[info.id].get());
403398
}
404399

@@ -425,7 +420,7 @@ void TrafficLightDisplay::updateTrafficLightBulbs(
425420
for (const auto & bulb : current_bulbs) {
426421
if (traffic_light_bulb_displays_.find(bulb.id) == traffic_light_bulb_displays_.end()) {
427422
auto bulb_display = std::make_unique<rviz_rendering::Shape>(
428-
rviz_rendering::Shape::Type::Sphere, scene_manager_, root_node_);
423+
rviz_rendering::Shape::Type::Sphere, scene_manager_, scene_node_);
429424

430425
Ogre::ColourValue color;
431426
if (bulb.color == "red") {
@@ -460,6 +455,17 @@ void TrafficLightDisplay::update(float wall_dt, float ros_dt)
460455
return;
461456
}
462457

458+
Ogre::Vector3 position;
459+
Ogre::Quaternion orientation;
460+
if (!this->context_->getFrameManager()->getTransform(
461+
lanelet_map_header_, position, orientation)) {
462+
RCLCPP_DEBUG(
463+
rclcpp::get_logger("TrafficLightDisplay"), "Error transforming from frame '%s' to frame '%s'",
464+
lanelet_map_header_.frame_id.c_str(), qPrintable(this->fixed_frame_));
465+
}
466+
this->scene_node_->setPosition(position);
467+
this->scene_node_->setOrientation(orientation);
468+
463469
if (checkTimeout()) {
464470
hideAllDisplays();
465471
return;
@@ -509,6 +515,7 @@ void TrafficLightDisplay::onLaneletMapReceived(
509515
const autoware_map_msgs::msg::LaneletMapBin::ConstSharedPtr msg)
510516
{
511517
std::lock_guard<std::mutex> lock(lanelet_map_mutex_);
518+
lanelet_map_header_ = msg->header;
512519
lanelet_map_ = std::make_shared<lanelet::LaneletMap>();
513520
lanelet::utils::conversion::fromBinMsg(*msg, lanelet_map_);
514521
}

0 commit comments

Comments
 (0)