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

#include <ControllerNode.hpp>

Inheritance diagram for ControllerNode:
Collaboration diagram for ControllerNode:

Public Member Functions

 ControllerNode ()
 

Private Member Functions

void loop ()
 
void send_debug_messages ()
 
void send_simulation_messages ()
 
void calculate_erpm ()
 
void calculate_turn_angle ()
 
void publish_control_values (ControlMotionType::UniquePtr msg)
 
void on_measurement_callback (MeasurementsType::SharedPtr msg)
 
void on_pathpolynom_callback (PathpolynomType::SharedPtr msg)
 
void on_controller_reference_callback (ControllerReferenceType::SharedPtr msg)
 
void on_map_debug_image_callback (const sensor_msgs::msg::Image::ConstSharedPtr &msg)
 
rcl_interfaces::msg::SetParametersResult new_parameters_callback (const std::vector< rclcpp::Parameter > &parameters)
 

Private Attributes

bool m_debugMode = false
 
bool m_simulationMode = false
 
std::atomic< bool > m_disableController
 
std::atomic< bool > m_stop_ControllerNode = false
 
std::atomic< bool > m_start_ParkingNode = false
 
rclcpp::Publisher< ControlMotionType >::SharedPtr m_controlValuesPubSPtr
 
rclcpp::Publisher< ControlLightsType >::SharedPtr m_controlLightsPubSPtr
 
rclcpp::Publisher< DebugControllerType >::SharedPtr m_debugControllerPubSPtr
 
rclcpp::Publisher< SimulationVehicleControlType >::SharedPtr m_simulationVehicleControlPubSPtr
 
rclcpp::Publisher< std_msgs::msg::UInt8 >::SharedPtr m_lightsStdPublisherSPtr
 
rclcpp::Subscription< PathpolynomType >::SharedPtr m_pathPolynomSubSPtr
 
rclcpp::Subscription< ControllerReferenceType >::SharedPtr m_controllerRefSubSPtr
 
rclcpp::Subscription< MeasurementsType >::SharedPtr m_measurementSubSPtr
 
image_transport::Subscriber m_localMapDebugImgSubscription
 
image_transport::Publisher m_localMapDebugTrajectoryImgPublisher
 
MeasurementsType::SharedPtr m_lastReceivedMeasurementSPtr
 
std::mutex m_measurementMtx
 
std::shared_ptr< ControlLightsType > m_lastSentControlLights
 
PathpolynomType::SharedPtr m_lastReceivedPathpolynomSPtr
 
std::shared_ptr< PolySpline > m_currentReferenceSplineSPtr
 
std::shared_ptr< galaxis::line_markings_reference_t > m_currentLineMarkingReferenceSPtr
 
std::mutex m_pathPolynomMtx
 
std::atomic< int64_t > m_lastPolynomUpdateTimestamp
 
std::shared_ptr< galaxis::control::TwoAndAHalfCarrots > m_controlTwoAndAHalfCarrotsSPtr
 
std::shared_ptr< std::vector< float > > m_turnAnglesSPtr
 
std::mutex m_controlMtx
 
std::atomic< float > m_currentVelocity = 0.f
 
std::atomic< float > m_currentVelocityApplied = 0.f
 
std::atomic< float > m_currentVelocityReference = 0.f
 
std::tuple< float, float > m_currentTurnAngles = std::make_tuple(0.f, 0.f)
 
std::tuple< std::atomic< bool >, std::atomic< bool > > m_currentIndicatorState = std::make_tuple(false, false)
 
std::atomic< float > m_minVelocity = 0.4f
 
std::atomic< float > m_velocityRollingAverageFactorForNewVelocity = 0.01f
 

Additional Inherited Members

- Protected Member Functions inherited from GalaxisNode
 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 ()
 

Detailed Description

Definition at line 22 of file ControllerNode.hpp.

Constructor & Destructor Documentation

◆ ControllerNode()

ControllerNode::ControllerNode ( )

Definition at line 19 of file ControllerNode.cpp.

19  :
20  GalaxisNode("ControllerNode") {
21 
22  log("Starting ControllerNode...");
23 
24  galaxis::ros::create_subscription(this,
26  std::bind(&ControllerNode::on_measurement_callback, this, _1));
27  galaxis::ros::create_subscription(this,
29  std::bind(&ControllerNode::on_pathpolynom_callback, this, _1));
30 
31  galaxis::ros::create_subscription(this,
34 
35  galaxis::ros::create_publisher(this, m_controlValuesPubSPtr);
36  galaxis::ros::create_publisher(this, m_controlLightsPubSPtr);
37  galaxis::ros::create_publisher(this, m_debugControllerPubSPtr);
38 
39 
40  rclcpp::QoS qosParamsR = get_qos_profile(QOS_RELIABLE);
41  m_lightsStdPublisherSPtr = this->create_publisher<std_msgs::msg::UInt8>("/lights/std_msg", qosParamsR);
42 
43  //Debug MapDrawTrajectory
44  m_localMapDebugTrajectoryImgPublisher = image_transport::create_publisher(this, TOPIC_AP_CONTROLLER_DATA_DEBUG);
45 
46  // Simulation Adapter Publisher
47  rclcpp::QoS qosParams = get_qos_profile(QOS_BEST_EFFORT);
48  m_simulationVehicleControlPubSPtr = this->create_publisher<SimulationVehicleControlType>("galaxis/simulation/remotecontrol", qosParams);
49 
50  // Configuration
51  // m_turnAnglesSPtr = galaxis::utils::read_from_file_to_float("settings/onstartup_control_turn_angles.csv");
52  m_turnAnglesSPtr = std::make_shared<vector<float>>();
53  m_turnAnglesSPtr->push_back(-0.35);
54  m_turnAnglesSPtr->push_back(-0.30);
55  m_turnAnglesSPtr->push_back(-0.24);
56  m_turnAnglesSPtr->push_back(-0.20);
57  m_turnAnglesSPtr->push_back(-0.16);
58  m_turnAnglesSPtr->push_back(-0.12);
59  m_turnAnglesSPtr->push_back(-0.08);
60  m_turnAnglesSPtr->push_back(-0.04);
61  m_turnAnglesSPtr->push_back(-0.02);
62  m_turnAnglesSPtr->push_back(0);
63  m_turnAnglesSPtr->push_back(0.02);
64  m_turnAnglesSPtr->push_back(0.04);
65  m_turnAnglesSPtr->push_back(0.08);
66  m_turnAnglesSPtr->push_back(0.12);
67  m_turnAnglesSPtr->push_back(0.16);
68  m_turnAnglesSPtr->push_back(0.20);
69  m_turnAnglesSPtr->push_back(0.24);
70  m_turnAnglesSPtr->push_back(0.30);
71  m_turnAnglesSPtr->push_back(0.35);
72 
73  float horizonStepSize = 0.5f;
74  int errorAccuracyStepsPerHorizon = 4;
76  float errorIncreaseForFirstHorizon = 4;
77 
78  // Further Config from file
79  std::string configPath = "settings/onstartup_controller.json";
80  auto settingsJsonSPtr = read_json_file(configPath);
81  json& settingsJson = (*settingsJsonSPtr)["settings"];
82 
83  if(this->get_global_settings()["simulation_mode"]) {
84  m_simulationMode = true;
86  }
87  m_debugMode = settingsJson["debug_mode"];
88 
89  log("Configuration:\n - SimulationMode: ", m_simulationMode ? "ENABLED" : "DISABLED");
90  log(" - DebugMode: ", m_debugMode ? "ENABLED" : "DISABLED");
91  log("CarConfiguration:\n - CarWheelbase: ", carWheelbase);
92 
93  if (m_simulationMode || m_debugMode) sleep(1); // to view settings
94 
95  m_controlTwoAndAHalfCarrotsSPtr = std::make_shared<TwoAndAHalfCarrots>(TwoAndAHalfCarrots(m_turnAnglesSPtr, horizonStepSize, 2 /* horizon */, errorAccuracyStepsPerHorizon, carWheelbase, errorIncreaseForFirstHorizon));
96 
97  m_currentReferenceSplineSPtr = std::make_shared<PolySpline>();
98  m_currentReferenceSplineSPtr->add_polynom(-100, 100, galaxis::polynom{ 0, 0, 0, 0 });
99 
100  m_currentVelocity = 0.0f;
102 
104 
105 
106  // debug subscription
107  if(settingsJson["publish_map_trajectory_merged_debug_msg"] == true) {
108  m_localMapDebugImgSubscription = image_transport::create_subscription(
109  this,
110  galaxis::ros::TOPIC_AP_DATA_IMAGE_DEBUG,
111  std::bind(&ControllerNode::on_map_debug_image_callback, this, _1),
112  "raw");
113  }
114 
115  this->enable_parameters(std::bind(&ControllerNode::new_parameters_callback, this, std::placeholders::_1));
116 
117  // start controller loop
118  m_disableController = false;
119  std::thread(&ControllerNode::loop, this).detach();
120 }

References calculate_turn_angle(), galaxis::controllerSettings::carWheelbase, galaxis::controllerSettings::carWheelbaseSimulationDrDrift, GalaxisNode::enable_parameters(), GalaxisNode::get_global_settings(), galaxis::utils::log(), loop(), m_controllerRefSubSPtr, m_controlLightsPubSPtr, m_controlTwoAndAHalfCarrotsSPtr, m_controlValuesPubSPtr, m_currentReferenceSplineSPtr, m_currentVelocity, m_currentVelocityApplied, m_debugControllerPubSPtr, m_debugMode, m_disableController, m_lightsStdPublisherSPtr, m_localMapDebugImgSubscription, m_localMapDebugTrajectoryImgPublisher, m_measurementSubSPtr, m_pathPolynomSubSPtr, m_simulationMode, m_simulationVehicleControlPubSPtr, m_turnAnglesSPtr, new_parameters_callback(), on_controller_reference_callback(), on_map_debug_image_callback(), on_measurement_callback(), on_pathpolynom_callback(), and galaxis::utils::read_json_file().

Here is the call graph for this function:

Member Function Documentation

◆ calculate_erpm()

void ControllerNode::calculate_erpm ( )
private

◆ calculate_turn_angle()

void ControllerNode::calculate_turn_angle ( )
private

Definition at line 259 of file ControllerNode.cpp.

259  {
260  m_controlMtx.lock();
261  m_pathPolynomMtx.lock();
262 
263  // TODO: set current Pose (maybe not neccessary)
264  // CarPose currentPose();
265  // currentPose.orientation = ...;
266  if(m_currentVelocityReference >= 0.01f) {
268  std::get<1>(m_currentTurnAngles) = 0; // rear turn angle
269  }
270 
271  // decrease velocity for steering
272  float veloFactorForDecrease = 1 - std::abs(std::get<0>(m_currentTurnAngles)) * 1.5f;
273  float desiredVelocity = m_currentVelocityReference * veloFactorForDecrease;
274 
276 
279  m_currentVelocity = min;
280  }
281 
283  float ref = m_currentVelocityReference;
284  m_currentVelocity = ref;
285  }
286 
287  if(m_currentVelocityReference < 0.01f) {
288  m_currentVelocity = 0;
289  }
290 
291  if(m_simulationMode == true) {
292  float currVelo = m_currentVelocity;
293  m_currentVelocityApplied = currVelo;
294  }
295 
296  log("[CALCULATION] TurnAngle [Rad]: ", std::get<0>(m_currentTurnAngles), " Velocity [m/s]: ", m_currentVelocity);
297 
298  m_pathPolynomMtx.unlock();
299  m_controlMtx.unlock();
300 }

References galaxis::utils::log(), m_controlMtx, m_controlTwoAndAHalfCarrotsSPtr, m_currentLineMarkingReferenceSPtr, m_currentReferenceSplineSPtr, m_currentTurnAngles, m_currentVelocity, m_currentVelocityApplied, m_currentVelocityReference, m_minVelocity, m_pathPolynomMtx, m_simulationMode, and m_velocityRollingAverageFactorForNewVelocity.

Referenced by ControllerNode(), and on_pathpolynom_callback().

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

◆ loop()

void ControllerNode::loop ( )
private

Definition at line 122 of file ControllerNode.cpp.

122  {
123  while(1) {
124  //TODO wait for measurements...
125  // if(m_disableController == true) { // controller idle
126  // std::this_thread::sleep_for(std::chrono::milliseconds(10));
127  // continue;
128  // }
129 
130  bool apOffline = false;
131  // Stop Car if more than 0.4 seconds no poly updates from AP
132  if(std::abs(this->get_clock()->now().nanoseconds() - m_lastPolynomUpdateTimestamp) > 4e8) {
133  log_warning("Stopping car. No Polynom update within 400ms! (Is the AP online?)");
134  m_currentVelocity = 0.f;
135  apOffline = true;
136  }
137 
138  auto msgUPtr = std::make_unique<ControlMotionType>();
140  msgUPtr->set_motor_current = 0;
141  msgUPtr->set_servo_front = galaxis::servoSettings::angleToServoSetting(std::get<0>(m_currentTurnAngles));
142  msgUPtr->set_servo_rear = 0; //std::get<1>(m_currentTurnAngles);
143  msgUPtr->set_brakes = ((m_currentVelocity == 0.f) && !apOffline);
144 
145  // parking mode
146  if(m_stop_ControllerNode == true) {
147  auto set_start_ParkingNode_result = this->set_parameter(rclcpp::Parameter("CarOS.start_ParkingNode", 1));
148  if (!set_start_ParkingNode_result.successful) {
149  RCLCPP_ERROR(this->get_logger(), "Failed to set CarOS.start_ParkingNode: %s", set_start_ParkingNode_result.reason.c_str());
150  }
151  log_warning("Real World: In parking mode. Controller Node is in idle mode.");
152  } else {
153  publish_control_values(std::move(msgUPtr));
154 
155  // send lights only if changed
156  // PROBLEM! with ECU ? maybe due to flash?
157  if(m_lastSentControlLights == nullptr || (this->get_clock()->now() - m_lastSentControlLights->header.stamp) > rclcpp::Duration(0,100000000)) { // every 100ms
158  m_lastSentControlLights = std::make_shared<ControlLightsType>();
159  m_lastSentControlLights->header.stamp = this->get_clock()->now();
160  m_lastSentControlLights->set_blinker_left = std::get<0>(m_currentIndicatorState);
161  m_lastSentControlLights->set_blinker_right = std::get<1>(m_currentIndicatorState);
162  m_lastSentControlLights->set_headlight = true;
163  m_lastSentControlLights->set_brake_light = ((m_currentVelocity == 0.f) && !apOffline); // TODO
165 
166 
167  // for VideoCockpit
168  auto lightUPtr = std::make_unique<std_msgs::msg::UInt8>();
169  lightUPtr->data = 0; // DDDDDBRL (D:=DontCare, B:=Brake, R:=Right, L:=Left)
170  lightUPtr->data |= std::get<0>(m_currentIndicatorState) ? 1 : 0;
171  lightUPtr->data |= (std::get<1>(m_currentIndicatorState) ? 1 : 0) << 1;
172  lightUPtr->data |= (((m_currentVelocity == 0.f) && !apOffline) ? 1 : 0) << 2;
173  m_lightsStdPublisherSPtr->publish(std::move(lightUPtr));
174  }
175  }
176  //phth end
177 
178 
179 
180  // send control debug
181  if(m_debugMode == true) {
183  }
184 
185  // send Simulation Message
186  if(m_simulationMode == true) {
187  //phth
188  if(m_stop_ControllerNode == true) {
189  auto set_start_ParkingNode_result = this->set_parameter(rclcpp::Parameter("CarOS.start_ParkingNode", 1));
190  if (!set_start_ParkingNode_result.successful) {
191  RCLCPP_ERROR(this->get_logger(), "Failed to set CarOS.start_ParkingNode: %s", set_start_ParkingNode_result.reason.c_str());
192  }
193  log_warning("Simulation: In parking mode. Controller Node is in idle mode.");
194  } else {
196  }
197  //phth end
198  }
199 
200  std::this_thread::sleep_for(std::chrono::milliseconds(2)); // TODO: maybe remove
201  }
202 }

References galaxis::servoSettings::angleToServoSetting(), galaxis::utils::log_warning(), m_controlLightsPubSPtr, m_currentIndicatorState, m_currentTurnAngles, m_currentVelocity, m_debugMode, m_lastPolynomUpdateTimestamp, m_lastSentControlLights, m_lightsStdPublisherSPtr, m_simulationMode, m_stop_ControllerNode, publish_control_values(), send_debug_messages(), send_simulation_messages(), and galaxis::motorSettings::velocityToErpm().

Referenced by ControllerNode().

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

◆ new_parameters_callback()

rcl_interfaces::msg::SetParametersResult ControllerNode::new_parameters_callback ( const std::vector< rclcpp::Parameter > &  parameters)
private

Definition at line 431 of file ControllerNode.cpp.

431  {
432  log("[ControllerNode] NEW PARAMETERS");
433 
434  rcl_interfaces::msg::SetParametersResult result;
435  result.successful = true;
436  result.reason = "";
437 
438  for (const auto &param: parameters) {
439  if (param.get_name() == "settings.horizon_step_time_sec") {
440  if(check_parameter<double>(param, result, 0.1, 2.0)) {
441  m_controlTwoAndAHalfCarrotsSPtr->set_horizon_step_time(param.as_double());
442  }
443  }
444  else if (param.get_name() == "settings.error_accuracy_steps_per_horizon") {
445  if(check_parameter<int>(param, result, 5, 100)) {
446  m_controlTwoAndAHalfCarrotsSPtr->set_error_accuracy_steps_per_horizon(param.as_int());
447  }
448  }
449  else if (param.get_name() == "settings.error_factor_first_horizon") {
450  if(check_parameter<double>(param, result, -5.0, 5.0)) {
451  m_controlTwoAndAHalfCarrotsSPtr->set_error_factor_first_horizon(param.as_double());
452  }
453  }
454  else if (param.get_name() == "settings.max_decreased_velocity_for_steering") {
455  if(check_parameter<double>(param, result, 0.3)) {
456  m_minVelocity = param.as_double();
457  }
458  }
459  else if (param.get_name() == "settings.velocity_rolling_average_factor_to_new_velocity") {
460  if(check_parameter<double>(param, result, 0.000001, 1)) {
462  }
463  }
464  //phth
465  else if (param.get_name() == "CarOS.stop_ControllerNode") {
466  if(check_parameter<int>(param, result, 0)) {
467  m_stop_ControllerNode = (param.as_int() == 1);
468  }
469  }
470  else if (param.get_name() == "CarOS.start_ParkingNode") {
471  if(check_parameter<int>(param, result, 0)) {
472  m_start_ParkingNode = (param.as_int() == 1);
473  }
474  }
475 
476  //phth end
477  else if (param.get_name() == "controlmetrics.cross_angle_error_weight") {
478  if(check_parameter<double>(param, result, 0)) {
479  m_controlTwoAndAHalfCarrotsSPtr->set_cross_angle_error_weight( param.as_double());
480  }
481  }
482  else if (param.get_name() == "controlmetrics.cross_line_marking_error_weight") {
483  if(check_parameter<double>(param, result, 0)) {
484  m_controlTwoAndAHalfCarrotsSPtr->set_cross_line_marking_error_weight( param.as_double());
485  }
486  }
487  else {
488  result.successful = false;
489  result.reason += "[" + param.get_name() + "] UNKNOWN param or NOT IMPLEMENTED; ";
490  }
491  }
492 
493  if(result.successful == false) {
494  log_warning("[AutopilotNode] Failed to set some parameters. Reasons: ", result.reason);
495  }
496 
497  return result;
498 }

References galaxis::utils::log(), galaxis::utils::log_warning(), m_controlTwoAndAHalfCarrotsSPtr, m_minVelocity, m_start_ParkingNode, m_stop_ControllerNode, and m_velocityRollingAverageFactorForNewVelocity.

Referenced by ControllerNode().

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

◆ on_controller_reference_callback()

void ControllerNode::on_controller_reference_callback ( ControllerReferenceType::SharedPtr  msg)
private

Definition at line 353 of file ControllerNode.cpp.

353  {
354 
355  m_disableController = (msg->controller_enable == false);
356  m_currentVelocityReference = msg->velocity_reference;
357  std::get<0>(m_currentIndicatorState) = msg->indicator_left;
358  std::get<1>(m_currentIndicatorState) = msg->indicator_right;
359 
360  log("#New Controller Reference received: \n - VelocityRef [m/s]: ", m_currentVelocityReference, "\n - Indicators (L,R): ", std::get<0>(m_currentIndicatorState), ",", std::get<1>(m_currentIndicatorState));
361 }

References galaxis::utils::log(), m_currentIndicatorState, m_currentVelocityReference, and m_disableController.

Referenced by ControllerNode().

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

◆ on_map_debug_image_callback()

void ControllerNode::on_map_debug_image_callback ( const sensor_msgs::msg::Image::ConstSharedPtr &  msg)
private

Definition at line 363 of file ControllerNode.cpp.

363  {
364  if(m_localMapDebugTrajectoryImgPublisher.getNumSubscribers() == 0) {
365  log("[on_map_debug_image_callback] Skip sending Map-Trajectory-Debug-Image. Reason: NO Subscriber on the corresponding topic.");
366  return;
367  }
368 
369  std::shared_ptr<sensor_msgs::msg::Image> imageMsg = std::make_shared<sensor_msgs::msg::Image>();
370 
371  imageMsg->header.stamp = msg->header.stamp;
372  imageMsg->width = msg->width;
373  imageMsg->height = msg->height;
374  imageMsg->encoding = msg->encoding;
375  imageMsg->is_bigendian = msg->is_bigendian;
376  imageMsg->step = msg->step;
377 
378  imageMsg->data = msg->data;
379 
380  // draw trajectory
381 
382  // m_pathPolynomMtx.lock();
383  // float orientation = m_lastReceivedPathpolynomSPtr->pose.orientation;
384  // Eigen::Rotation2Df rotationMat(orientation);
385  // m_pathPolynomMtx.unlock();
386 
387  m_controlMtx.lock();
388  auto poseSeries = m_controlTwoAndAHalfCarrotsSPtr->get_last_first_poseseries();
389 
390  float trajectoryPointPositionX = 0.f;
391  float trajectoryPointPositionY = 0.f;
392  for(int i = 0; i < 2; ++i) {
393  for(auto const& pose : *poseSeries) {
394  trajectoryPointPositionX = - pose->position[1] * 100;
395  trajectoryPointPositionY = galaxis::autopilot::lookupLookBehindCarCM + pose->position[0] * 100;
396 
397  // draw circle
398  int radiusCM = 2;
399  for(int y = -radiusCM; y <= radiusCM; y++) {
400  for(int x = -radiusCM; x <= radiusCM; x++) {
401  if(x*x+y*y <= radiusCM*radiusCM) {
402  int imageX = trajectoryPointPositionX + x + imageMsg->width / 2;
403  int imageY = imageMsg->height - trajectoryPointPositionY + y;
404  int index = imageY * imageMsg->step + imageX * 3;
405 
406  //skip if not on image
407  if (imageX < 0 || imageY < 0 || imageX >= imageMsg->width || imageY >= imageMsg->height) {
408  continue;
409  }
410 
411  if(index >= 0 && index + 2 <= static_cast<int>(imageMsg->data.size())) {
412  imageMsg->data[index] = 255;
413  imageMsg->data[index + 1] = 242;
414  imageMsg->data[index + 2] = 167;
415  // Yellow: https://www.color-hex.com/color/fff2a7
416  }
417  }
418  }
419  }
420  }
421 
422  poseSeries = m_controlTwoAndAHalfCarrotsSPtr->get_last_second_poseseries();
423  }
424 
425  m_controlMtx.unlock();
426 
427  m_localMapDebugTrajectoryImgPublisher.publish(imageMsg);
428  log("[DEBUG] [PUBLISH] Map-Trajectory-Debug-Image");
429 }

References galaxis::utils::log(), galaxis::autopilot::lookupLookBehindCarCM, m_controlMtx, m_controlTwoAndAHalfCarrotsSPtr, and m_localMapDebugTrajectoryImgPublisher.

Referenced by ControllerNode().

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

◆ on_measurement_callback()

void ControllerNode::on_measurement_callback ( MeasurementsType::SharedPtr  msg)
private

Definition at line 302 of file ControllerNode.cpp.

302  {
303  log("#New Measurements arrived.");
304  if(m_measurementMtx.try_lock()) {
307  m_measurementMtx.unlock();
308  } else {
309  log_warning("ControllerNode::on_measurement_callback: MeasurementsPtr mutexed. Could not update Measurements");
310  }
311 }

References galaxis::motorSettings::erpmToVelocity(), galaxis::utils::log(), galaxis::utils::log_warning(), m_currentVelocityApplied, m_lastReceivedMeasurementSPtr, and m_measurementMtx.

Referenced by ControllerNode().

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

◆ on_pathpolynom_callback()

void ControllerNode::on_pathpolynom_callback ( PathpolynomType::SharedPtr  msg)
private

Definition at line 313 of file ControllerNode.cpp.

313  {
314  log("#New Pathpolynom received.");
315  m_pathPolynomMtx.lock();
317 
319  m_currentReferenceSplineSPtr->add_polynom(-100, 100, galaxis::polynom{
320  static_cast<float>(msg->c[0]),
321  static_cast<float>(msg->c[1]),
322  static_cast<float>(msg->c[2]),
323  static_cast<float>(msg->c[3])
324  }); // TODO Spline?
325 
326  m_currentLineMarkingReferenceSPtr = std::make_shared<galaxis::line_markings_reference_t>();
327  m_currentLineMarkingReferenceSPtr->center = PolySpline(msg->c_m, msg->max_center, msg->min_center);
328  m_currentLineMarkingReferenceSPtr->right = PolySpline(msg->c_r, msg->max_right, msg->min_right);
329  m_currentLineMarkingReferenceSPtr->left = PolySpline(msg->c_l, msg->max_left, msg->min_left);
330  m_currentLineMarkingReferenceSPtr->isCenterEnabled = msg->center_enabled;
331  m_currentLineMarkingReferenceSPtr->isRightEnabled = msg->right_enabled;
332  m_currentLineMarkingReferenceSPtr->isLeftEnabled = msg->left_enabled;
333 
334 
335  m_lastPolynomUpdateTimestamp = this->get_clock()->now().nanoseconds();
336 
337  m_pathPolynomMtx.unlock();
338 
339  //log("->calculate_turn_angle");
341 }

References calculate_turn_angle(), galaxis::utils::log(), m_currentLineMarkingReferenceSPtr, m_currentReferenceSplineSPtr, m_lastPolynomUpdateTimestamp, m_lastReceivedPathpolynomSPtr, and m_pathPolynomMtx.

Referenced by ControllerNode().

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

◆ publish_control_values()

void ControllerNode::publish_control_values ( ControlMotionType::UniquePtr  msg)
private

Definition at line 343 of file ControllerNode.cpp.

343  {
344  assert(msg != nullptr);
345  assert(m_controlValuesPubSPtr != nullptr);
346 
347  log("[PUBLISH] ControlValues\n - ERPM: ", msg->set_motor_erpm, "\n - Motor Current: ", msg->set_motor_current, "\n - Servo Front: ",
348  static_cast<int>(msg->set_servo_front), "\n - Servo Back: ", static_cast<int>(msg->set_servo_rear), "\n - Brakes: ", msg->set_brakes, "\n");
349 
350  m_controlValuesPubSPtr->publish(std::move(msg));
351 }

References galaxis::utils::log(), and m_controlValuesPubSPtr.

Referenced by loop().

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

◆ send_debug_messages()

void ControllerNode::send_debug_messages ( )
private

Definition at line 204 of file ControllerNode.cpp.

204  {
205  if(m_lastReceivedPathpolynomSPtr == nullptr) {
206  log("[SKIP] PathPolynom is nullptr. Skip sending Debug Message.");
207  return;
208  }
209 
210  if(m_controlMtx.try_lock()) {
211  if(m_pathPolynomMtx.try_lock()) {
212  DebugControllerType::UniquePtr debugMessage = std::make_unique<DebugControllerType>();
213 
214  debugMessage->polynom = PathpolynomType(*m_lastReceivedPathpolynomSPtr);
215  debugMessage->turnangle_front = std::get<0>(m_currentTurnAngles);
216  debugMessage->turnangle_rear = std::get<1>(m_currentTurnAngles);
217  debugMessage->car_speed = m_currentVelocity;
218 
219  std::shared_ptr<galaxis::control::CarPoseSeries const> firstPoseSeries = m_controlTwoAndAHalfCarrotsSPtr->get_last_first_poseseries();
220  std::shared_ptr<galaxis::control::CarPoseSeries const> secondPoseSeries = m_controlTwoAndAHalfCarrotsSPtr->get_last_second_poseseries();
221 
222  for(auto const pose: *firstPoseSeries) {
223  Vector2fType vec;
224  vec.x = pose->position[0];
225  vec.y = pose->position[1];
226  debugMessage->carpose_series.push_back(vec);
227  }
228 
229  for(auto const pose: *secondPoseSeries) {
230  Vector2fType vec;
231  vec.x = pose->position[0];
232  vec.y = pose->position[1];
233  debugMessage->carpose_series.push_back(vec);
234  }
235 
236  m_debugControllerPubSPtr->publish(std::move(debugMessage));
237  log("[PUBLISH] DebugController message.");
238 
239  m_pathPolynomMtx.unlock();
240  } else {
241  log("[SKIP] PathPolynom mutexed. Skip sending Debug Message.");
242  }
243  m_controlMtx.unlock();
244  } else {
245  log("[SKIP] Control mutexed. Skip sending Debug Message.");
246  }
247 }

References galaxis::utils::log(), m_controlMtx, m_controlTwoAndAHalfCarrotsSPtr, m_currentTurnAngles, m_currentVelocity, m_debugControllerPubSPtr, m_lastReceivedPathpolynomSPtr, and m_pathPolynomMtx.

Referenced by loop().

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

◆ send_simulation_messages()

void ControllerNode::send_simulation_messages ( )
private

Definition at line 249 of file ControllerNode.cpp.

249  {
250  auto message = std::make_unique<SimulationVehicleControlType>();
251 
252  message->car_speed = m_currentVelocity;
253  message->turnangle_front = std::get<0>(m_currentTurnAngles);
254  message->reset = false;
255 
256  m_simulationVehicleControlPubSPtr->publish(std::move(message));
257 }

References m_currentTurnAngles, m_currentVelocity, and m_simulationVehicleControlPubSPtr.

Referenced by loop().

Here is the caller graph for this function:

Member Data Documentation

◆ m_controllerRefSubSPtr

rclcpp::Subscription<ControllerReferenceType>::SharedPtr ControllerNode::m_controllerRefSubSPtr
private

Definition at line 40 of file ControllerNode.hpp.

Referenced by ControllerNode().

◆ m_controlLightsPubSPtr

rclcpp::Publisher<ControlLightsType>::SharedPtr ControllerNode::m_controlLightsPubSPtr
private

Definition at line 33 of file ControllerNode.hpp.

Referenced by ControllerNode(), and loop().

◆ m_controlMtx

std::mutex ControllerNode::m_controlMtx
private

◆ m_controlTwoAndAHalfCarrotsSPtr

std::shared_ptr<galaxis::control::TwoAndAHalfCarrots> ControllerNode::m_controlTwoAndAHalfCarrotsSPtr
private

◆ m_controlValuesPubSPtr

rclcpp::Publisher<ControlMotionType>::SharedPtr ControllerNode::m_controlValuesPubSPtr
private

Definition at line 32 of file ControllerNode.hpp.

Referenced by ControllerNode(), and publish_control_values().

◆ m_currentIndicatorState

std::tuple<std::atomic<bool>, std::atomic<bool> > ControllerNode::m_currentIndicatorState = std::make_tuple(false, false)
private

Definition at line 71 of file ControllerNode.hpp.

Referenced by loop(), and on_controller_reference_callback().

◆ m_currentLineMarkingReferenceSPtr

std::shared_ptr<galaxis::line_markings_reference_t> ControllerNode::m_currentLineMarkingReferenceSPtr
private

Definition at line 56 of file ControllerNode.hpp.

Referenced by calculate_turn_angle(), and on_pathpolynom_callback().

◆ m_currentReferenceSplineSPtr

std::shared_ptr<PolySpline> ControllerNode::m_currentReferenceSplineSPtr
private

◆ m_currentTurnAngles

std::tuple<float, float> ControllerNode::m_currentTurnAngles = std::make_tuple(0.f, 0.f)
private

◆ m_currentVelocity

std::atomic<float> ControllerNode::m_currentVelocity = 0.f
private

◆ m_currentVelocityApplied

std::atomic<float> ControllerNode::m_currentVelocityApplied = 0.f
private

◆ m_currentVelocityReference

std::atomic<float> ControllerNode::m_currentVelocityReference = 0.f
private

Definition at line 69 of file ControllerNode.hpp.

Referenced by calculate_turn_angle(), and on_controller_reference_callback().

◆ m_debugControllerPubSPtr

rclcpp::Publisher<DebugControllerType>::SharedPtr ControllerNode::m_debugControllerPubSPtr
private

Definition at line 34 of file ControllerNode.hpp.

Referenced by ControllerNode(), and send_debug_messages().

◆ m_debugMode

bool ControllerNode::m_debugMode = false
private

Definition at line 24 of file ControllerNode.hpp.

Referenced by ControllerNode(), and loop().

◆ m_disableController

std::atomic<bool> ControllerNode::m_disableController
private

Definition at line 26 of file ControllerNode.hpp.

Referenced by ControllerNode(), and on_controller_reference_callback().

◆ m_lastPolynomUpdateTimestamp

std::atomic<int64_t> ControllerNode::m_lastPolynomUpdateTimestamp
private

Definition at line 59 of file ControllerNode.hpp.

Referenced by loop(), and on_pathpolynom_callback().

◆ m_lastReceivedMeasurementSPtr

MeasurementsType::SharedPtr ControllerNode::m_lastReceivedMeasurementSPtr
private

Definition at line 47 of file ControllerNode.hpp.

Referenced by on_measurement_callback().

◆ m_lastReceivedPathpolynomSPtr

PathpolynomType::SharedPtr ControllerNode::m_lastReceivedPathpolynomSPtr
private

Definition at line 54 of file ControllerNode.hpp.

Referenced by on_pathpolynom_callback(), and send_debug_messages().

◆ m_lastSentControlLights

std::shared_ptr<ControlLightsType> ControllerNode::m_lastSentControlLights
private

Definition at line 51 of file ControllerNode.hpp.

Referenced by loop().

◆ m_lightsStdPublisherSPtr

rclcpp::Publisher<std_msgs::msg::UInt8>::SharedPtr ControllerNode::m_lightsStdPublisherSPtr
private

Definition at line 36 of file ControllerNode.hpp.

Referenced by ControllerNode(), and loop().

◆ m_localMapDebugImgSubscription

image_transport::Subscriber ControllerNode::m_localMapDebugImgSubscription
private

Definition at line 43 of file ControllerNode.hpp.

Referenced by ControllerNode().

◆ m_localMapDebugTrajectoryImgPublisher

image_transport::Publisher ControllerNode::m_localMapDebugTrajectoryImgPublisher
private

Definition at line 44 of file ControllerNode.hpp.

Referenced by ControllerNode(), and on_map_debug_image_callback().

◆ m_measurementMtx

std::mutex ControllerNode::m_measurementMtx
private

Definition at line 48 of file ControllerNode.hpp.

Referenced by on_measurement_callback().

◆ m_measurementSubSPtr

rclcpp::Subscription<MeasurementsType>::SharedPtr ControllerNode::m_measurementSubSPtr
private

Definition at line 41 of file ControllerNode.hpp.

Referenced by ControllerNode().

◆ m_minVelocity

std::atomic<float> ControllerNode::m_minVelocity = 0.4f
private

Definition at line 72 of file ControllerNode.hpp.

Referenced by calculate_turn_angle(), and new_parameters_callback().

◆ m_pathPolynomMtx

std::mutex ControllerNode::m_pathPolynomMtx
private

◆ m_pathPolynomSubSPtr

rclcpp::Subscription<PathpolynomType>::SharedPtr ControllerNode::m_pathPolynomSubSPtr
private

Definition at line 39 of file ControllerNode.hpp.

Referenced by ControllerNode().

◆ m_simulationMode

bool ControllerNode::m_simulationMode = false
private

Definition at line 25 of file ControllerNode.hpp.

Referenced by calculate_turn_angle(), ControllerNode(), and loop().

◆ m_simulationVehicleControlPubSPtr

rclcpp::Publisher<SimulationVehicleControlType>::SharedPtr ControllerNode::m_simulationVehicleControlPubSPtr
private

Definition at line 35 of file ControllerNode.hpp.

Referenced by ControllerNode(), and send_simulation_messages().

◆ m_start_ParkingNode

std::atomic<bool> ControllerNode::m_start_ParkingNode = false
private

Definition at line 29 of file ControllerNode.hpp.

Referenced by new_parameters_callback().

◆ m_stop_ControllerNode

std::atomic<bool> ControllerNode::m_stop_ControllerNode = false
private

Definition at line 28 of file ControllerNode.hpp.

Referenced by loop(), and new_parameters_callback().

◆ m_turnAnglesSPtr

std::shared_ptr<std::vector<float> > ControllerNode::m_turnAnglesSPtr
private

Definition at line 63 of file ControllerNode.hpp.

Referenced by ControllerNode().

◆ m_velocityRollingAverageFactorForNewVelocity

std::atomic<float> ControllerNode::m_velocityRollingAverageFactorForNewVelocity = 0.01f
private

Definition at line 73 of file ControllerNode.hpp.

Referenced by calculate_turn_angle(), and new_parameters_callback().


The documentation for this class was generated from the following files:
StationaryBeaconPosition::x
int32_t x
Definition: marvelmind.h:76
ControllerNode::m_lastReceivedMeasurementSPtr
MeasurementsType::SharedPtr m_lastReceivedMeasurementSPtr
Definition: ControllerNode.hpp:47
galaxis::servoSettings::angleToServoSetting
int8_t angleToServoSetting(float angle)
Definition: servoSettings.cpp:22
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
galaxis::PolySpline
Definition: poly.hpp:37
ControllerNode::m_lastSentControlLights
std::shared_ptr< ControlLightsType > m_lastSentControlLights
Definition: ControllerNode.hpp:51
GalaxisNode::enable_parameters
void enable_parameters(std::function< rcl_interfaces::msg::SetParametersResult(const std::vector< rclcpp::Parameter > &)> callbackFunc)
Definition: GalaxisNode.cpp:69
StationaryBeaconPosition::y
int32_t y
Definition: marvelmind.h:76
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
galaxis::autopilot::lookupLookBehindCarCM
constexpr int lookupLookBehindCarCM
Definition: AutopilotSettings.hpp:38
galaxis::polynom
std::vector< float > polynom
Definition: poly.hpp:20
json
nlohmann::json json
Definition: AutoPilotNode.hpp:21
Vector2fType
messages::msg::Vector2f Vector2fType
Definition: messages.hpp:44
galaxis::utils::log_warning
void log_warning(const Args &... args)
Definition: logger.hpp:41
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
galaxis::controllerSettings::carWheelbaseSimulationDrDrift
constexpr float carWheelbaseSimulationDrDrift
Definition: controllerSettings.hpp:8
ControllerNode::m_controllerRefSubSPtr
rclcpp::Subscription< ControllerReferenceType >::SharedPtr m_controllerRefSubSPtr
Definition: ControllerNode.hpp:40
ControllerNode::m_localMapDebugImgSubscription
image_transport::Subscriber m_localMapDebugImgSubscription
Definition: ControllerNode.hpp:43
ControllerNode::calculate_turn_angle
void calculate_turn_angle()
Definition: ControllerNode.cpp:259
galaxis::utils::read_json_file
shared_ptr< json > read_json_file(std::string path)
Definition: settings.cpp:5
galaxis::control::TwoAndAHalfCarrots
Definition: control.hpp:28
GalaxisNode::get_global_settings
json const & get_global_settings()
Definition: GalaxisNode.cpp:119
ControllerNode::m_start_ParkingNode
std::atomic< bool > m_start_ParkingNode
Definition: ControllerNode.hpp:29
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
PathpolynomType
messages::msg::Pathpolynom PathpolynomType
Definition: messages.hpp:42
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
GalaxisNode::GalaxisNode
GalaxisNode()=delete
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
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
galaxis::motorSettings::erpmToVelocity
float erpmToVelocity(float const p_erpm)
returns the velocity in [m/s] for a given ERPM
Definition: motorSettings.cpp:5
galaxis::motorSettings::velocityToErpm
float velocityToErpm(float const p_velocity)
Definition: motorSettings.cpp:9
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
galaxis::utils::log
void log(const Args &... args)
Definition: logger.hpp:33
ControllerNode::m_currentVelocity
std::atomic< float > m_currentVelocity
Definition: ControllerNode.hpp:67
galaxis::controllerSettings::carWheelbase
constexpr float carWheelbase
Definition: controllerSettings.hpp:7
ControllerNode::m_currentVelocityReference
std::atomic< float > m_currentVelocityReference
Definition: ControllerNode.hpp:69