Skip to content

Commit 53d8a47

Browse files
committed
added all planning topics
1 parent e53b2a1 commit 53d8a47

File tree

4 files changed

+71
-10
lines changed

4 files changed

+71
-10
lines changed

tools/reaction_analyzer/include/reaction_analyzer_node.hpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef REACTION_ANALYZER_NODE_HPP_
1616
#define REACTION_ANALYZER_NODE_HPP_
1717

18+
#include <motion_utils/trajectory/trajectory.hpp>
1819
#include <rclcpp/rclcpp.hpp>
1920
#include <tier4_autoware_utils/geometry/geometry.hpp>
2021
#include <tier4_autoware_utils/math/unit_conversion.hpp>
@@ -55,17 +56,16 @@ using autoware_auto_planning_msgs::msg::Trajectory;
5556
using geometry_msgs::msg::Pose;
5657
using nav_msgs::msg::Odometry;
5758
using sensor_msgs::msg::PointCloud2;
59+
5860
using ControlBuffer =
5961
std::pair<std::vector<AckermannControlCommand>, std::optional<AckermannControlCommand>>;
60-
61-
using BufferVariant =
62-
std::variant<ControlBuffer
63-
// , std::vector<OtherMessageType> // Add other message types here
64-
>;
62+
using PlanningBuffer = std::pair<Trajectory, std::optional<Trajectory>>;
63+
using BufferVariant = std::variant<ControlBuffer, PlanningBuffer>;
6564

6665
enum class MessageType {
6766
Unknown = 0,
6867
AckermannControlCommand = 1,
68+
Trajectory = 2,
6969
};
7070

7171
struct TopicConfig
@@ -120,7 +120,8 @@ class ReactionAnalyzerNode : public rclcpp::Node
120120
std::vector<rclcpp::SubscriptionBase::SharedPtr> subscribers_;
121121
void controlCommandOutputCallback(
122122
const std::string & node_name, const AckermannControlCommand::ConstSharedPtr msg_ptr);
123-
123+
void planningOutputCallback(
124+
const std::string & node_name, const Trajectory::ConstSharedPtr msg_ptr);
124125
std::unordered_map<std::string, BufferVariant> messageBuffers_;
125126

126127
std::mutex mutex_;
@@ -182,10 +183,6 @@ class ReactionAnalyzerNode : public rclcpp::Node
182183
bool all_topics_reacted_{false};
183184
std::optional<rclcpp::Time> last_initialize_test_time_;
184185

185-
// measurement for control cmd
186-
// std::optional<ControlCommandWithSeenTime> trajectory_follower_brake_cmd;
187-
// std::optional<ControlCommandWithSeenTime> vehicle_cmd_gate_brake_cmd;
188-
189186
// Timer
190187
rclcpp::TimerBase::SharedPtr timer_;
191188

tools/reaction_analyzer/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<depend>autoware_auto_planning_msgs</depend>
2121
<depend>autoware_auto_system_msgs</depend>
2222
<depend>autoware_auto_vehicle_msgs</depend>
23+
<depend>motion_utils</depend>
2324
<depend>eigen</depend>
2425
<depend>libpcl-all-dev</depend>
2526
<depend>pcl_conversions</depend>

tools/reaction_analyzer/param/reaction_analyzer.param.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
/**:
22
ros__parameters:
33
chain:
4+
obstacle_stop_planner:
5+
topic_name: /planning/scenario_planning/lane_driving/trajectory
6+
message_type: autoware_auto_planning_msgs::msg::Trajectory
7+
scenario_selector:
8+
topic_name: /planning/scenario_planning/scenario_selector/trajectory
9+
message_type: autoware_auto_planning_msgs::msg::Trajectory
10+
motion_velocity_smoother:
11+
topic_name: /planning/scenario_planning/motion_velocity_smoother/trajectory
12+
message_type: autoware_auto_planning_msgs::msg::Trajectory
13+
planning_validator:
14+
topic_name: /planning/scenario_planning/trajectory
15+
message_type: autoware_auto_planning_msgs::msg::Trajectory
416
trajectory_follower:
517
topic_name: /control/trajectory_follower/control_cmd
618
message_type: autoware_auto_control_msgs::msg::AckermannControlCommand

tools/reaction_analyzer/src/reaction_analyzer_node.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ MessageType stringToMessageType(const std::string & input)
8282
{
8383
if (input == "autoware_auto_control_msgs::msg::AckermannControlCommand") {
8484
return MessageType::AckermannControlCommand;
85+
} else if (input == "autoware_auto_planning_msgs::msg::Trajectory") {
86+
return MessageType::Trajectory;
8587
} else {
8688
return MessageType::Unknown;
8789
}
@@ -305,6 +307,28 @@ void ReactionAnalyzerNode::onTimer()
305307
mutex_.unlock();
306308
}
307309
}
310+
} else if (auto * message = std::get_if<PlanningBuffer>(&variant)) {
311+
if (!message->second) {
312+
all_topics_reacted_ = false;
313+
const auto nearest_idx = motion_utils::findNearestIndex(
314+
message->first.points, current_odometry_ptr->pose.pose.position);
315+
//
316+
// constexpr double lookahead_distance = 15.0;
317+
// const auto destination_idx = motion_utils::calcLongitudinalOffsetPoint(
318+
// message->first.points, nearest_idx, lookahead_distance);
319+
const auto zero_vel_idx = motion_utils::searchZeroVelocityIndex(
320+
message->first.points, nearest_idx, message->first.points.size() - 1);
321+
322+
if (zero_vel_idx) {
323+
std::cout << key << " found: nearest_idx: " << nearest_idx
324+
<< " zero_vel_idx: " << zero_vel_idx.value()
325+
<< " size: " << message->first.points.size() << " stamp: " << message->first.header.stamp.nanosec << std::endl;
326+
mutex_.lock();
327+
auto * tmp = std::get_if<PlanningBuffer>(&messageBuffers_[key]);
328+
if (tmp) tmp->second = message->first;
329+
mutex_.unlock();
330+
}
331+
}
308332
}
309333
// Add similar blocks for other types
310334
}
@@ -317,6 +341,10 @@ void ReactionAnalyzerNode::onTimer()
317341
if (message->second) {
318342
reaction_times.emplace_back(key, rclcpp::Time(message->second->stamp));
319343
}
344+
} else if (auto * message = std::get_if<PlanningBuffer>(&variant)) {
345+
if (message->second) {
346+
reaction_times.emplace_back(key, rclcpp::Time(message->second->header.stamp));
347+
}
320348
}
321349
}
322350

@@ -450,6 +478,20 @@ void ReactionAnalyzerNode::controlCommandOutputCallback(
450478
setControlCommandToBuffer(std::get<ControlBuffer>(variant).first, *msg_ptr);
451479
}
452480

481+
void ReactionAnalyzerNode::planningOutputCallback(
482+
const std::string & node_name, const Trajectory::ConstSharedPtr msg_ptr)
483+
{
484+
std::lock_guard<std::mutex> lock(mutex_);
485+
auto & variant = messageBuffers_[node_name];
486+
if (!std::holds_alternative<PlanningBuffer>(variant)) {
487+
// If the variant doesn't hold a vector of AckermannControlCommand yet, initialize it
488+
PlanningBuffer buffer(*msg_ptr, std::nullopt);
489+
variant = buffer;
490+
} else {
491+
std::get<PlanningBuffer>(variant).first = *msg_ptr;
492+
}
493+
}
494+
453495
void ReactionAnalyzerNode::initObservers(const reaction_analyzer::ChainModules & modules)
454496
{
455497
for (const auto & module : modules) {
@@ -463,6 +505,15 @@ void ReactionAnalyzerNode::initObservers(const reaction_analyzer::ChainModules &
463505
subscribers_.push_back(subscriber);
464506
break;
465507
}
508+
case MessageType::Trajectory: {
509+
auto callback = [this, module](const Trajectory::ConstSharedPtr msg) {
510+
this->planningOutputCallback(module.node_name, msg);
511+
};
512+
auto subscriber = this->create_subscription<Trajectory>(
513+
module.topic_address, 1, callback, createSubscriptionOptions(this));
514+
subscribers_.push_back(subscriber);
515+
break;
516+
}
466517
case MessageType::Unknown:
467518
RCLCPP_WARN(
468519
this->get_logger(), "Unknown message type for topic: %s", module.topic_address.c_str());

0 commit comments

Comments
 (0)