Skip to content

Commit

Permalink
feat(behavior_velocity): support new traffic signal interface
Browse files Browse the repository at this point in the history
Signed-off-by: Tomohito Ando <tomohito.ando@tier4.jp>
  • Loading branch information
TomohitoAndo committed Jun 30, 2023
1 parent 75eecc7 commit 1e5bf66
Show file tree
Hide file tree
Showing 23 changed files with 140 additions and 196 deletions.
6 changes: 3 additions & 3 deletions common/tier4_traffic_light_rviz_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ This plugin panel publishes dummy traffic light signals.

### Output

| Name | Type | Description |
| ------------------------------------------------------- | -------------------------------------------------------- | ----------------------------- |
| `/perception/traffic_light_recognition/traffic_signals` | `autoware_auto_perception_msgs::msg::TrafficSignalArray` | Publish traffic light signals |
| Name | Type | Description |
| ------------------------------------------------------- | --------------------------------------------------- | ----------------------------- |
| `/perception/traffic_light_recognition/traffic_signals` | `autoware_perception_msgs::msg::TrafficSignalArray` | Publish traffic light signals |

## HowToUse

Expand Down
2 changes: 1 addition & 1 deletion common/tier4_traffic_light_rviz_plugin/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>autoware_auto_mapping_msgs</depend>
<depend>autoware_auto_perception_msgs</depend>
<depend>autoware_perception_msgs</depend>
<depend>lanelet2_extension</depend>
<depend>libqt5-core</depend>
<depend>libqt5-gui</depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <utility>
#include <vector>

#undef signals
namespace rviz_plugins
{
TrafficLightPublishPanel::TrafficLightPublishPanel(QWidget * parent) : rviz_common::Panel(parent)
Expand Down Expand Up @@ -138,55 +139,55 @@ void TrafficLightPublishPanel::onSetTrafficLightState()
const auto shape = light_shape_combo_->currentText();
const auto status = light_status_combo_->currentText();

TrafficLight traffic_light;
TrafficLightElement traffic_light;
traffic_light.confidence = traffic_light_confidence_input_->value();

if (color == "RED") {
traffic_light.color = TrafficLight::RED;
traffic_light.color = TrafficLightElement::RED;
} else if (color == "AMBER") {
traffic_light.color = TrafficLight::AMBER;
traffic_light.color = TrafficLightElement::AMBER;
} else if (color == "GREEN") {
traffic_light.color = TrafficLight::GREEN;
traffic_light.color = TrafficLightElement::GREEN;
} else if (color == "WHITE") {
traffic_light.color = TrafficLight::WHITE;
traffic_light.color = TrafficLightElement::WHITE;
} else if (color == "UNKNOWN") {
traffic_light.color = TrafficLight::UNKNOWN;
traffic_light.color = TrafficLightElement::UNKNOWN;
}

if (shape == "CIRCLE") {
traffic_light.shape = TrafficLight::CIRCLE;
traffic_light.shape = TrafficLightElement::CIRCLE;
} else if (shape == "LEFT_ARROW") {
traffic_light.shape = TrafficLight::LEFT_ARROW;
traffic_light.shape = TrafficLightElement::LEFT_ARROW;
} else if (shape == "RIGHT_ARROW") {
traffic_light.shape = TrafficLight::RIGHT_ARROW;
traffic_light.shape = TrafficLightElement::RIGHT_ARROW;
} else if (shape == "UP_ARROW") {
traffic_light.shape = TrafficLight::UP_ARROW;
traffic_light.shape = TrafficLightElement::UP_ARROW;
} else if (shape == "DOWN_ARROW") {
traffic_light.shape = TrafficLight::DOWN_ARROW;
traffic_light.shape = TrafficLightElement::DOWN_ARROW;
} else if (shape == "DOWN_LEFT_ARROW") {
traffic_light.shape = TrafficLight::DOWN_LEFT_ARROW;
traffic_light.shape = TrafficLightElement::DOWN_LEFT_ARROW;
} else if (shape == "DOWN_RIGHT_ARROW") {
traffic_light.shape = TrafficLight::DOWN_RIGHT_ARROW;
traffic_light.shape = TrafficLightElement::DOWN_RIGHT_ARROW;
} else if (shape == "UNKNOWN") {
traffic_light.shape = TrafficLight::UNKNOWN;
traffic_light.shape = TrafficLightElement::UNKNOWN;
}

if (status == "SOLID_OFF") {
traffic_light.status = TrafficLight::SOLID_OFF;
traffic_light.status = TrafficLightElement::SOLID_OFF;
} else if (status == "SOLID_ON") {
traffic_light.status = TrafficLight::SOLID_ON;
traffic_light.status = TrafficLightElement::SOLID_ON;
} else if (status == "FLASHING") {
traffic_light.status = TrafficLight::FLASHING;
traffic_light.status = TrafficLightElement::FLASHING;
} else if (status == "UNKNOWN") {
traffic_light.status = TrafficLight::UNKNOWN;
traffic_light.status = TrafficLightElement::UNKNOWN;
}

TrafficSignal traffic_signal;
traffic_signal.lights.push_back(traffic_light);
traffic_signal.map_primitive_id = traffic_light_id;
traffic_signal.elements.push_back(traffic_light);
traffic_signal.traffic_signal_id = traffic_light_id;

for (auto & signal : extra_traffic_signals_.signals) {
if (signal.map_primitive_id == traffic_light_id) {
if (signal.traffic_signal_id == traffic_light_id) {
signal = traffic_signal;
return;
}
Expand Down Expand Up @@ -247,7 +248,7 @@ void TrafficLightPublishPanel::createWallTimer()
void TrafficLightPublishPanel::onTimer()
{
if (enable_publish_) {
extra_traffic_signals_.header.stamp = rclcpp::Clock().now();
extra_traffic_signals_.stamp = rclcpp::Clock().now();
pub_traffic_signals_->publish(extra_traffic_signals_);
}

Expand All @@ -260,35 +261,35 @@ void TrafficLightPublishPanel::onTimer()
for (size_t i = 0; i < extra_traffic_signals_.signals.size(); ++i) {
const auto & signal = extra_traffic_signals_.signals.at(i);

if (signal.lights.empty()) {
if (signal.elements.empty()) {
continue;
}

auto id_label = new QLabel(QString::number(signal.map_primitive_id));
auto id_label = new QLabel(QString::number(signal.traffic_signal_id));
id_label->setAlignment(Qt::AlignCenter);

auto color_label = new QLabel();
color_label->setAlignment(Qt::AlignCenter);

const auto & light = signal.lights.front();
const auto & light = signal.elements.front();
switch (light.color) {
case TrafficLight::RED:
case TrafficLightElement::RED:
color_label->setText("RED");
color_label->setStyleSheet("background-color: #FF0000;");
break;
case TrafficLight::AMBER:
case TrafficLightElement::AMBER:
color_label->setText("AMBER");
color_label->setStyleSheet("background-color: #FFBF00;");
break;
case TrafficLight::GREEN:
case TrafficLightElement::GREEN:
color_label->setText("GREEN");
color_label->setStyleSheet("background-color: #7CFC00;");
break;
case TrafficLight::WHITE:
case TrafficLightElement::WHITE:
color_label->setText("WHITE");
color_label->setStyleSheet("background-color: #FFFFFF;");
break;
case TrafficLight::UNKNOWN:
case TrafficLightElement::UNKNOWN:
color_label->setText("UNKNOWN");
color_label->setStyleSheet("background-color: #808080;");
break;
Expand All @@ -300,31 +301,28 @@ void TrafficLightPublishPanel::onTimer()
shape_label->setAlignment(Qt::AlignCenter);

switch (light.shape) {
case TrafficLight::CIRCLE:
case TrafficLightElement::CIRCLE:
shape_label->setText("CIRCLE");
break;
case TrafficLight::LEFT_ARROW:
case TrafficLightElement::LEFT_ARROW:
shape_label->setText("LEFT_ARROW");
break;
case TrafficLight::RIGHT_ARROW:
case TrafficLightElement::RIGHT_ARROW:
shape_label->setText("RIGHT_ARROW");
break;
case TrafficLight::UP_ARROW:
case TrafficLightElement::UP_ARROW:
shape_label->setText("UP_ARROW");
break;
case TrafficLight::DOWN_ARROW:
case TrafficLightElement::DOWN_ARROW:
shape_label->setText("DOWN_ARROW");
break;
case TrafficLight::DOWN_LEFT_ARROW:
case TrafficLightElement::DOWN_LEFT_ARROW:
shape_label->setText("DOWN_LEFT_ARROW");
break;
case TrafficLight::DOWN_RIGHT_ARROW:
case TrafficLightElement::DOWN_RIGHT_ARROW:
shape_label->setText("DOWN_RIGHT_ARROW");
break;
case TrafficLight::FLASHING:
shape_label->setText("FLASHING");
break;
case TrafficLight::UNKNOWN:
case TrafficLightElement::UNKNOWN:
shape_label->setText("UNKNOWN");
break;
default:
Expand All @@ -335,16 +333,16 @@ void TrafficLightPublishPanel::onTimer()
status_label->setAlignment(Qt::AlignCenter);

switch (light.status) {
case TrafficLight::SOLID_OFF:
case TrafficLightElement::SOLID_OFF:
status_label->setText("SOLID_OFF");
break;
case TrafficLight::SOLID_ON:
case TrafficLightElement::SOLID_ON:
status_label->setText("SOLID_ON");
break;
case TrafficLight::FLASHING:
case TrafficLightElement::FLASHING:
status_label->setText("FLASHING");
break;
case TrafficLight::UNKNOWN:
case TrafficLightElement::UNKNOWN:
status_label->setText("UNKNOWN");
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <rviz_common/panel.hpp>

#include <autoware_auto_mapping_msgs/msg/had_map_bin.hpp>
#include <autoware_auto_perception_msgs/msg/traffic_signal_array.hpp>
#include <autoware_perception_msgs/msg/traffic_signal_array.hpp>
#endif

#include <set>
Expand All @@ -36,10 +36,9 @@ namespace rviz_plugins
{

using autoware_auto_mapping_msgs::msg::HADMapBin;
using autoware_auto_perception_msgs::msg::TrafficLight;
using autoware_auto_perception_msgs::msg::TrafficSignal;
using autoware_auto_perception_msgs::msg::TrafficSignalArray;

using autoware_perception_msgs::msg::TrafficLightElement;
using autoware_perception_msgs::msg::TrafficSignal;
using autoware_perception_msgs::msg::TrafficSignalArray;
class TrafficLightPublishPanel : public rviz_common::Panel
{
Q_OBJECT
Expand Down
1 change: 1 addition & 0 deletions planning/behavior_velocity_crosswalk_module/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<buildtool_depend>autoware_cmake</buildtool_depend>
<buildtool_depend>eigen3_cmake_module</buildtool_depend>

<depend>autoware_perception_msgs</depend>
<depend>autoware_auto_perception_msgs</depend>
<depend>autoware_auto_planning_msgs</depend>
<depend>autoware_auto_tf2</depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,16 +878,16 @@ bool CrosswalkModule::isRedSignalForPedestrians() const

if (
planner_param_.tl_state_timeout <
(clock_->now() - traffic_signal_stamped->header.stamp).seconds()) {
(clock_->now() - traffic_signal_stamped->stamp).seconds()) {
continue;
}

const auto & lights = traffic_signal_stamped->signal.lights;
const auto & lights = traffic_signal_stamped->signal.elements;
if (lights.empty()) {
continue;
}

if (lights.front().color == TrafficLight::RED) {
if (lights.front().color == TrafficLightElement::RED) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ namespace behavior_velocity_planner
using autoware_auto_perception_msgs::msg::ObjectClassification;
using autoware_auto_perception_msgs::msg::PredictedObject;
using autoware_auto_perception_msgs::msg::PredictedObjects;
using autoware_auto_perception_msgs::msg::TrafficLight;
using autoware_auto_planning_msgs::msg::PathWithLaneId;
using autoware_perception_msgs::msg::TrafficLightElement;
using lanelet::autoware::Crosswalk;
using tier4_api_msgs::msg::CrosswalkStatus;
using tier4_autoware_utils::StopWatch;
Expand Down
1 change: 1 addition & 0 deletions planning/behavior_velocity_intersection_module/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>autoware_perception_msgs</depend>
<depend>autoware_auto_perception_msgs</depend>
<depend>autoware_auto_planning_msgs</depend>
<depend>behavior_velocity_planner_common</depend>
Expand Down
18 changes: 8 additions & 10 deletions planning/behavior_velocity_intersection_module/src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,10 @@ bool hasAssociatedTrafficLight(lanelet::ConstLanelet lane)
}

bool isTrafficLightArrowActivated(
lanelet::ConstLanelet lane,
const std::map<int, autoware_auto_perception_msgs::msg::TrafficSignalStamped> & tl_infos)
lanelet::ConstLanelet lane, const std::map<int, TrafficSignalStamped> & tl_infos)
{
using TrafficLightElement = autoware_perception_msgs::msg::TrafficLightElement;

const auto & turn_direction = lane.attributeOr("turn_direction", "else");
std::optional<int> tl_id = std::nullopt;
for (auto && tl_reg_elem : lane.regulatoryElementsAs<lanelet::TrafficLight>()) {
Expand All @@ -687,16 +688,13 @@ bool isTrafficLightArrowActivated(
return false;
}
const auto & tl_info = tl_info_it->second;
for (auto && tl_light : tl_info.signal.lights) {
if (tl_light.color != autoware_auto_perception_msgs::msg::TrafficLight::GREEN) continue;
if (tl_light.status != autoware_auto_perception_msgs::msg::TrafficLight::SOLID_ON) continue;
if (
turn_direction == std::string("left") &&
tl_light.shape == autoware_auto_perception_msgs::msg::TrafficLight::LEFT_ARROW)
for (auto && tl_light : tl_info.signal.elements) {
if (tl_light.color != TrafficLightElement::GREEN) continue;
if (tl_light.status != TrafficLightElement::SOLID_ON) continue;
if (turn_direction == std::string("left") && tl_light.shape == TrafficLightElement::LEFT_ARROW)
return true;
if (
turn_direction == std::string("right") &&
tl_light.shape == autoware_auto_perception_msgs::msg::TrafficLight::RIGHT_ARROW)
turn_direction == std::string("right") && tl_light.shape == TrafficLightElement::RIGHT_ARROW)
return true;
}
return false;
Expand Down
3 changes: 1 addition & 2 deletions planning/behavior_velocity_intersection_module/src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ std::optional<Polygon2d> getIntersectionArea(

bool hasAssociatedTrafficLight(lanelet::ConstLanelet lane);
bool isTrafficLightArrowActivated(
lanelet::ConstLanelet lane,
const std::map<int, autoware_auto_perception_msgs::msg::TrafficSignalStamped> & tl_infos);
lanelet::ConstLanelet lane, const std::map<int, TrafficSignalStamped> & tl_infos);

std::vector<DescritizedLane> generateDetectionLaneDivisions(
lanelet::ConstLanelets detection_lanelets,
Expand Down
18 changes: 9 additions & 9 deletions planning/behavior_velocity_planner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ So for example, in order to stop at a stop line with the vehicles' front on the

## Input topics

| Name | Type | Description |
| ----------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| `~input/path_with_lane_id` | autoware_auto_planning_msgs::msg::PathWithLaneId | path with lane_id |
| `~input/vector_map` | autoware_auto_mapping_msgs::msg::HADMapBin | vector map |
| `~input/vehicle_odometry` | nav_msgs::msg::Odometry | vehicle velocity |
| `~input/dynamic_objects` | autoware_auto_perception_msgs::msg::PredictedObjects | dynamic objects |
| `~input/no_ground_pointcloud` | sensor_msgs::msg::PointCloud2 | obstacle pointcloud |
| `~/input/compare_map_filtered_pointcloud` | sensor_msgs::msg::PointCloud2 | obstacle pointcloud filtered by compare map. Note that this is used only when the detection method of run out module is Points. |
| `~input/traffic_signals` | autoware_auto_perception_msgs::msg::TrafficSignalArray | traffic light states |
| Name | Type | Description |
| ----------------------------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `~input/path_with_lane_id` | autoware_auto_planning_msgs::msg::PathWithLaneId | path with lane_id |
| `~input/vector_map` | autoware_auto_mapping_msgs::msg::HADMapBin | vector map |
| `~input/vehicle_odometry` | nav_msgs::msg::Odometry | vehicle velocity |
| `~input/dynamic_objects` | autoware_auto_perception_msgs::msg::PredictedObjects | dynamic objects |
| `~input/no_ground_pointcloud` | sensor_msgs::msg::PointCloud2 | obstacle pointcloud |
| `~/input/compare_map_filtered_pointcloud` | sensor_msgs::msg::PointCloud2 | obstacle pointcloud filtered by compare map. Note that this is used only when the detection method of run out module is Points. |
| `~input/traffic_signals` | autoware_perception_msgs::msg::TrafficSignalArray | traffic light states |

## Output topics

Expand Down
10 changes: 5 additions & 5 deletions planning/behavior_velocity_planner/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ BehaviorVelocityPlannerNode::BehaviorVelocityPlannerNode(const rclcpp::NodeOptio
std::bind(&BehaviorVelocityPlannerNode::onLaneletMap, this, _1),
createSubscriptionOptions(this));
sub_traffic_signals_ =
this->create_subscription<autoware_auto_perception_msgs::msg::TrafficSignalArray>(
this->create_subscription<autoware_perception_msgs::msg::TrafficSignalArray>(
"~/input/traffic_signals", 1,
std::bind(&BehaviorVelocityPlannerNode::onTrafficSignals, this, _1),
createSubscriptionOptions(this));
Expand Down Expand Up @@ -287,15 +287,15 @@ void BehaviorVelocityPlannerNode::onLaneletMap(
}

void BehaviorVelocityPlannerNode::onTrafficSignals(
const autoware_auto_perception_msgs::msg::TrafficSignalArray::ConstSharedPtr msg)
const autoware_perception_msgs::msg::TrafficSignalArray::ConstSharedPtr msg)
{
std::lock_guard<std::mutex> lock(mutex_);

for (const auto & signal : msg->signals) {
autoware_auto_perception_msgs::msg::TrafficSignalStamped traffic_signal;
traffic_signal.header = msg->header;
TrafficSignalStamped traffic_signal;
traffic_signal.stamp = msg->stamp;
traffic_signal.signal = signal;
planner_data_.traffic_light_id_map[signal.map_primitive_id] = traffic_signal;
planner_data_.traffic_light_id_map[signal.traffic_signal_id] = traffic_signal;
}
}

Expand Down
Loading

0 comments on commit 1e5bf66

Please sign in to comment.