generated from tier4/ros2-project-template
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ars548): updated the driver according to new documentation (#253)
* feat: updated the ars548 driver according to new received documentation Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: removed logs and added the max time slot value Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: added the min/maz frequencies as constants Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: fixed compilation errors Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: added units to a print Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: replaced hardcoded strings for some defined in the message Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: removed hardcoded numbers in print Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: refactored the rate checker logic into a class Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: replaced hardcoded prints Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: refactored the ring buffer Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: refactored for clarity Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: added the units to the variable names Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: replaced ifelse clauses byt switch Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * Revert "chore: replaced ifelse clauses byt switch" This reverts commit 0d2efb5. * chore: deleted duplicated logic with method call Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: deleted unused code Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * chore: replaced initial check with the use of an optional Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> * fix: fixed burst of messages sent to the radar during startup Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp> --------- Signed-off-by: Kenzo Lobos-Tsunekawa <kenzo.lobos@tier4.jp>
- Loading branch information
Showing
8 changed files
with
256 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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_hz, double max_rate_hz, std::size_t buffer_size) | ||
: min_rate_hz_(min_rate_hz), max_rate_hz_(max_rate_hz), ring_buffer_(buffer_size) | ||
{ | ||
} | ||
|
||
bool is_full() const { return ring_buffer_.is_full(); } | ||
|
||
void update(double stamp) | ||
{ | ||
if (last_stamp_) { | ||
ring_buffer_.push_back(stamp - last_stamp_.value()); | ||
} | ||
|
||
last_stamp_ = stamp; | ||
} | ||
|
||
bool is_valid() const | ||
{ | ||
double average = get_average(); | ||
return average >= min_rate_hz_ && average <= max_rate_hz_; | ||
} | ||
|
||
double get_average() const { return 1.0 / ring_buffer_.get_average(); } | ||
|
||
private: | ||
std::optional<double> last_stamp_; | ||
double min_rate_hz_; | ||
double max_rate_hz_; | ||
RingBuffer<double> ring_buffer_; | ||
}; | ||
|
||
} // namespace nebula::util |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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 <algorithm> | ||
#include <stdexcept> | ||
#include <vector> | ||
|
||
namespace nebula::util | ||
{ | ||
|
||
template <typename T> | ||
class RingBuffer | ||
{ | ||
public: | ||
explicit RingBuffer(std::size_t capacity) { buffer_.reserve(capacity); } | ||
|
||
void push_back(const T & value) | ||
{ | ||
if (is_full()) { | ||
sum_ -= buffer_[index_]; | ||
buffer_[index_] = value; | ||
} else { | ||
buffer_.push_back(value); | ||
} | ||
|
||
sum_ += value; | ||
index_ = (index_ + 1) % buffer_.capacity(); | ||
} | ||
|
||
std::size_t size() const { return buffer_.size(); } | ||
|
||
bool is_full() const { return buffer_.size() == buffer_.capacity(); } | ||
|
||
T get_average() const { return sum_ / buffer_.size(); } | ||
|
||
private: | ||
T sum_{}; | ||
std::vector<T> buffer_; | ||
std::size_t index_{0}; | ||
}; | ||
|
||
} // namespace nebula::util |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 9 additions & 4 deletions
13
nebula_messages/continental_srvs/srv/ContinentalArs548SetRadarParameters.srv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters