1
- // Copyright 2022 Tier IV, Inc.
1
+ // Copyright 2022 TIER IV, Inc.
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- #include " tier4_autoware_utils/vehicle/vehicle_state_checker .hpp"
15
+ #include " tier4_autoware_utils/vehicle/vehicle_arrival_checker .hpp"
16
16
17
17
#include " tier4_autoware_utils/trajectory/trajectory.hpp"
18
18
19
19
#include < string>
20
20
21
21
namespace tier4_autoware_utils
22
22
{
23
- VehicleStateChecker::VehicleStateChecker (rclcpp::Node * node)
23
+ VehicleArrivalChecker::VehicleArrivalChecker (rclcpp::Node * node)
24
24
: clock_(node->get_clock ()), logger_(node->get_logger ())
25
25
{
26
26
using std::placeholders::_1;
27
27
28
28
sub_odom_ = node->create_subscription <nav_msgs::msg::Odometry>(
29
29
" /localization/kinematic_state" , rclcpp::QoS (1 ),
30
- std::bind (&VehicleStateChecker ::onOdom, this , _1));
30
+ std::bind (&VehicleArrivalChecker ::onOdom, this , _1));
31
31
32
32
sub_trajectory_ = node->create_subscription <Trajectory>(
33
33
" /planning/scenario_planning/trajectory" , rclcpp::QoS (1 ),
34
- std::bind (&VehicleStateChecker::onTrajectory, this , _1));
35
-
36
- sub_velocity_status_ = node->create_subscription <VelocityReport>(
37
- " /vehicle/status/velocity_status" , rclcpp::QoS (1 ),
38
- std::bind (&VehicleStateChecker::onVelocityStatus, this , _1));
34
+ std::bind (&VehicleArrivalChecker::onTrajectory, this , _1));
39
35
}
40
36
41
- bool VehicleStateChecker::checkStopped (const double stop_duration = 0.0 ) const
37
+ bool VehicleArrivalChecker::isVehicleStopped (const double stop_duration = 0.0 ) const
42
38
{
43
39
if (twist_buffer_.empty ()) {
44
40
return false ;
@@ -67,13 +63,13 @@ bool VehicleStateChecker::checkStopped(const double stop_duration = 0.0) const
67
63
return true ;
68
64
}
69
65
70
- bool VehicleStateChecker::checkStoppedAtStopPoint (const double stop_duration = 0.0 ) const
66
+ bool VehicleArrivalChecker::isVehicleStoppedAtStopPoint (const double stop_duration = 0.0 ) const
71
67
{
72
68
if (!odometry_ptr_ || !trajectory_ptr_) {
73
69
return false ;
74
70
}
75
71
76
- if (!checkStopped (stop_duration)) {
72
+ if (!isVehicleStopped (stop_duration)) {
77
73
return false ;
78
74
}
79
75
@@ -88,36 +84,7 @@ bool VehicleStateChecker::checkStoppedAtStopPoint(const double stop_duration = 0
88
84
th_arrived_distance_m;
89
85
}
90
86
91
- bool VehicleStateChecker::checkStoppedWithoutLocalization (const double stop_duration = 0.0 ) const
92
- {
93
- if (velocity_status_buffer_.empty ()) {
94
- return false ;
95
- }
96
-
97
- // Get velocities within stop_duration
98
- const auto now = clock_->now ();
99
- std::vector<double > vs;
100
- for (const auto & velocity : velocity_status_buffer_) {
101
- vs.push_back (velocity.longitudinal_velocity );
102
-
103
- const auto time_diff = now - velocity.header .stamp ;
104
- if (time_diff.seconds () >= stop_duration) {
105
- break ;
106
- }
107
- }
108
-
109
- // Check all velocities
110
- constexpr double stop_velocity = 1e-3 ;
111
- for (const auto & v : vs) {
112
- if (v >= stop_velocity) {
113
- return false ;
114
- }
115
- }
116
-
117
- return true ;
118
- }
119
-
120
- void VehicleStateChecker::onOdom (const nav_msgs::msg::Odometry::SharedPtr msg)
87
+ void VehicleArrivalChecker::onOdom (const nav_msgs::msg::Odometry::SharedPtr msg)
121
88
{
122
89
odometry_ptr_ = msg;
123
90
@@ -142,24 +109,5 @@ void VehicleStateChecker::onOdom(const nav_msgs::msg::Odometry::SharedPtr msg)
142
109
}
143
110
}
144
111
145
- void VehicleStateChecker::onVelocityStatus (const VelocityReport::SharedPtr msg)
146
- {
147
- velocity_status_buffer_.push_front (*msg);
148
-
149
- const auto now = clock_->now ();
150
- while (true ) {
151
- // Check oldest data time
152
- const auto time_diff = now - velocity_status_buffer_.back ().header .stamp ;
153
-
154
- // Finish when oldest data is newer than threshold
155
- if (time_diff.seconds () <= velocity_buffer_time_sec) {
156
- break ;
157
- }
158
-
159
- // Remove old data
160
- velocity_status_buffer_.pop_back ();
161
- }
162
- }
163
-
164
- void VehicleStateChecker::onTrajectory (const Trajectory::SharedPtr msg) { trajectory_ptr_ = msg; }
112
+ void VehicleArrivalChecker::onTrajectory (const Trajectory::SharedPtr msg) { trajectory_ptr_ = msg; }
165
113
} // namespace tier4_autoware_utils
0 commit comments