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.
20
20
21
21
namespace tier4_autoware_utils
22
22
{
23
- VehicleStateChecker::VehicleStateChecker (rclcpp::Node * node)
23
+ VehicleStopChecker::VehicleStopChecker (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));
31
-
32
- sub_trajectory_ = node->create_subscription <Trajectory>(
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));
30
+ std::bind (&VehicleStopChecker::onOdom, this , _1));
39
31
}
40
32
41
- bool VehicleStateChecker::checkStopped (const double stop_duration = 0.0 ) const
33
+ bool VehicleStopChecker::isVehicleStopped (const double stop_duration = 0.0 ) const
42
34
{
43
35
if (twist_buffer_.empty ()) {
44
36
return false ;
45
37
}
46
38
47
- // Get velocities within stop_duration
48
39
const auto now = clock_->now ();
40
+ const auto time_buffer = now - twist_buffer_.back ().header .stamp ;
41
+ if (time_buffer.seconds () < stop_duration) {
42
+ return false ;
43
+ }
44
+
45
+ // Get velocities within stop_duration
49
46
std::vector<double > vs;
50
47
for (const auto & velocity : twist_buffer_) {
51
48
vs.push_back (velocity.twist .linear .x );
@@ -67,38 +64,59 @@ bool VehicleStateChecker::checkStopped(const double stop_duration = 0.0) const
67
64
return true ;
68
65
}
69
66
70
- bool VehicleStateChecker::checkStoppedAtStopPoint (const double stop_duration = 0.0 ) const
67
+ void VehicleStopChecker::onOdom (const nav_msgs::msg::Odometry::SharedPtr msg)
71
68
{
72
- if (!odometry_ptr_ || !trajectory_ptr_) {
73
- return false ;
74
- }
69
+ auto current_velocity = std::make_shared<geometry_msgs::msg::TwistStamped>();
70
+ current_velocity-> header = msg-> header ;
71
+ current_velocity-> twist = msg-> twist . twist ;
75
72
76
- if (!checkStopped (stop_duration)) {
77
- return false ;
78
- }
73
+ twist_buffer_.push_front (*current_velocity);
79
74
80
- const auto & p = odometry_ptr_->pose .pose .position ;
81
- const auto idx = searchZeroVelocityIndex (trajectory_ptr_->points );
75
+ const auto now = clock_->now ();
76
+ while (true ) {
77
+ // Check oldest data time
78
+ const auto time_diff = now - twist_buffer_.back ().header .stamp ;
82
79
83
- if (!idx) {
84
- return false ;
80
+ // Finish when oldest data is newer than threshold
81
+ if (time_diff.seconds () <= velocity_buffer_time_sec) {
82
+ break ;
83
+ }
84
+
85
+ // Remove old data
86
+ twist_buffer_.pop_back ();
85
87
}
88
+ }
86
89
87
- return std::abs (calcSignedArcLength (trajectory_ptr_->points , p, idx.get ())) <
88
- th_arrived_distance_m;
90
+ VehicleArrivalChecker::VehicleArrivalChecker (rclcpp::Node * node)
91
+ : clock_(node->get_clock ()), logger_(node->get_logger ())
92
+ {
93
+ using std::placeholders::_1;
94
+
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
+ sub_trajectory_ = node->create_subscription <Trajectory>(
100
+ " /planning/scenario_planning/trajectory" , rclcpp::QoS (1 ),
101
+ std::bind (&VehicleArrivalChecker::onTrajectory, this , _1));
89
102
}
90
103
91
- bool VehicleStateChecker::checkStoppedWithoutLocalization (const double stop_duration = 0.0 ) const
104
+ bool VehicleArrivalChecker::isVehicleStopped (const double stop_duration = 0.0 ) const
92
105
{
93
- if (velocity_status_buffer_ .empty ()) {
106
+ if (twist_buffer_ .empty ()) {
94
107
return false ;
95
108
}
96
109
97
- // Get velocities within stop_duration
98
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
99
117
std::vector<double > vs;
100
- for (const auto & velocity : velocity_status_buffer_ ) {
101
- vs.push_back (velocity.longitudinal_velocity );
118
+ for (const auto & velocity : twist_buffer_ ) {
119
+ vs.push_back (velocity.twist . linear . x );
102
120
103
121
const auto time_diff = now - velocity.header .stamp ;
104
122
if (time_diff.seconds () >= stop_duration) {
@@ -117,7 +135,28 @@ bool VehicleStateChecker::checkStoppedWithoutLocalization(const double stop_dura
117
135
return true ;
118
136
}
119
137
120
- void VehicleStateChecker::onOdom (const nav_msgs::msg::Odometry::SharedPtr msg)
138
+ bool VehicleArrivalChecker::isVehicleStoppedAtStopPoint (const double stop_duration = 0.0 ) const
139
+ {
140
+ if (!odometry_ptr_ || !trajectory_ptr_) {
141
+ return false ;
142
+ }
143
+
144
+ if (!isVehicleStopped (stop_duration)) {
145
+ return false ;
146
+ }
147
+
148
+ const auto & p = odometry_ptr_->pose .pose .position ;
149
+ const auto idx = searchZeroVelocityIndex (trajectory_ptr_->points );
150
+
151
+ if (!idx) {
152
+ return false ;
153
+ }
154
+
155
+ return std::abs (calcSignedArcLength (trajectory_ptr_->points , p, idx.get ())) <
156
+ th_arrived_distance_m;
157
+ }
158
+
159
+ void VehicleArrivalChecker::onOdom (const nav_msgs::msg::Odometry::SharedPtr msg)
121
160
{
122
161
odometry_ptr_ = msg;
123
162
@@ -142,24 +181,5 @@ void VehicleStateChecker::onOdom(const nav_msgs::msg::Odometry::SharedPtr msg)
142
181
}
143
182
}
144
183
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; }
184
+ void VehicleArrivalChecker::onTrajectory (const Trajectory::SharedPtr msg) { trajectory_ptr_ = msg; }
165
185
} // namespace tier4_autoware_utils
0 commit comments