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

#include <GalaxisNode.hpp>

Inheritance diagram for GalaxisNode:
Collaboration diagram for GalaxisNode:

Protected Member Functions

 GalaxisNode ()=delete
 
 GalaxisNode (std::string p_name, unsigned int p_heartbeatTimePeriod)
 
 GalaxisNode (std::string p_name)
 
template<typename MsgSPtr >
void tickSub (std::map< galaxis::serviceStates::State, std::function< void(const MsgSPtr)>> const *p_functionMapPtr, MsgSPtr const p_message)
 
template<typename... Args>
void tickPub (std::map< galaxis::serviceStates::State, std::function< void(Args...)>> const *p_functionMapPtr, Args... p_args)
 
void register_callback (std::function< void(galaxis::serviceStates::State)> p_function)
 
void service_state_callback (ServiceStateType::SharedPtr const p_msgSPtr)
 
galaxis::serviceStates::State get_current_service_state () const
 
void enable_parameters (std::function< rcl_interfaces::msg::SetParametersResult(const std::vector< rclcpp::Parameter > &)> callbackFunc)
 
void create_parameters (std::shared_ptr< json > configJsonSPtr)
 
json const & get_global_settings ()
 

Private Attributes

std::string m_nodeName = "nodename_not_set"
 
galaxis::serviceStates::State m_serviceState = galaxis::serviceStates::State::BOOTSTRAP
 
galaxis::ROSHeartbeat m_heartbeatHandler
 
rclcpp::Subscription< ServiceStateType >::SharedPtr m_serviceSubscription
 
rclcpp::Subscription< SystemSettingsType >::SharedPtr m_systemSettingsSubSPtr
 
std::function< void(galaxis::serviceStates::State)> m_callback_service_state
 
OnSetParametersCallbackHandle::SharedPtr m_parameterCallbackHandle
 
std::vector< std::string > m_rosParameterNamesVec
 
json m_globalSettings
 

Detailed Description

Definition at line 21 of file GalaxisNode.hpp.

Constructor & Destructor Documentation

◆ GalaxisNode() [1/3]

GalaxisNode::GalaxisNode ( )
protecteddelete

◆ GalaxisNode() [2/3]

GalaxisNode::GalaxisNode ( std::string  p_name,
unsigned int  p_heartbeatTimePeriod 
)
protected

Definition at line 10 of file GalaxisNode.cpp.

10  :
11  Node(p_name), m_heartbeatHandler(static_cast<rclcpp::Node*>(this), p_name, p_heartbeatTimePeriod) {
12 
13  m_nodeName = p_name;
14  galaxis::ros::create_subscription(this, m_serviceSubscription, std::bind(&GalaxisNode::service_state_callback, this, std::placeholders::_1));
15 
16  m_parameterCallbackHandle = nullptr;
17 
18  // load global settings: settings/global.json
19  try {
20  auto settings = galaxis::utils::read_json_file("settings/onstartup_global.json");
21  m_globalSettings = (*settings)["settings"];
22  }
23  catch (std::exception &e) {
24  log_warning("Failed to load Global System Settings!");
25  }
26 }

References galaxis::utils::log_warning(), m_globalSettings, m_nodeName, m_parameterCallbackHandle, m_serviceSubscription, galaxis::utils::read_json_file(), and service_state_callback().

Here is the call graph for this function:

◆ GalaxisNode() [3/3]

GalaxisNode::GalaxisNode ( std::string  p_name)
protected

Definition at line 27 of file GalaxisNode.cpp.

27 : GalaxisNode(p_name, 200) {}

Member Function Documentation

◆ create_parameters()

void GalaxisNode::create_parameters ( std::shared_ptr< json >  configJsonSPtr)
protected

Definition at line 81 of file GalaxisNode.cpp.

81  {
82  log("[GALAXIS_NODE] Create ROS parameters from JSON.");
83 
84  try {
85  for (json::iterator itSubSec = configJsonSPtr->begin(); itSubSec != configJsonSPtr->end(); ++itSubSec) {
86  for (json::iterator itParam = itSubSec.value().begin(); itParam != itSubSec.value().end(); ++itParam) {
87  std::string fullParameterName = itSubSec.key() + "." + itParam.key();
88 
89  rcl_interfaces::msg::ParameterDescriptor paramDesc;
90  paramDesc.description = fullParameterName;
91  if(itParam.value().is_number_integer()) {
92  this->declare_parameter<int>(fullParameterName.c_str(), itParam.value(), paramDesc);
93  }
94  else if(itParam.value().is_number_float()) {
95  this->declare_parameter<double>(fullParameterName.c_str(), itParam.value(), paramDesc);
96  }
97  else {
98  log_warning("[GALAXIS_NODE] Type of parameter ", fullParameterName, " is NOT valid (INT or FLOAT/DOUBLE). Skipping.");
99  }
100 
101  m_rosParameterNamesVec.push_back(fullParameterName);
102  }
103  }
104  }
105  catch(const std::exception& e) {
106  log_warning("[GALAXIS_NODE] Failed to create parameters!");
107  }
108 }

References galaxis::utils::log(), galaxis::utils::log_warning(), and m_rosParameterNamesVec.

Referenced by enable_parameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enable_parameters()

void GalaxisNode::enable_parameters ( std::function< rcl_interfaces::msg::SetParametersResult(const std::vector< rclcpp::Parameter > &)>  callbackFunc)
protected

Definition at line 69 of file GalaxisNode.cpp.

69  {
70  // read parameters from json, create ros params, run node implemented cb and set cb for new params
71  std::shared_ptr<json> nodeSettings = galaxis::utils::read_system_settings(m_nodeName);
72  this->create_parameters(nodeSettings);
73  auto result = callbackFunc(this->get_parameters(m_rosParameterNamesVec));
74  m_parameterCallbackHandle = this->add_on_set_parameters_callback(callbackFunc);
75 
76  if (result.successful == false) {
77  log_error("[GALAXIS_NODE] Can NOT enable parameter functionality. Reason:\n", result.reason);
78  }
79 }

References create_parameters(), galaxis::utils::log_error(), m_nodeName, m_parameterCallbackHandle, m_rosParameterNamesVec, and galaxis::utils::read_system_settings().

Referenced by AutoPilotNode::AutoPilotNode(), ControllerNode::ControllerNode(), RealSenseNode::RealSenseNode(), and StopLineDetection::StopLineDetection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_current_service_state()

galaxis::serviceStates::State GalaxisNode::get_current_service_state ( ) const
protected

Definition at line 65 of file GalaxisNode.cpp.

65  {
66  return m_serviceState;
67 }

References m_serviceState.

◆ get_global_settings()

json const & GalaxisNode::get_global_settings ( )
protected

Definition at line 119 of file GalaxisNode.cpp.

119  {
120  return m_globalSettings;
121 }

References m_globalSettings.

Referenced by AutoPilotNode::AutoPilotNode(), ControllerNode::ControllerNode(), and StopLineDetection::StopLineDetection().

Here is the caller graph for this function:

◆ register_callback()

void GalaxisNode::register_callback ( std::function< void(galaxis::serviceStates::State)>  p_function)
protected

Definition at line 29 of file GalaxisNode.cpp.

29  {
30  m_callback_service_state = p_function;
31 }

References m_callback_service_state.

◆ service_state_callback()

void GalaxisNode::service_state_callback ( ServiceStateType::SharedPtr const  p_msgSPtr)
protected

Definition at line 33 of file GalaxisNode.cpp.

33  {
34  switch(p_msgSPtr->state) {
35  case ServiceStateType::STATE_BOOTSTRAP:
36  RCLCPP_INFO(this->get_logger(), "galaxis::serviceStates::State: switch to BOOTSTRAP");
39  }
40  break;
41  case ServiceStateType::STATE_FREE_DRIVING:
42  RCLCPP_INFO(this->get_logger(), "galaxis::serviceStates::State: switch to FREE_DRIVING");
45  }
46  break;
47  case ServiceStateType::STATE_OBSTACLE_DRIVING:
48  RCLCPP_INFO(this->get_logger(), "galaxis::serviceStates::State: switch to OBSTACLE_DRIVING");
51  }
52  break;
53  default:
54  RCLCPP_ERROR(this->get_logger(), "galaxis::serviceStates::State not implemented. %i", m_serviceState);
55  // throw galaxis::Errors::NOT_IMPLEMENTED_ERROR();
56  break;
57  }
58 
59  m_serviceState = static_cast<galaxis::serviceStates::State>(p_msgSPtr->state);
60 
61  // set service state for heartbeat message
63 }

References galaxis::serviceStates::BOOTSTRAP, galaxis::serviceStates::FREE_DRIVING, m_callback_service_state, m_heartbeatHandler, m_serviceState, galaxis::serviceStates::OBSTACLE_DRIVING, and galaxis::ROSHeartbeat::set_service_state().

Referenced by GalaxisNode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tickPub()

template<typename... Args>
void GalaxisNode::tickPub ( std::map< galaxis::serviceStates::State, std::function< void(Args...)>> const *  p_functionMapPtr,
Args...  p_args 
)
inlineprotected

Definition at line 55 of file GalaxisNode.hpp.

55  {
56  if(p_functionMapPtr->find(m_serviceState) != p_functionMapPtr->end()) {
57  p_functionMapPtr->at(m_serviceState)(p_args...);
58  } else {
59  RCLCPP_INFO(this->get_logger(), "No Pub/Sub implemented for %i", m_serviceState);
60  }
61  }

References m_serviceState.

◆ tickSub()

template<typename MsgSPtr >
void GalaxisNode::tickSub ( std::map< galaxis::serviceStates::State, std::function< void(const MsgSPtr)>> const *  p_functionMapPtr,
MsgSPtr const  p_message 
)
inlineprotected

Definition at line 46 of file GalaxisNode.hpp.

46  {
47  if(p_functionMapPtr->find(m_serviceState) != p_functionMapPtr->end()) {
48  p_functionMapPtr->at(m_serviceState)(p_message);
49  } else {
50  RCLCPP_INFO(this->get_logger(), "No Pub/Sub implemented for %i", m_serviceState);
51  }
52  }

References m_serviceState.

Member Data Documentation

◆ m_callback_service_state

std::function<void(galaxis::serviceStates::State)> GalaxisNode::m_callback_service_state
private

Definition at line 32 of file GalaxisNode.hpp.

Referenced by register_callback(), and service_state_callback().

◆ m_globalSettings

json GalaxisNode::m_globalSettings
private

Definition at line 38 of file GalaxisNode.hpp.

Referenced by GalaxisNode(), and get_global_settings().

◆ m_heartbeatHandler

galaxis::ROSHeartbeat GalaxisNode::m_heartbeatHandler
private

Definition at line 27 of file GalaxisNode.hpp.

Referenced by service_state_callback().

◆ m_nodeName

std::string GalaxisNode::m_nodeName = "nodename_not_set"
private

Definition at line 23 of file GalaxisNode.hpp.

Referenced by enable_parameters(), and GalaxisNode().

◆ m_parameterCallbackHandle

OnSetParametersCallbackHandle::SharedPtr GalaxisNode::m_parameterCallbackHandle
private

Definition at line 35 of file GalaxisNode.hpp.

Referenced by enable_parameters(), and GalaxisNode().

◆ m_rosParameterNamesVec

std::vector<std::string> GalaxisNode::m_rosParameterNamesVec
private

Definition at line 36 of file GalaxisNode.hpp.

Referenced by create_parameters(), and enable_parameters().

◆ m_serviceState

galaxis::serviceStates::State GalaxisNode::m_serviceState = galaxis::serviceStates::State::BOOTSTRAP
private

◆ m_serviceSubscription

rclcpp::Subscription<ServiceStateType>::SharedPtr GalaxisNode::m_serviceSubscription
private

Definition at line 29 of file GalaxisNode.hpp.

Referenced by GalaxisNode().

◆ m_systemSettingsSubSPtr

rclcpp::Subscription<SystemSettingsType>::SharedPtr GalaxisNode::m_systemSettingsSubSPtr
private

Definition at line 30 of file GalaxisNode.hpp.


The documentation for this class was generated from the following files:
galaxis::serviceStates::OBSTACLE_DRIVING
@ OBSTACLE_DRIVING
Definition: ServiceState.hpp:13
galaxis::utils::log_error
void log_error(const Args &... args)
Definition: logger.hpp:50
GalaxisNode::create_parameters
void create_parameters(std::shared_ptr< json > configJsonSPtr)
Definition: GalaxisNode.cpp:81
galaxis::utils::log_warning
void log_warning(const Args &... args)
Definition: logger.hpp:41
galaxis::utils::read_system_settings
shared_ptr< json > read_system_settings(std::string key)
Definition: settings.cpp:14
galaxis::serviceStates::BOOTSTRAP
@ BOOTSTRAP
Definition: ServiceState.hpp:10
GalaxisNode::service_state_callback
void service_state_callback(ServiceStateType::SharedPtr const p_msgSPtr)
Definition: GalaxisNode.cpp:33
GalaxisNode::m_callback_service_state
std::function< void(galaxis::serviceStates::State)> m_callback_service_state
Definition: GalaxisNode.hpp:32
galaxis::utils::read_json_file
shared_ptr< json > read_json_file(std::string path)
Definition: settings.cpp:5
galaxis::ROSHeartbeat::set_service_state
void set_service_state(::galaxis::serviceStates::State const p_serviceState)
Definition: ros_heartbeat.cpp:38
GalaxisNode::GalaxisNode
GalaxisNode()=delete
GalaxisNode::m_serviceSubscription
rclcpp::Subscription< ServiceStateType >::SharedPtr m_serviceSubscription
Definition: GalaxisNode.hpp:29
GalaxisNode::m_heartbeatHandler
galaxis::ROSHeartbeat m_heartbeatHandler
Definition: GalaxisNode.hpp:27
GalaxisNode::m_nodeName
std::string m_nodeName
Definition: GalaxisNode.hpp:23
galaxis::serviceStates::FREE_DRIVING
@ FREE_DRIVING
Definition: ServiceState.hpp:12
GalaxisNode::m_parameterCallbackHandle
OnSetParametersCallbackHandle::SharedPtr m_parameterCallbackHandle
Definition: GalaxisNode.hpp:35
galaxis::utils::log
void log(const Args &... args)
Definition: logger.hpp:33
GalaxisNode::m_serviceState
galaxis::serviceStates::State m_serviceState
Definition: GalaxisNode.hpp:25
GalaxisNode::m_globalSettings
json m_globalSettings
Definition: GalaxisNode.hpp:38
GalaxisNode::m_rosParameterNamesVec
std::vector< std::string > m_rosParameterNamesVec
Definition: GalaxisNode.hpp:36
galaxis::serviceStates::State
State
Definition: ServiceState.hpp:9