Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tier4_autoware_utils): add vehicle state checker #896

Merged
24 changes: 12 additions & 12 deletions common/tier4_autoware_utils/src/vehicle/vehicle_state_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,31 @@ bool VehicleStopChecker::isVehicleStopped(const double stop_duration = 0.0) cons
return false;
}

constexpr double stop_velocity = 1e-3;
const auto now = clock_->now();
const auto time_buffer = now - twist_buffer_.back().header.stamp;
if (time_buffer.seconds() < stop_duration) {

const auto time_buffer_front = now - twist_buffer_.back().header.stamp;
isamu-takagi marked this conversation as resolved.
Show resolved Hide resolved
if (time_buffer_front.seconds() < stop_duration) {
return false;
isamu-takagi marked this conversation as resolved.
Show resolved Hide resolved
}

const auto time_buffer_back = now - twist_buffer_.front().header.stamp;
isamu-takagi marked this conversation as resolved.
Show resolved Hide resolved
if (time_buffer_back.seconds() > stop_duration) {
return twist_buffer_.front().twist.linear.x < stop_velocity;
}

// Get velocities within stop_duration
std::vector<double> vs;
for (const auto & velocity : twist_buffer_) {
vs.push_back(velocity.twist.linear.x);
if (stop_velocity <= velocity.twist.linear.x) {
return false;
}

const auto time_diff = now - velocity.header.stamp;
if (time_diff.seconds() >= stop_duration) {
break;
}
}

// Check all velocities
constexpr double stop_velocity = 1e-3;
for (const auto & v : vs) {
if (v >= stop_velocity) {
return false;
}
}

return true;
}

Expand Down