@@ -25,7 +25,7 @@ VehicleStopChecker::VehicleStopChecker(rclcpp::Node * node)
25
25
{
26
26
using std::placeholders::_1;
27
27
28
- sub_odom_ = node->create_subscription <nav_msgs::msg:: Odometry>(
28
+ sub_odom_ = node->create_subscription <Odometry>(
29
29
" /localization/kinematic_state" , rclcpp::QoS (1 ),
30
30
std::bind (&VehicleStopChecker::onOdom, this , _1));
31
31
}
@@ -64,9 +64,11 @@ bool VehicleStopChecker::isVehicleStopped(const double stop_duration = 0.0) cons
64
64
return true ;
65
65
}
66
66
67
- void VehicleStopChecker::onOdom (const nav_msgs::msg:: Odometry::SharedPtr msg)
67
+ void VehicleStopChecker::onOdom (const Odometry::SharedPtr msg)
68
68
{
69
- auto current_velocity = std::make_shared<geometry_msgs::msg::TwistStamped>();
69
+ odometry_ptr_ = msg;
70
+
71
+ auto current_velocity = std::make_shared<TwistStamped>();
70
72
current_velocity->header = msg->header ;
71
73
current_velocity->twist = msg->twist .twist ;
72
74
@@ -87,54 +89,15 @@ void VehicleStopChecker::onOdom(const nav_msgs::msg::Odometry::SharedPtr msg)
87
89
}
88
90
}
89
91
90
- VehicleArrivalChecker::VehicleArrivalChecker (rclcpp::Node * node)
91
- : clock_(node->get_clock ()), logger_(node->get_logger ())
92
+ VehicleArrivalChecker::VehicleArrivalChecker (rclcpp::Node * node) : VehicleStopChecker(node)
92
93
{
93
94
using std::placeholders::_1;
94
95
95
- sub_odom_ = node->create_subscription <nav_msgs::msg::Odometry>(
96
- " /localization/kinematic_state" , rclcpp::QoS (1 ),
97
- std::bind (&VehicleArrivalChecker::onOdom, this , _1));
98
-
99
96
sub_trajectory_ = node->create_subscription <Trajectory>(
100
97
" /planning/scenario_planning/trajectory" , rclcpp::QoS (1 ),
101
98
std::bind (&VehicleArrivalChecker::onTrajectory, this , _1));
102
99
}
103
100
104
- bool VehicleArrivalChecker::isVehicleStopped (const double stop_duration = 0.0 ) const
105
- {
106
- if (twist_buffer_.empty ()) {
107
- return false ;
108
- }
109
-
110
- const auto now = clock_->now ();
111
- const auto time_buffer = now - twist_buffer_.back ().header .stamp ;
112
- if (time_buffer.seconds () < stop_duration) {
113
- return false ;
114
- }
115
-
116
- // Get velocities within stop_duration
117
- std::vector<double > vs;
118
- for (const auto & velocity : twist_buffer_) {
119
- vs.push_back (velocity.twist .linear .x );
120
-
121
- const auto time_diff = now - velocity.header .stamp ;
122
- if (time_diff.seconds () >= stop_duration) {
123
- break ;
124
- }
125
- }
126
-
127
- // Check all velocities
128
- constexpr double stop_velocity = 1e-3 ;
129
- for (const auto & v : vs) {
130
- if (v >= stop_velocity) {
131
- return false ;
132
- }
133
- }
134
-
135
- return true ;
136
- }
137
-
138
101
bool VehicleArrivalChecker::isVehicleStoppedAtStopPoint (const double stop_duration = 0.0 ) const
139
102
{
140
103
if (!odometry_ptr_ || !trajectory_ptr_) {
@@ -156,30 +119,5 @@ bool VehicleArrivalChecker::isVehicleStoppedAtStopPoint(const double stop_durati
156
119
th_arrived_distance_m;
157
120
}
158
121
159
- void VehicleArrivalChecker::onOdom (const nav_msgs::msg::Odometry::SharedPtr msg)
160
- {
161
- odometry_ptr_ = msg;
162
-
163
- auto current_velocity = std::make_shared<geometry_msgs::msg::TwistStamped>();
164
- current_velocity->header = msg->header ;
165
- current_velocity->twist = msg->twist .twist ;
166
-
167
- twist_buffer_.push_front (*current_velocity);
168
-
169
- const auto now = clock_->now ();
170
- while (true ) {
171
- // Check oldest data time
172
- const auto time_diff = now - twist_buffer_.back ().header .stamp ;
173
-
174
- // Finish when oldest data is newer than threshold
175
- if (time_diff.seconds () <= velocity_buffer_time_sec) {
176
- break ;
177
- }
178
-
179
- // Remove old data
180
- twist_buffer_.pop_back ();
181
- }
182
- }
183
-
184
122
void VehicleArrivalChecker::onTrajectory (const Trajectory::SharedPtr msg) { trajectory_ptr_ = msg; }
185
123
} // namespace tier4_autoware_utils
0 commit comments