Skip to content

Commit 5b6c046

Browse files
committed
Review changes
1 parent 9c1f244 commit 5b6c046

File tree

15 files changed

+77
-74
lines changed

15 files changed

+77
-74
lines changed

simulation/behavior_tree_plugin/include/behavior_tree_plugin/action_node.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <traffic_simulator/traffic_lights/traffic_lights.hpp>
3232
#include <traffic_simulator/utils/lanelet_map.hpp>
3333
#include <traffic_simulator/utils/pose.hpp>
34+
#include <traffic_simulator_msgs/msg/behavior_parameter.hpp>
3435
#include <traffic_simulator_msgs/msg/obstacle.hpp>
3536
#include <traffic_simulator_msgs/msg/waypoints_array.hpp>
3637
#include <unordered_map>
@@ -86,7 +87,8 @@ class ActionNode : public BT::ActionNodeBase
8687
BT::InputPort<std::shared_ptr<traffic_simulator::CanonicalizedEntityStatus>>("canonicalized_entity_status"),
8788
BT::InputPort<std::shared_ptr<traffic_simulator::TrafficLightsBase>>("traffic_lights"),
8889
BT::InputPort<traffic_simulator::behavior::Request>("request"),
89-
BT::InputPort<std::shared_ptr<DistancesMap>>("distances_map"),
90+
BT::InputPort<std::shared_ptr<EuclideanDistancesMap>>("euclidean_distances_map"),
91+
BT::InputPort<traffic_simulator_msgs::msg::BehaviorParameter>("behavior_parameter"),
9092
BT::OutputPort<std::optional<traffic_simulator_msgs::msg::Obstacle>>("obstacle"),
9193
BT::OutputPort<traffic_simulator_msgs::msg::WaypointsArray>("waypoints"),
9294
BT::OutputPort<traffic_simulator::behavior::Request>("request"),
@@ -117,7 +119,8 @@ class ActionNode : public BT::ActionNodeBase
117119
std::optional<double> target_speed;
118120
EntityStatusDict other_entity_status;
119121
lanelet::Ids route_lanelets;
120-
std::shared_ptr<DistancesMap> distances_map;
122+
std::shared_ptr<EuclideanDistancesMap> euclidean_distances_map;
123+
traffic_simulator_msgs::msg::BehaviorParameter behavior_parameter;
121124

122125
auto getDistanceToTargetEntity(
123126
const math::geometry::CatmullRomSplineInterface & spline,

simulation/behavior_tree_plugin/include/behavior_tree_plugin/pedestrian/behavior_tree.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class PedestrianBehaviorTree : public BehaviorPluginBase
7070
DEFINE_GETTER_SETTER(TrafficLights, std::shared_ptr<traffic_simulator::TrafficLightsBase>)
7171
DEFINE_GETTER_SETTER(VehicleParameters, traffic_simulator_msgs::msg::VehicleParameters)
7272
DEFINE_GETTER_SETTER(Waypoints, traffic_simulator_msgs::msg::WaypointsArray)
73-
DEFINE_GETTER_SETTER(DistancesMap, std::shared_ptr<DistancesMap>)
73+
DEFINE_GETTER_SETTER(EuclideanDistancesMap, std::shared_ptr<EuclideanDistancesMap>)
7474
// clang-format on
7575

7676
#undef DEFINE_GETTER_SETTER

simulation/behavior_tree_plugin/include/behavior_tree_plugin/pedestrian/pedestrian_action_node.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class PedestrianActionNode : public ActionNode
3333
{
3434
// clang-format off
3535
return BT::PortsList({
36-
BT::InputPort<traffic_simulator_msgs::msg::BehaviorParameter>("behavior_parameter"),
3736
BT::InputPort<traffic_simulator_msgs::msg::PedestrianParameters>("pedestrian_parameters"),
3837
}) + entity_behavior::ActionNode::providedPorts();
3938
// clang-format on
@@ -42,9 +41,6 @@ class PedestrianActionNode : public ActionNode
4241
auto calculateUpdatedEntityStatusInWorldFrame(double target_speed) const
4342
-> traffic_simulator::EntityStatus;
4443
auto calculateUpdatedEntityStatus(double target_speed) const -> traffic_simulator::EntityStatus;
45-
46-
protected:
47-
traffic_simulator_msgs::msg::BehaviorParameter behavior_parameter;
4844
};
4945
} // namespace entity_behavior
5046

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/behavior_tree.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class VehicleBehaviorTree : public BehaviorPluginBase
7474
DEFINE_GETTER_SETTER(TrafficLights, std::shared_ptr<traffic_simulator::TrafficLightsBase>)
7575
DEFINE_GETTER_SETTER(VehicleParameters, traffic_simulator_msgs::msg::VehicleParameters)
7676
DEFINE_GETTER_SETTER(Waypoints, traffic_simulator_msgs::msg::WaypointsArray)
77-
DEFINE_GETTER_SETTER(DistancesMap, std::shared_ptr<DistancesMap>)
77+
DEFINE_GETTER_SETTER(EuclideanDistancesMap, std::shared_ptr<EuclideanDistancesMap>)
7878
// clang-format on
7979
#undef DEFINE_GETTER_SETTER
8080

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/vehicle_action_node.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class VehicleActionNode : public ActionNode
4343
// clang-format off
4444
return BT::PortsList({
4545
BT::InputPort<std::shared_ptr<math::geometry::CatmullRomSpline>>("reference_trajectory"),
46-
BT::InputPort<traffic_simulator_msgs::msg::BehaviorParameter>("behavior_parameter"),
4746
BT::InputPort<traffic_simulator_msgs::msg::VehicleParameters>("vehicle_parameters")}) +
4847
entity_behavior::ActionNode::providedPorts();
4948
// clang-format on
@@ -56,7 +55,6 @@ class VehicleActionNode : public ActionNode
5655
const traffic_simulator_msgs::msg::WaypointsArray & waypoints) = 0;
5756

5857
protected:
59-
traffic_simulator_msgs::msg::BehaviorParameter behavior_parameter;
6058
traffic_simulator_msgs::msg::VehicleParameters vehicle_parameters;
6159
std::shared_ptr<math::geometry::CatmullRomSpline> reference_trajectory;
6260
std::unique_ptr<math::geometry::CatmullRomSubspline> trajectory;

simulation/behavior_tree_plugin/src/action_node.cpp

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ auto ActionNode::getBlackBoardValues() -> void
9191
if (!getInput<lanelet::Ids>("route_lanelets", route_lanelets)) {
9292
THROW_SIMULATION_ERROR("failed to get input route_lanelets in ActionNode");
9393
}
94-
if (!getInput<std::shared_ptr<DistancesMap>>("distances_map", distances_map)) {
95-
THROW_SIMULATION_ERROR("failed to get input distances_map in ActionNode");
94+
if (!getInput<std::shared_ptr<EuclideanDistancesMap>>(
95+
"euclidean_distances_map", euclidean_distances_map)) {
96+
THROW_SIMULATION_ERROR("failed to get input euclidean_distances_map in ActionNode");
97+
}
98+
if (!getInput<traffic_simulator_msgs::msg::BehaviorParameter>(
99+
"behavior_parameter", behavior_parameter)) {
100+
behavior_parameter = traffic_simulator_msgs::msg::BehaviorParameter();
96101
}
97102
}
98103

@@ -240,34 +245,35 @@ auto ActionNode::getDistanceToFrontEntity(
240245
auto ActionNode::getFrontEntityName(const math::geometry::CatmullRomSplineInterface & spline) const
241246
-> std::optional<std::string>
242247
{
243-
if (distances_map == nullptr) {
244-
return std::nullopt;
245-
}
246-
std::map<double, std::string> rough_distances;
247-
for (const auto & [name_pair, distance] : *distances_map) {
248-
if (
249-
name_pair.first == canonicalized_entity_status->getName() && distance < spline.getLength()) {
250-
rough_distances.emplace(distance, name_pair.second);
251-
} else if (
252-
name_pair.second == canonicalized_entity_status->getName() && distance < spline.getLength()) {
253-
rough_distances.emplace(distance, name_pair.first);
248+
if (euclidean_distances_map != nullptr) {
249+
std::map<double, std::string> euclidean_distances;
250+
double stopDistance = calculateStopDistance(behavior_parameter.dynamic_constraints);
251+
double horizon = spline.getLength() > stopDistance ? spline.getLength() : stopDistance;
252+
for (const auto & [name_pair, euclidean_distance] : *euclidean_distances_map) {
253+
if (euclidean_distance < horizon) {
254+
if (name_pair.first == canonicalized_entity_status->getName()) {
255+
euclidean_distances.emplace(euclidean_distance, name_pair.second);
256+
} else if (name_pair.second == canonicalized_entity_status->getName()) {
257+
euclidean_distances.emplace(euclidean_distance, name_pair.first);
258+
}
259+
}
254260
}
255-
}
256261

257-
for (const auto & [rough_distance, name] : rough_distances) {
258-
const auto quat = math::geometry::getRotation(
259-
canonicalized_entity_status->getMapPose().orientation,
260-
other_entity_status.at(name).getMapPose().orientation);
261-
/**
262-
* @note hard-coded parameter, if the Yaw value of RPY is in ~1.5708 -> 1.5708, entity is a candidate of front entity.
263-
*/
264-
if (
265-
std::fabs(math::geometry::convertQuaternionToEulerAngle(quat).z) <=
266-
boost::math::constants::half_pi<double>()) {
267-
const auto distance = getDistanceToTargetEntity(spline, other_entity_status.at(name));
268-
269-
if (distance && distance.value() < spline.getLength()) {
270-
return name;
262+
for (const auto & [euclidean_distance, name] : euclidean_distances) {
263+
const auto quat = math::geometry::getRotation(
264+
canonicalized_entity_status->getMapPose().orientation,
265+
other_entity_status.at(name).getMapPose().orientation);
266+
/**
267+
* @note hard-coded parameter, if the Yaw value of RPY is in ~1.5708 -> 1.5708, entity is a candidate of front entity.
268+
*/
269+
if (
270+
std::fabs(math::geometry::convertQuaternionToEulerAngle(quat).z) <=
271+
boost::math::constants::half_pi<double>()) {
272+
const auto distance = getDistanceToTargetEntity(spline, other_entity_status.at(name));
273+
274+
if (distance && distance.value() < horizon) {
275+
return name;
276+
}
271277
}
272278
}
273279
}

simulation/behavior_tree_plugin/src/pedestrian/pedestrian_action_node.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ PedestrianActionNode::PedestrianActionNode(
3030
void PedestrianActionNode::getBlackBoardValues()
3131
{
3232
ActionNode::getBlackBoardValues();
33-
if (!getInput<traffic_simulator_msgs::msg::BehaviorParameter>(
34-
"behavior_parameter", behavior_parameter)) {
35-
behavior_parameter = traffic_simulator_msgs::msg::BehaviorParameter();
36-
}
3733
if (!getInput<traffic_simulator_msgs::msg::PedestrianParameters>(
3834
"pedestrian_parameters", pedestrian_parameters)) {
3935
THROW_SIMULATION_ERROR("failed to get input pedestrian_parameters in PedestrianActionNode");

simulation/behavior_tree_plugin/src/vehicle/vehicle_action_node.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ VehicleActionNode::VehicleActionNode(const std::string & name, const BT::NodeCon
2929
void VehicleActionNode::getBlackBoardValues()
3030
{
3131
ActionNode::getBlackBoardValues();
32-
if (!getInput<traffic_simulator_msgs::msg::BehaviorParameter>(
33-
"behavior_parameter", behavior_parameter)) {
34-
behavior_parameter = traffic_simulator_msgs::msg::BehaviorParameter();
35-
}
3632
if (!getInput<traffic_simulator_msgs::msg::VehicleParameters>(
3733
"vehicle_parameters", vehicle_parameters)) {
3834
THROW_SIMULATION_ERROR("failed to get input vehicle_parameters in VehicleActionNode");

simulation/do_nothing_plugin/include/do_nothing_plugin/plugin.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public: \
5858
DEFINE_GETTER_SETTER(TrafficLights, std::shared_ptr<traffic_simulator::TrafficLightsBase>)
5959
DEFINE_GETTER_SETTER(VehicleParameters, traffic_simulator_msgs::msg::VehicleParameters)
6060
DEFINE_GETTER_SETTER(Waypoints, traffic_simulator_msgs::msg::WaypointsArray)
61-
DEFINE_GETTER_SETTER(DistancesMap, std::shared_ptr<DistancesMap>)
61+
DEFINE_GETTER_SETTER(EuclideanDistancesMap, std::shared_ptr<EuclideanDistancesMap>)
6262
// clang-format on
6363
#undef DEFINE_GETTER_SETTER
6464

simulation/traffic_simulator/include/traffic_simulator/behavior/behavior_plugin_base.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace entity_behavior
3636
using EntityStatusDict =
3737
std::unordered_map<std::string, traffic_simulator::CanonicalizedEntityStatus>;
3838

39-
using DistancesMap = std::unordered_map<std::pair<std::string, std::string>, double>;
39+
using EuclideanDistancesMap = std::unordered_map<std::pair<std::string, std::string>, double>;
4040

4141
class BehaviorPluginBase
4242
{
@@ -46,13 +46,13 @@ class BehaviorPluginBase
4646
virtual auto update(const double current_time, const double step_time) -> void = 0;
4747
virtual const std::string & getCurrentAction() const = 0;
4848

49-
#define DEFINE_GETTER_SETTER(NAME, KEY, TYPE) \
50-
virtual TYPE get##NAME() = 0; \
51-
virtual void set##NAME(const TYPE & value) = 0; \
52-
auto get##NAME##Key() const -> const std::string & \
53-
{ \
54-
static const std::string key = KEY; \
55-
return key; \
49+
#define DEFINE_GETTER_SETTER(NAME, KEY, TYPE) \
50+
virtual TYPE get##NAME() = 0; \
51+
virtual void set##NAME(const TYPE & value) = 0; \
52+
auto get##NAME##Key() const->const std::string & \
53+
{ \
54+
static const std::string key = KEY; \
55+
return key; \
5656
}
5757

5858
// clang-format off
@@ -76,7 +76,7 @@ class BehaviorPluginBase
7676
DEFINE_GETTER_SETTER(TrafficLights, "traffic_lights", std::shared_ptr<traffic_simulator::TrafficLightsBase>)
7777
DEFINE_GETTER_SETTER(VehicleParameters, "vehicle_parameters", traffic_simulator_msgs::msg::VehicleParameters)
7878
DEFINE_GETTER_SETTER(Waypoints, "waypoints", traffic_simulator_msgs::msg::WaypointsArray)
79-
DEFINE_GETTER_SETTER(DistancesMap, "distances_map", std::shared_ptr<DistancesMap>)
79+
DEFINE_GETTER_SETTER(EuclideanDistancesMap, "euclidean_distances_map", std::shared_ptr<EuclideanDistancesMap>)
8080
// clang-format on
8181
#undef DEFINE_GETTER_SETTER
8282
};

0 commit comments

Comments
 (0)