Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
GalaxisNode.hpp
Go to the documentation of this file.
1 #ifndef GALAXIS_NODE_HPP_
2 #define GALAXIS_NODE_HPP_
3 
6 #include "galaxis/messages.hpp"
7 #include "galaxis/Errors.hpp"
8 #include "rclcpp/rclcpp.hpp"
9 #include <chrono>
10 #include <map>
11 #include <memory>
12 #include <functional>
13 
14 #include "rcl_interfaces/msg/set_parameters_result.hpp"
15 #include "rcl_interfaces/msg/floating_point_range.hpp"
16 #include "rcl_interfaces/msg/parameter_descriptor.hpp"
17 
18 #include <nlohmann/json.hpp>
19 using nlohmann::json;
20 
21 class GalaxisNode : public rclcpp::Node {
22 private:
23  std::string m_nodeName = "nodename_not_set";
24 
26 
28 
29  rclcpp::Subscription<ServiceStateType>::SharedPtr m_serviceSubscription;
30  rclcpp::Subscription<SystemSettingsType>::SharedPtr m_systemSettingsSubSPtr;
31 
33 
34  // parameters
35  OnSetParametersCallbackHandle::SharedPtr m_parameterCallbackHandle;
36  std::vector<std::string> m_rosParameterNamesVec;
37 
39 
40 protected:
41  GalaxisNode() = delete;
42  GalaxisNode(std::string p_name, unsigned int p_heartbeatTimePeriod);
43  GalaxisNode(std::string p_name);
44 
45  template <typename MsgSPtr>
46  void tickSub(std::map<galaxis::serviceStates::State, std::function<void(const MsgSPtr)>> const* p_functionMapPtr, MsgSPtr const p_message) {
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  }
53 
54  template <typename... Args>
55  void tickPub(std::map<galaxis::serviceStates::State, std::function<void(Args...)>> const* p_functionMapPtr, Args... p_args) {
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  }
62 
63  void register_callback(std::function<void(galaxis::serviceStates::State)> p_function);
64  void service_state_callback(ServiceStateType::SharedPtr const p_msgSPtr);
66 
67  // system/node settings
68  void enable_parameters(std::function<rcl_interfaces::msg::SetParametersResult(const std::vector<rclcpp::Parameter>&)> callbackFunc);
69  void create_parameters(std::shared_ptr<json> configJsonSPtr);
70  // virtual rcl_interfaces::msg::SetParametersResult new_parameters_callback(const std::vector<rclcpp::Parameter>& parameters);
71 
72 
73  json const& get_global_settings();
74 };
75 
76 #endif // !GALAXIS_NODE_HPP_
GalaxisNode::enable_parameters
void enable_parameters(std::function< rcl_interfaces::msg::SetParametersResult(const std::vector< rclcpp::Parameter > &)> callbackFunc)
Definition: GalaxisNode.cpp:69
json
nlohmann::json json
Definition: AutoPilotNode.hpp:21
GalaxisNode::create_parameters
void create_parameters(std::shared_ptr< json > configJsonSPtr)
Definition: GalaxisNode.cpp:81
galaxis::ROSHeartbeat
Definition: ros_heartbeat.hpp: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
GalaxisNode::register_callback
void register_callback(std::function< void(galaxis::serviceStates::State)> p_function)
Definition: GalaxisNode.cpp:29
GalaxisNode::get_global_settings
json const & get_global_settings()
Definition: GalaxisNode.cpp:119
GalaxisNode::tickSub
void tickSub(std::map< galaxis::serviceStates::State, std::function< void(const MsgSPtr)>> const *p_functionMapPtr, MsgSPtr const p_message)
Definition: GalaxisNode.hpp:46
GalaxisNode::GalaxisNode
GalaxisNode()=delete
GalaxisNode::m_serviceSubscription
rclcpp::Subscription< ServiceStateType >::SharedPtr m_serviceSubscription
Definition: GalaxisNode.hpp:29
GalaxisNode::m_systemSettingsSubSPtr
rclcpp::Subscription< SystemSettingsType >::SharedPtr m_systemSettingsSubSPtr
Definition: GalaxisNode.hpp:30
ServiceState.hpp
GalaxisNode::tickPub
void tickPub(std::map< galaxis::serviceStates::State, std::function< void(Args...)>> const *p_functionMapPtr, Args... p_args)
Definition: GalaxisNode.hpp:55
GalaxisNode::m_heartbeatHandler
galaxis::ROSHeartbeat m_heartbeatHandler
Definition: GalaxisNode.hpp:27
GalaxisNode
Definition: GalaxisNode.hpp:21
GalaxisNode::get_current_service_state
galaxis::serviceStates::State get_current_service_state() const
Definition: GalaxisNode.cpp:65
GalaxisNode::m_nodeName
std::string m_nodeName
Definition: GalaxisNode.hpp:23
ros_heartbeat.hpp
GalaxisNode::m_parameterCallbackHandle
OnSetParametersCallbackHandle::SharedPtr m_parameterCallbackHandle
Definition: GalaxisNode.hpp:35
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
messages.hpp
Errors.hpp
galaxis::serviceStates::State
State
Definition: ServiceState.hpp:9