Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
ControllerNode.hpp
Go to the documentation of this file.
1 #ifndef _CONTROLLERNODE_HPP_
2 #define _CONTROLLERNODE_HPP_
3 
4 #include <memory>
5 #include <mutex>
6 #include <atomic>
7 
8 #include "rclcpp/rclcpp.hpp"
10 #include "std_msgs/msg/string.hpp"
11 #include <galaxis/messages.hpp>
12 #include <galaxis/Errors.hpp>
13 
14 #include <control/control.hpp>
15 #include <utils/logger.hpp>
16 #include <utils/poly.hpp>
17 #include <std_msgs/msg/u_int8.hpp>
18 
19 #include <image_transport/image_transport.h>
20 
21 
22 class ControllerNode : public GalaxisNode {
23 private:
24  bool m_debugMode = false;
25  bool m_simulationMode = false;
26  std::atomic<bool> m_disableController;
27 
28  std::atomic<bool> m_stop_ControllerNode = false;
29  std::atomic<bool> m_start_ParkingNode = false;
30 
31  // Publishers
32  rclcpp::Publisher<ControlMotionType>::SharedPtr m_controlValuesPubSPtr;
33  rclcpp::Publisher<ControlLightsType>::SharedPtr m_controlLightsPubSPtr;
34  rclcpp::Publisher<DebugControllerType>::SharedPtr m_debugControllerPubSPtr;
35  rclcpp::Publisher<SimulationVehicleControlType>::SharedPtr m_simulationVehicleControlPubSPtr;
36  rclcpp::Publisher<std_msgs::msg::UInt8>::SharedPtr m_lightsStdPublisherSPtr;
37 
38  //Subscribers
39  rclcpp::Subscription<PathpolynomType>::SharedPtr m_pathPolynomSubSPtr;
40  rclcpp::Subscription<ControllerReferenceType>::SharedPtr m_controllerRefSubSPtr;
41  rclcpp::Subscription<MeasurementsType>::SharedPtr m_measurementSubSPtr;
42  //Debug
43  image_transport::Subscriber m_localMapDebugImgSubscription;
44  image_transport::Publisher m_localMapDebugTrajectoryImgPublisher;
45 
46  // Measurements
47  MeasurementsType::SharedPtr m_lastReceivedMeasurementSPtr;
48  std::mutex m_measurementMtx;
49 
50  //ControlLights
51  std::shared_ptr<ControlLightsType> m_lastSentControlLights;
52 
53  // Pathpolynom
54  PathpolynomType::SharedPtr m_lastReceivedPathpolynomSPtr;
55  std::shared_ptr<PolySpline> m_currentReferenceSplineSPtr;
56  std::shared_ptr<galaxis::line_markings_reference_t> m_currentLineMarkingReferenceSPtr;
57 
58  std::mutex m_pathPolynomMtx;
59  std::atomic<int64_t> m_lastPolynomUpdateTimestamp;
60 
61  // Control
62  std::shared_ptr<galaxis::control::TwoAndAHalfCarrots> m_controlTwoAndAHalfCarrotsSPtr;
63  std::shared_ptr<std::vector<float>> m_turnAnglesSPtr;
64  std::mutex m_controlMtx;
65 
66  // - Current settings
67  std::atomic<float> m_currentVelocity = 0.f; // in m/s
68  std::atomic<float> m_currentVelocityApplied = 0.f; // in m/s
69  std::atomic<float> m_currentVelocityReference = 0.f; // in m/s
70  std::tuple<float, float> m_currentTurnAngles = std::make_tuple(0.f, 0.f); // in radiance
71  std::tuple<std::atomic<bool>, std::atomic<bool>> m_currentIndicatorState = std::make_tuple(false, false); // in radiance
72  std::atomic<float> m_minVelocity = 0.4f; // min Velocity for steering in m/s // 45deg = m_minVelocity
73  std::atomic<float> m_velocityRollingAverageFactorForNewVelocity = 0.01f;
74 
75 public:
77 
78 private:
79  void loop();
80  void send_debug_messages();
82 
83  void calculate_erpm();
84  void calculate_turn_angle();
85 
86  // publish
87  void publish_control_values(ControlMotionType::UniquePtr msg);
88 
89  // subscribe
90  void on_measurement_callback(MeasurementsType::SharedPtr msg);
91  void on_pathpolynom_callback(PathpolynomType::SharedPtr msg);
92  void on_controller_reference_callback(ControllerReferenceType::SharedPtr msg);
93  // debug
94  void on_map_debug_image_callback(const sensor_msgs::msg::Image::ConstSharedPtr& msg);
95 
96  rcl_interfaces::msg::SetParametersResult new_parameters_callback(const std::vector<rclcpp::Parameter>& parameters);
97 };
98 
99 #endif // _CONTROLLERNODE_HPP_
ControllerNode::m_lastReceivedMeasurementSPtr
MeasurementsType::SharedPtr m_lastReceivedMeasurementSPtr
Definition: ControllerNode.hpp:47
ControllerNode::m_minVelocity
std::atomic< float > m_minVelocity
Definition: ControllerNode.hpp:72
ControllerNode::on_controller_reference_callback
void on_controller_reference_callback(ControllerReferenceType::SharedPtr msg)
Definition: ControllerNode.cpp:353
ControllerNode::m_lastSentControlLights
std::shared_ptr< ControlLightsType > m_lastSentControlLights
Definition: ControllerNode.hpp:51
ControllerNode::loop
void loop()
Definition: ControllerNode.cpp:122
ControllerNode::on_map_debug_image_callback
void on_map_debug_image_callback(const sensor_msgs::msg::Image::ConstSharedPtr &msg)
Definition: ControllerNode.cpp:363
ControllerNode::m_controlValuesPubSPtr
rclcpp::Publisher< ControlMotionType >::SharedPtr m_controlValuesPubSPtr
Definition: ControllerNode.hpp:32
ControllerNode::send_simulation_messages
void send_simulation_messages()
Definition: ControllerNode.cpp:249
ControllerNode::m_debugControllerPubSPtr
rclcpp::Publisher< DebugControllerType >::SharedPtr m_debugControllerPubSPtr
Definition: ControllerNode.hpp:34
ControllerNode::m_debugMode
bool m_debugMode
Definition: ControllerNode.hpp:24
ControllerNode::m_turnAnglesSPtr
std::shared_ptr< std::vector< float > > m_turnAnglesSPtr
Definition: ControllerNode.hpp:63
ControllerNode::m_simulationMode
bool m_simulationMode
Definition: ControllerNode.hpp:25
ControllerNode::m_currentTurnAngles
std::tuple< float, float > m_currentTurnAngles
Definition: ControllerNode.hpp:70
ControllerNode::m_controlMtx
std::mutex m_controlMtx
Definition: ControllerNode.hpp:64
ControllerNode::m_disableController
std::atomic< bool > m_disableController
Definition: ControllerNode.hpp:26
ControllerNode::ControllerNode
ControllerNode()
Definition: ControllerNode.cpp:19
ControllerNode::calculate_erpm
void calculate_erpm()
ControllerNode::m_controllerRefSubSPtr
rclcpp::Subscription< ControllerReferenceType >::SharedPtr m_controllerRefSubSPtr
Definition: ControllerNode.hpp:40
control.hpp
poly.hpp
ControllerNode::m_localMapDebugImgSubscription
image_transport::Subscriber m_localMapDebugImgSubscription
Definition: ControllerNode.hpp:43
ControllerNode::calculate_turn_angle
void calculate_turn_angle()
Definition: ControllerNode.cpp:259
ControllerNode::m_start_ParkingNode
std::atomic< bool > m_start_ParkingNode
Definition: ControllerNode.hpp:29
ControllerNode
Definition: ControllerNode.hpp:22
ControllerNode::m_simulationVehicleControlPubSPtr
rclcpp::Publisher< SimulationVehicleControlType >::SharedPtr m_simulationVehicleControlPubSPtr
Definition: ControllerNode.hpp:35
ControllerNode::m_controlLightsPubSPtr
rclcpp::Publisher< ControlLightsType >::SharedPtr m_controlLightsPubSPtr
Definition: ControllerNode.hpp:33
ControllerNode::m_localMapDebugTrajectoryImgPublisher
image_transport::Publisher m_localMapDebugTrajectoryImgPublisher
Definition: ControllerNode.hpp:44
GalaxisNode.hpp
ControllerNode::publish_control_values
void publish_control_values(ControlMotionType::UniquePtr msg)
Definition: ControllerNode.cpp:343
ControllerNode::m_measurementSubSPtr
rclcpp::Subscription< MeasurementsType >::SharedPtr m_measurementSubSPtr
Definition: ControllerNode.hpp:41
ControllerNode::m_lightsStdPublisherSPtr
rclcpp::Publisher< std_msgs::msg::UInt8 >::SharedPtr m_lightsStdPublisherSPtr
Definition: ControllerNode.hpp:36
ControllerNode::on_pathpolynom_callback
void on_pathpolynom_callback(PathpolynomType::SharedPtr msg)
Definition: ControllerNode.cpp:313
ControllerNode::on_measurement_callback
void on_measurement_callback(MeasurementsType::SharedPtr msg)
Definition: ControllerNode.cpp:302
ControllerNode::m_controlTwoAndAHalfCarrotsSPtr
std::shared_ptr< galaxis::control::TwoAndAHalfCarrots > m_controlTwoAndAHalfCarrotsSPtr
Definition: ControllerNode.hpp:62
ControllerNode::m_pathPolynomSubSPtr
rclcpp::Subscription< PathpolynomType >::SharedPtr m_pathPolynomSubSPtr
Definition: ControllerNode.hpp:39
ControllerNode::m_currentVelocityApplied
std::atomic< float > m_currentVelocityApplied
Definition: ControllerNode.hpp:68
ControllerNode::m_lastPolynomUpdateTimestamp
std::atomic< int64_t > m_lastPolynomUpdateTimestamp
Definition: ControllerNode.hpp:59
ControllerNode::m_lastReceivedPathpolynomSPtr
PathpolynomType::SharedPtr m_lastReceivedPathpolynomSPtr
Definition: ControllerNode.hpp:54
ControllerNode::send_debug_messages
void send_debug_messages()
Definition: ControllerNode.cpp:204
ControllerNode::m_stop_ControllerNode
std::atomic< bool > m_stop_ControllerNode
Definition: ControllerNode.hpp:28
ControllerNode::m_currentReferenceSplineSPtr
std::shared_ptr< PolySpline > m_currentReferenceSplineSPtr
Definition: ControllerNode.hpp:55
GalaxisNode
Definition: GalaxisNode.hpp:21
ControllerNode::m_measurementMtx
std::mutex m_measurementMtx
Definition: ControllerNode.hpp:48
ControllerNode::m_pathPolynomMtx
std::mutex m_pathPolynomMtx
Definition: ControllerNode.hpp:58
ControllerNode::m_currentLineMarkingReferenceSPtr
std::shared_ptr< galaxis::line_markings_reference_t > m_currentLineMarkingReferenceSPtr
Definition: ControllerNode.hpp:56
ControllerNode::m_velocityRollingAverageFactorForNewVelocity
std::atomic< float > m_velocityRollingAverageFactorForNewVelocity
Definition: ControllerNode.hpp:73
logger.hpp
ControllerNode::new_parameters_callback
rcl_interfaces::msg::SetParametersResult new_parameters_callback(const std::vector< rclcpp::Parameter > &parameters)
Definition: ControllerNode.cpp:431
ControllerNode::m_currentIndicatorState
std::tuple< std::atomic< bool >, std::atomic< bool > > m_currentIndicatorState
Definition: ControllerNode.hpp:71
ControllerNode::m_currentVelocity
std::atomic< float > m_currentVelocity
Definition: ControllerNode.hpp:67
messages.hpp
Errors.hpp
ControllerNode::m_currentVelocityReference
std::atomic< float > m_currentVelocityReference
Definition: ControllerNode.hpp:69