Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
testSetupNode Class Reference

#include <testSetupNode.hpp>

Inheritance diagram for testSetupNode:
Collaboration diagram for testSetupNode:

Public Member Functions

 testSetupNode (void)
 
bool send_settings_ (std::shared_ptr< std::map< std::string, std::vector< rclcpp::Parameter >>> p_settingsGUIParameterMap)
 

Private Attributes

std::mutex m_sendMtx
 

Detailed Description

Definition at line 10 of file testSetupNode.hpp.

Constructor & Destructor Documentation

◆ testSetupNode()

testSetupNode::testSetupNode ( void  )

Definition at line 16 of file testSetupNode.cpp.

16  :
17  rclcpp::Node("testSetupNode") {
18 }

Member Function Documentation

◆ send_settings_()

bool testSetupNode::send_settings_ ( std::shared_ptr< std::map< std::string, std::vector< rclcpp::Parameter >>>  p_settingsGUIParameterMap)

Definition at line 20 of file testSetupNode.cpp.

20  {
21  m_sendMtx.lock();
22 
23  bool status = true; // successful
24 
25  for (auto const& [nodeName, parametersVec] : *p_settingsGUIParameterMap) {
26  // 1. define a ParametersClient (which is a wrapper around parameter services)
27  // which can get and set the parameters of each ROS node
28  auto parameters_client = std::make_shared<rclcpp::SyncParametersClient>(this, "/" + nodeName);
29 
30  if(!parameters_client->wait_for_service(1s)) {
31  if (!rclcpp::ok()) {
32  RCLCPP_ERROR(this->get_logger(), "Interrupted while waiting for the service of node %s. Exiting.", nodeName.c_str());
33  rclcpp::shutdown();
34  }
35 
36  RCLCPP_INFO(this->get_logger(), "Service for Node %s not available, abort sending parameters to this node...", nodeName.c_str());
37  status = false;
38  continue;
39  }
40 
41  if(parameters_client == nullptr) {
42  RCLCPP_ERROR(this->get_logger(), "parameters_client is null");
43  // throw galaxis::Errors::POINTER_ERROR();
44  status = false;
45  continue;
46  }
47 
48  // 2. Set parameters, if they were changed.
49  for (auto & parameter : parametersVec)
50  {
51  rclcpp::ParameterValue previousParameterValue = parameters_client->get_parameters({parameter.get_name()}).at(0).get_parameter_value();
52  if (parameter.get_parameter_value() != previousParameterValue) {
53  auto set_parameters_results = parameters_client->set_parameters(
54  {
55  rclcpp::Parameter(parameter.get_name(), parameter.get_parameter_value()),
56  }
57  );
58 
59  // Check to see if the parameter was set. Log updated parameters.
60  for (auto & result : set_parameters_results) {
61  if (!result.successful) {
62  RCLCPP_ERROR(this->get_logger(), "Failed to set parameter: %s", result.reason.c_str());
63  }
64  else {
65  RCLCPP_WARN(this->get_logger(), "[New Parameter] Set & changed parameter successfully: %s = %s", parameter.get_name().c_str(), parameter.value_to_string().c_str());
66  }
67  }
68  }
69  else {
70  RCLCPP_INFO(this->get_logger(), "No change: %s = %s", parameter.get_name().c_str(), parameter.value_to_string().c_str());
71  }
72  }
73  RCLCPP_INFO(this->get_logger(), "====================================== END OF SET PARAMETER LOG %s ======================================", nodeName.c_str());
74  }
75  m_sendMtx.unlock();
76 
77  return status;
78 }

References m_sendMtx.

Referenced by JsonEditorMain::on_Send_clicked().

Here is the caller graph for this function:

Member Data Documentation

◆ m_sendMtx

std::mutex testSetupNode::m_sendMtx
private

Definition at line 12 of file testSetupNode.hpp.

Referenced by send_settings_().


The documentation for this class was generated from the following files:
testSetupNode::m_sendMtx
std::mutex m_sendMtx
Definition: testSetupNode.hpp:12