-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add add_analyzer functionality #3
base: ros2
Are you sure you want to change the base?
Changes from 10 commits
863d110
8bea594
817e6f6
d8c28eb
464935e
ff06009
468203c
43b6a15
cff4a46
b66a4ce
4af79fc
adfa0ff
ffe773f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# Aggregator Example | ||
|
||
This is a simple example to show the diagnostic_aggregator in action. It involves one python script producing dummy diagnostic data ([example_pub.py](./example_pub.py)), and one diagnostic aggregator configuration ([example.yaml](./example.yaml)) that provides analyzers aggregating it. | ||
This is a simple example to show the diagnostic_aggregator and add_analyzer in action. It involves one python script producing dummy diagnostic data ([example_pub.py](./example_pub.py)), one diagnostic aggregator configuration ([example_analyzers.yaml](./example_analyzers.yaml)) and one add_analyzer configuration ([example_add_analyzers.yaml](./example_add_analyzers.yaml)). | ||
|
||
The aggregator will launch and load all the analyzers listed in ([example_analyzers.yaml](./example_analyzers.yaml)). Then the aggregator will be notified that there are additional analyzers that we also want to load in ([example_add_analyzers.yaml](./example_add_analyzers.yaml)). After this reload all analyzers will be active. | ||
|
||
Run the example with `ros2 launch diagnostic_aggregator example.launch.py` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/**: | ||
ros__parameters: | ||
optional: | ||
type: diagnostic_aggregator/GenericAnalyzer | ||
path: Optional | ||
contains: [ '/optional' ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
<license>BSD-3-Clause</license> | ||
|
||
<url type="website">http://www.ros.org/wiki/diagnostic_aggregator</url> | ||
|
||
<author>Kevin Watts</author> | ||
<author email="[email protected]">Brice Rebsamen</author> | ||
<author email="[email protected]">Arne Nordmann</author> | ||
|
@@ -22,6 +22,7 @@ | |
|
||
<build_depend>diagnostic_msgs</build_depend> | ||
<build_depend>pluginlib</build_depend> | ||
<build_depend>rcl_interfaces</build_depend> | ||
<build_depend>rclcpp</build_depend> | ||
<build_depend>std_msgs</build_depend> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/********************************************************************* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2009, Willow Garage, Inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of the Willow Garage nor the names of its | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just use the standard BSD sentences:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I change it? Now the license matches all the other files in the repo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, yeh I see what you mean now it can't stay willow garage :P |
||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*********************************************************************/ | ||
|
||
/**< \author Martin Cornelis */ | ||
|
||
#include <chrono> | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "rcl_interfaces/srv/set_parameters_atomically.hpp" | ||
#include "rcl_interfaces/msg/parameter.hpp" | ||
|
||
using namespace std::chrono_literals; | ||
|
||
class AddAnalyzer : public rclcpp::Node | ||
{ | ||
public: | ||
AddAnalyzer() | ||
: Node("add_analyzer_node", "", rclcpp::NodeOptions().allow_undeclared_parameters( | ||
true).automatically_declare_parameters_from_overrides(true)) | ||
{ | ||
client_ = this->create_client<rcl_interfaces::srv::SetParametersAtomically>( | ||
"/analyzers/set_parameters_atomically"); | ||
} | ||
|
||
void send_request() | ||
{ | ||
while (!client_->wait_for_service(1s)) { | ||
if (!rclcpp::ok()) { | ||
RCLCPP_ERROR(this->get_logger(), "Interrupted while waiting for the service. Exiting."); | ||
return; | ||
} | ||
RCLCPP_INFO_ONCE(this->get_logger(), "service not available, waiting ..."); | ||
} | ||
auto request = std::make_shared<rcl_interfaces::srv::SetParametersAtomically::Request>(); | ||
std::map<std::string, rclcpp::Parameter> parameters; | ||
|
||
if (!this->get_parameters("", parameters)) { | ||
RCLCPP_ERROR(this->get_logger(), "Failed to retrieve parameters"); | ||
} | ||
for (const auto & [param_name, param] : parameters) { | ||
// Find the suffix | ||
size_t suffix_start = param_name.find_last_of('.'); | ||
// Remove suffix if it exists | ||
if (suffix_start != std::string::npos) { | ||
std::string stripped_param_name = param_name.substr(0, suffix_start); | ||
// Check in map if the stripped param name with the added suffix "path" exists | ||
// This indicates the parameter is part of an analyzer description | ||
if (parameters.count(stripped_param_name + ".path") > 0) { | ||
RCLCPP_INFO(this->get_logger(), param_name.c_str()); | ||
auto parameter_msg = param.to_parameter_msg(); | ||
request->parameters.push_back(parameter_msg); | ||
} | ||
} | ||
} | ||
|
||
auto result = client_->async_send_request(request); | ||
// Wait for the result. | ||
if (rclcpp::spin_until_future_complete(this->get_node_base_interface(), result) == | ||
rclcpp::FutureReturnCode::SUCCESS) | ||
{ | ||
RCLCPP_INFO(this->get_logger(), "Parameters succesfully set"); | ||
} else { | ||
RCLCPP_ERROR(this->get_logger(), "Failed to set parameters"); | ||
} | ||
} | ||
|
||
private: | ||
rclcpp::Client<rcl_interfaces::srv::SetParametersAtomically>::SharedPtr client_; | ||
std::string analyzers_ns_ = "analyzers."; | ||
}; | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
rclcpp::init(argc, argv); | ||
|
||
auto add_analyzer = std::make_shared<AddAnalyzer>(); | ||
add_analyzer->send_request(); | ||
rclcpp::shutdown(); | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you write this code or adapted this from somewhere? If you wrote it yourself, this should be the BV where you work for, so
Copyright 2024 Nobleo Autonomous Solutions B.V.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrote it myself but just copied the pasta for the notice and forgot to make it Nobleo Technology or whatever it should be, will update.