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(ars548): updated the driver according to new documentation #253

Merged
merged 21 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a22a695
feat: updated the ars548 driver according to new received documentation
knzo25 Jan 20, 2025
9424af1
chore: removed logs and added the max time slot value
knzo25 Jan 21, 2025
daeb43c
chore: added the min/maz frequencies as constants
knzo25 Jan 21, 2025
1ecd4d2
chore: fixed compilation errors
knzo25 Jan 21, 2025
681efb3
chore: added units to a print
knzo25 Feb 10, 2025
5909afc
chore: replaced hardcoded strings for some defined in the message
knzo25 Feb 10, 2025
114ac93
chore: removed hardcoded numbers in print
knzo25 Feb 10, 2025
b10082b
chore: refactored the rate checker logic into a class
knzo25 Feb 10, 2025
ff00898
chore: replaced hardcoded prints
knzo25 Feb 10, 2025
79a01d4
chore: refactored the ring buffer
knzo25 Feb 10, 2025
52162e9
Merge branch 'main' into feat/ars548_update
knzo25 Feb 10, 2025
65872f7
chore: refactored for clarity
knzo25 Feb 12, 2025
fc4cefb
chore: added the units to the variable names
knzo25 Feb 12, 2025
0d2efb5
chore: replaced ifelse clauses byt switch
knzo25 Feb 12, 2025
a34cb38
Revert "chore: replaced ifelse clauses byt switch"
knzo25 Feb 12, 2025
c15aaa0
chore: deleted duplicated logic with method call
knzo25 Feb 12, 2025
17aabf7
chore: deleted unused code
knzo25 Feb 12, 2025
8dc4b8d
chore: replaced initial check with the use of an optional
knzo25 Feb 12, 2025
d7fe448
fix: fixed burst of messages sent to the radar during startup
knzo25 Feb 12, 2025
9ea0c67
Merge branch 'feat/ars548_update' of github.com:knzo25/nebula into fe…
knzo25 Feb 12, 2025
bec4751
Merge branch 'main' into feat/ars548_update
knzo25 Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions nebula_common/include/nebula_common/util/rate_checker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2025 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "nebula_common/util/ring_buffer.hpp"

namespace nebula::util
{

class RateChecker
{
public:
RateChecker(double min_rate, double max_rate, std::size_t buffer_size)
: min_rate_(min_rate), max_rate_(max_rate), ring_buffer_(buffer_size)
{
}

bool is_valid(double stamp)
{
if (last_stamp_ > 0.0) {
double current_time = stamp;
double dt = stamp - last_stamp_;
ring_buffer_.push_back(dt);
}

last_stamp_ = stamp;

if (!ring_buffer_.is_full()) {
return true;
}

double average = 1.0 / ring_buffer_.get_average();
return average >= min_rate_ && average <= max_rate_;
}

double get_average() const { return 1.0 / ring_buffer_.get_average(); }

private:
double last_stamp_{0.0};
double min_rate_;
double max_rate_;
RingBuffer<double> ring_buffer_;
};

} // namespace nebula::util
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "nebula_ros/common/parameter_descriptors.hpp"

#include <nebula_common/continental/continental_ars548.hpp>
#include <nebula_common/util/ring_buffer.hpp>
#include <nebula_common/util/rate_checker.hpp>
#include <nebula_hw_interfaces/nebula_hw_interfaces_continental/continental_ars548_hw_interface.hpp>
#include <rclcpp/rclcpp.hpp>

Expand Down Expand Up @@ -115,12 +115,9 @@ class ContinentalARS548HwInterfaceWrapper
acceleration_sub_{};
rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr steering_angle_sub_{};

double last_odometry_stamp_{0.0};
double last_acceleration_stamp_{0.0};
double last_steering_angle_stamp_{0.0};
nebula::util::RingBuffer<double> odometry_ring_buffer_;
nebula::util::RingBuffer<double> acceleration_ring_buffer_;
nebula::util::RingBuffer<double> steering_angle_ring_buffer_;
nebula::util::RateChecker odometry_rate_checker_;
nebula::util::RateChecker acceleration_rate_checker_;
nebula::util::RateChecker steering_angle_rate_checker_;

bool standstill_{true};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ ContinentalARS548HwInterfaceWrapper::ContinentalARS548HwInterfaceWrapper(
logger_(parent_node->get_logger().get_child("HwInterfaceWrapper")),
status_(Status::NOT_INITIALIZED),
config_ptr_(config_ptr),
odometry_ring_buffer_(100),
acceleration_ring_buffer_(100),
steering_angle_ring_buffer_(100)
odometry_rate_checker_(
nebula::drivers::continental_ars548::min_odometry_hz,
nebula::drivers::continental_ars548::max_odometry_hz, 100),
acceleration_rate_checker_(
nebula::drivers::continental_ars548::min_odometry_hz,
nebula::drivers::continental_ars548::max_odometry_hz, 100),
steering_angle_rate_checker_(
nebula::drivers::continental_ars548::min_odometry_hz,
nebula::drivers::continental_ars548::max_odometry_hz, 100)
{
hw_interface_->set_logger(
std::make_shared<rclcpp::Logger>(parent_node->get_logger().get_child("HwInterface")));
Expand Down Expand Up @@ -128,20 +134,10 @@ void ContinentalARS548HwInterfaceWrapper::odometry_callback(
using nebula::drivers::continental_ars548::max_odometry_hz;
using nebula::drivers::continental_ars548::min_odometry_hz;

if (last_odometry_stamp_ == 0.0) {
last_odometry_stamp_ = msg->header.stamp.sec + msg->header.stamp.nanosec * 1e-9;
} else {
double current_time = msg->header.stamp.sec + msg->header.stamp.nanosec * 1e-9;
double dt = current_time - last_odometry_stamp_;
last_odometry_stamp_ = current_time;
odometry_ring_buffer_.push_back(dt);
}

double estimated_hz = 1.0 / odometry_ring_buffer_.get_average();
double stamp = msg->header.stamp.sec + msg->header.stamp.nanosec * 1e-9;

if (
odometry_ring_buffer_.is_full() && (estimated_hz < static_cast<double>(min_odometry_hz) ||
estimated_hz > static_cast<double>(max_odometry_hz))) {
if (!odometry_rate_checker_.is_valid(stamp)) {
double estimated_hz = odometry_rate_checker_.get_average();
rclcpp::Clock clock{RCL_ROS_TIME};
RCLCPP_WARN_THROTTLE(
logger_, clock, 5000,
Expand Down Expand Up @@ -178,20 +174,10 @@ void ContinentalARS548HwInterfaceWrapper::acceleration_callback(
using nebula::drivers::continental_ars548::max_odometry_hz;
using nebula::drivers::continental_ars548::min_odometry_hz;

if (last_acceleration_stamp_ == 0.0) {
last_acceleration_stamp_ = msg->header.stamp.sec + msg->header.stamp.nanosec * 1e-9;
} else {
double current_time = msg->header.stamp.sec + msg->header.stamp.nanosec * 1e-9;
double dt = current_time - last_acceleration_stamp_;
last_acceleration_stamp_ = current_time;
acceleration_ring_buffer_.push_back(dt);
}

double estimated_hz = 1.0 / acceleration_ring_buffer_.get_average();
double stamp = msg->header.stamp.sec + msg->header.stamp.nanosec * 1e-9;

if (
acceleration_ring_buffer_.is_full() && (estimated_hz < static_cast<double>(min_odometry_hz) ||
estimated_hz > static_cast<double>(max_odometry_hz))) {
if (!acceleration_rate_checker_.is_valid(stamp)) {
double estimated_hz = acceleration_rate_checker_.get_average();
rclcpp::Clock clock{RCL_ROS_TIME};
RCLCPP_WARN_THROTTLE(
logger_, clock, 5000,
Expand All @@ -211,23 +197,11 @@ void ContinentalARS548HwInterfaceWrapper::steering_angle_callback(
using nebula::drivers::continental_ars548::min_odometry_hz;

const auto now = std::chrono::high_resolution_clock::now();
const auto stamp =
const double stamp =
1e-9 * std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();

if (last_steering_angle_stamp_ == 0.0) {
last_steering_angle_stamp_ = stamp;
} else {
double dt = stamp - last_steering_angle_stamp_;
last_steering_angle_stamp_ = stamp;
steering_angle_ring_buffer_.push_back(dt);
}

double estimated_hz = 1.0 / steering_angle_ring_buffer_.get_average();

if (
steering_angle_ring_buffer_.is_full() &&
(estimated_hz < static_cast<double>(min_odometry_hz) ||
estimated_hz > static_cast<double>(max_odometry_hz))) {
if (!steering_angle_rate_checker_.is_valid(stamp)) {
double estimated_hz = steering_angle_rate_checker_.get_average();
rclcpp::Clock clock{RCL_ROS_TIME};
RCLCPP_WARN_THROTTLE(
logger_, clock, 5000,
Expand Down