Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
AutoPilotNode.cpp
Go to the documentation of this file.
1 #include "Node/AutoPilotNode.hpp"
2 
3 #include "utils/logger.hpp"
6 #include <utils/file.hpp>
7 #include <utils/settings.hpp>
8 #include <cstdlib>
9 #include <sensor_msgs/image_encodings.hpp>
10 
11 using std::placeholders::_1;
12 using namespace galaxis::ros;
13 using namespace galaxis::utils;
14 
16 
17 
18 AutoPilotNode::AutoPilotNode() : GalaxisNode("Autopilot"), m_autopilot(this), m_laneDetectionSharedMemory("/galaxis__lanes") {
19  // Map Messages: http://docs.ros.org/en/melodic/api/nav_msgs/html/msg/OccupancyGrid.html
20  log("AutoPilotNode: Initializing...");
21 
22  // Settings
23  try {
24  std::string configPath = "settings/onstartup_autopilot.json";
25  auto settingsJsonSPtr = read_json_file(configPath);
26  json& settingsJson = (*settingsJsonSPtr)["settings"];
27 
28  m_simulationMode = this->get_global_settings()["simulation_mode"];
29  m_fakeLineDetectionMode = this->get_global_settings()["fake_line_detection_mode"];
30  m_debugMode = settingsJson["debug_mode"];
31  m_sendFullMapDebugMsg = settingsJson["send_full_map_debug_msg"];
32  m_laneDetectionSharedMemoryMode = settingsJson["lane_detection_shared_memory"];
33  m_sendLaneDetectionImage = settingsJson["send_lane_detection_image"];
34  m_autopilot.m_decision.m_stopAtStartLine = settingsJson["wait_at_startline"];
35 
36  if(settingsJson["wait_for_qr_code_detection"] == false) { // start driving instantly
38  }
39  }
40  catch (const std::runtime_error& error) {
41  // pass
42  log_warning("##########################################################");
43  log_warning("############## READING CONFIGURATION FAILED ##############");
44  log_warning("############# Falling BACK TO DEFAULT CONFIG #############");
45  log_warning("##########################################################");
46  sleep(10);
47  }
48 
49  log("Configuration:\n - SimulationMode: ", m_simulationMode ? "ENABLED" : "DISABLED");
50  log(" - DebugMode: ", m_debugMode ? "ENABLED" : "DISABLED");
51  log(" - FakeLineDetectionMode: ", m_fakeLineDetectionMode ? "ENABLED" : "DISABLED");
52  log(" - SendFullMapDebugMessage: ", m_sendFullMapDebugMsg ? "ENABLED" : "DISABLED");
53  log(" - PoseSendSleepTime [microsec]: ", m_poseSendSleepTimeMicroSec);
54  if(m_debugMode || m_simulationMode || m_fakeLineDetectionMode || m_sendFullMapDebugMsg) sleep(1); // To view the configurations
55 
56  // Publisher
57  galaxis::ros::create_publisher(this, m_pathpolynomPubSPtr);
58  galaxis::ros::create_publisher(this, m_controllerRefPubSPtr);
59  galaxis::ros::create_publisher(this, m_carposePubSPtr);
60  galaxis::ros::create_publisher(this, m_parkingOperationPubSPtr);
61 
62  if(m_debugMode) {
63  m_mapDataImageDebugPub = image_transport::create_publisher(this, TOPIC_AP_DATA_IMAGE_DEBUG);
64  rclcpp::QoS qos_params_situation = get_qos_profile(QOS_RELIABLE);
65  m_autopilotStatePubSPtr = this->create_publisher<std_msgs::msg::UInt8>("/galaxis/ap/situation_state", qos_params_situation);
66  }
67  if(m_sendLaneDetectionImage) m_laneDetectionMessage = image_transport::create_publisher(this, "/galaxis/debug/ap/shm/lane_image");
68  if(m_sendFullMapDebugMsg) m_fullMapDataImageDebugPub = image_transport::create_publisher(this, TOPIC_AP_FULL_MAP_DATA_IMAGE_DEBUG);
69 
70  if(m_simulationMode) { // Initializing Simulation
71  rclcpp::QoS qos_params = get_qos_profile(QOS_BEST_EFFORT);
72  m_subscriberLaneDetectionSub = this->create_subscription<sensor_msgs::msg::Image>(
73  galaxis::ros::TOPIC_VCI_LANE_IMAGE_SIMULATION,
74  qos_params,
75  std::bind(&AutoPilotNode::on_vci_lane_detection_callback, this, _1));
76 
77  // Car Pose Subscription (Position, Orientation)
78  qos_params = get_qos_profile(QOS_BEST_EFFORT);
79  m_subscriberCarPoseSPtr = this->create_subscription<geometry_msgs::msg::Pose>("/simulation/gazebo/model/dr_drift/pose", qos_params, std::bind(&AutoPilotNode::on_simulation_pose_callback, this, std::placeholders::_1));
80 
81  // Obstacle Subscription
82  galaxis::ros::create_subscription(this, m_subscriberObstaclesSPtr, std::bind(&AutoPilotNode::on_obstacle_callback, this, _1));
83 
84  if(m_fakeLineDetectionMode) { // for SimulationLineDetection
86 
87  // ignore isInImage function which cuts off overlaid section
89  } else { // for VCI
91  }
92 
93  log_warning("SimulationLineDetection and Autopilot must run in same docker container!");
94  } else { // Initializing Normal Mode
95 
96  galaxis::ros::create_subscription(this,
98  std::bind(&AutoPilotNode::on_ecu_measurement_callback, this, _1));
99 
100 
101  // lane image
102  if(m_laneDetectionSharedMemoryMode == false) {
103  rclcpp::QoS qos_params = get_qos_profile(QOS_BEST_EFFORT);
104  m_subscriberLaneDetectionSub = this->create_subscription<sensor_msgs::msg::Image>(
105  galaxis::ros::TOPIC_VCI_LANE_IMAGE_SIMULATION,
106  qos_params,
107  std::bind(&AutoPilotNode::on_vci_lane_detection_callback, this, _1));
108  }
109  else {
111  std::thread(&AutoPilotNode::lane_detection_shared_memory_loop, this).detach();
112  }
113 
114  // Obstacle Subscription
115  galaxis::ros::create_subscription(this, m_subscriberObstaclesSPtr, std::bind(&AutoPilotNode::on_obstacle_callback, this, _1));
116 
117  // QRCode Subscription
118  galaxis::ros::create_subscription(this, m_subscriberQRCodeSPtr, std::bind(&AutoPilotNode::on_qr_code_callback, this, _1));
119 
120  // StopLine Subscription
121  galaxis::ros::create_subscription(this, m_subscriberStopLine, std::bind(&AutoPilotNode::on_stop_line_callback, this, _1));
122 
123  // Parking
124  m_lastParkingState = 0;
125  galaxis::ros::create_subscription(this, m_subscriberParkingStateSPtr, std::bind(&AutoPilotNode::on_parking_state_callback, this, _1));
126  galaxis::ros::create_publisher(this, m_parkingOperationPubSPtr);
127 
128  rclcpp::Time timeNow = this->get_clock()->now();
129  m_autopilot.m_localizer.add_position_timepoint(timeNow, Vector2f(0.f,0.f), 0, 0); // if no IMU is there
130 
132  }
133 
134  m_lastLaneDetectionUpdate = this->get_clock()->now();
135 
136  this->enable_parameters(std::bind(&AutoPilotNode::new_parameters_callback, this, std::placeholders::_1));
137 
138  log("AutopilotNode: Waiting for messages...");
139 
140  std::thread(&AutoPilotNode::car_pose_publish_loop, this).detach();
141  std::thread(&AutoPilotNode::controller_reference_publish_loop, this).detach();
142 
143  if(m_debugMode) {
144  std::thread(&AutoPilotNode::debug_publish_loop, this).detach();
145  }
146 
147  m_stoplineIgnoreAreaRadius = 0.f; // disabled
148 }
149 
151 
153  while(1) {
155  if(m_autopilot.m_localizer.is_empty()) continue;
156 
157  auto localizationPointSPtr = m_autopilot.m_localizer.get_latest_position_timepoint();
158 
159  std::unique_ptr<CarPoseEstimatedType> carposeUPtr = std::make_unique<CarPoseEstimatedType>();
160  carposeUPtr->pose.pos_x = localizationPointSPtr->position[0] / 1000;
161  carposeUPtr->pose.pos_y = localizationPointSPtr->position[1] / 1000;
162  carposeUPtr->pose.orientation = localizationPointSPtr->orientation;
163  carposeUPtr->header.stamp = localizationPointSPtr->timestamp;
164 
165  m_carposePubSPtr->publish(std::move(carposeUPtr));
166  }
167 }
168 
170  while(1) {
171  MicroStopwatch stopwatch;
173  long long time = stopwatch.get_time();
175  if(time > 0) usleep(time);
176  }
177 }
178 
180  while(1) {
181  m_controllerPublishMtx.lock();
182  MicroStopwatch stopwatch;
185  m_controllerPublishMtx.unlock();
186 
187  // send autopilot state
188  auto msgUPtr = std::make_unique<std_msgs::msg::UInt8>();
189  msgUPtr->data = static_cast<uint8_t>(m_autopilot.m_decision.get_current_situationstate());
190  m_autopilotStatePubSPtr->publish(std::move(msgUPtr));
191 
192  long long time = stopwatch.get_time();
193  log("\033[33mAutoPilotNode [debug_publish_loop]: Sending Debug Messages [microsec]: ", time, "\033[0m");
194  // sleep (~30hz)
195  time = 33000 - time;
196  if(time > 0) {
197  usleep(time);
198  }
199  }
200 }
201 
203  com::SharedData data;
204 
205  while(1) {
207  log("\033[44[AutoPilotNode] [lane_detection_shared_memory_loop] New lane message!\033[49");
208 
209  sensor_msgs::msg::Image::SharedPtr imageMsg = std::make_shared<sensor_msgs::msg::Image>();
210  imageMsg->height = 256;
211  imageMsg->width = 256;
212  imageMsg->step = imageMsg->width * 3;
213  imageMsg->data.resize(imageMsg->step * imageMsg->height);
214  imageMsg->encoding = sensor_msgs::image_encodings::RGB8;
215 
216  data.data = imageMsg->data.data();
217  data.dataSize = imageMsg->data.size();
218 
220  if(dataSizeRead == 0) {
221  log_warning("[AutoPilotNode] Sth failed while reading shared memory!");
222  continue;
223  }
224  else if(dataSizeRead != m_laneDetectionImageSize) {
225  log_warning("[AutoPilotNode] Shared Memory: Failed to read whole image!");
226  }
227 
228  imageMsg->header.stamp = rclcpp::Time(data.tv_sec, data.tv_nsec);
229 
231 
232  if(m_sendLaneDetectionImage) m_laneDetectionMessage.publish(imageMsg);
233  }
234  else {
235  std::this_thread::sleep_for(3ms);
236  }
237  }
238 }
239 
240 void AutoPilotNode::on_simulation_pose_callback(geometry_msgs::msg::Pose::SharedPtr p_message) {
241  rclcpp::Time currentTime = this->get_clock()->now(); // WARNING Pose has no header!
242 
243  // Copied from https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
244  // yaw (z-axis rotation)
245  double siny_cosp = 2 * (p_message->orientation.w * p_message->orientation.z + p_message->orientation.x * p_message->orientation.y);
246  double cosy_cosp = 1 - 2 * (p_message->orientation.y * p_message->orientation.y + p_message->orientation.z * p_message->orientation.z);
247  double yaw = std::atan2(siny_cosp, cosy_cosp);
248 
249  double absoluteYOrientation = 2*MATH_PI_DOUBLE - yaw;
250  // fix orientation from simulation to internal galaxis representation
251  absoluteYOrientation += MATH_PI_DOUBLE / 2;
252  absoluteYOrientation = std::fmod(absoluteYOrientation, 2*MATH_PI_DOUBLE);
253 
254 
255  Vector2f position = Vector2f(p_message->position.x, p_message->position.y); // m
256  // Shift Position to Front Axis
258  Eigen::Rotation2Df rotationMat(-absoluteYOrientation);
259  carPosOffToFrontAx = rotationMat * carPosOffToFrontAx;
260  position += carPosOffToFrontAx;
261  // position (m) to mm
262  position *= 1000; // to mm
263  // WARNING! currentTime Nanoseconds must not comply with on_vci_lane_detection_callback time; velocity set to 0!
264  m_autopilot.m_localizer.add_position_timepoint(currentTime, position, m_autopilot.m_decision.get_velocity_reference() * 1000.f, absoluteYOrientation);
265 
266 
267  // log_debug("CarPose added. Time: ", currentTime.nanoseconds());
268 }
269 
270 void AutoPilotNode::on_ecu_measurement_callback(MeasurementsType::SharedPtr msg) {
271  log("AutoPilotNode: Received Measurements Message");
272  rclcpp::Time msgTimestamp = msg->header.stamp;
273  // rclcpp::Time msgTimestamp = this->get_clock()->now();
274 
275  double orientation = msg->orientation;
276  m_autopilot.m_localizer.add_state(msgTimestamp, galaxis::motorSettings::erpmToVelocity(msg->motor_erpm) * 1000, orientation);
277 
278  // time of flight right / rear
279  m_autopilot.m_decision.update_tof(float(msg->time_of_flight_right) / 1000.f /*right*/, float(msg->time_of_flight_rear) / 1000.f/*rear*/);
280 }
281 
282 void AutoPilotNode::on_vci_lane_detection_callback(sensor_msgs::msg::Image::SharedPtr msg) {
283  log("AutoPilotNode: Received Lane Detection Message! Image Age [millisec]: ", (this->get_clock()->now() - msg->header.stamp).nanoseconds() / 1000000.f,"; Last Update was before [millisec]: ", (this->get_clock()->now() - m_lastLaneDetectionUpdate).nanoseconds() / 1000000.f);
284  m_lastLaneDetectionUpdate = this->get_clock()->now();
285 
287  log_warning("AutoPilotNode: Localizer never received Car Position. Skip.");
288  return;
289  }
290 
291  if(msg->encoding != sensor_msgs::image_encodings::RGB8) {
292  log_warning("AutoPilotNode: Lane Detection Image Encoding wrong! Must be RGB8 (skipping frame)");
293  return;
294  }
295 
296  MicroStopwatch stopwatch;
297 
298  // Message Timestamp:
299  rclcpp::Time msgTimestamp = msg->header.stamp;
300 
301  // TODO: check clock
302  try {
303  // auto localizationPointSPtr = m_autopilot.m_localizer.get_latest_position_timepoint(); // TODO
304  auto localizationPointSPtr = m_autopilot.m_localizer.get_position_timepoint_by_time(msgTimestamp);
305  galaxis::lina::Vector2f localizationPointPosition = localizationPointSPtr->position / 10; // update Map : divide position by 10 for mm to cm conversion
306 
307  if(m_debugMode == true) {
308  auto localizationLookupDiffTime = msgTimestamp - localizationPointSPtr->timestamp;
309  log_debug("AutoPilotNode: Lane Detection-Pose Lookup Diff Time [nanosec]: ", localizationLookupDiffTime.nanoseconds());
310  log_debug("AutoPilotNode: Lookup Orientation [Rad]: ", localizationPointSPtr->orientation);
311  }
312 
313  m_autopilot.m_mapDataLayer.updateMap(msg, localizationPointPosition, localizationPointSPtr->orientation);
314  }
315  catch (const std::runtime_error& error) {
316  log_error("Runtime ERROR: ", error.what());
317  }
318 
319  log("AutoPilotNode [on_vci_lane_detection_callback]: Map Data Layer update duration [microsec]: ", stopwatch.get_time());
320 
321  // this->send_controller_references();
322 }
323 
325  MicroStopwatch stopwatch;
326 
327  m_controllerPublishMtx.lock();
329 
330  m_controllerPublishMtx.unlock();
331  log("\033[36mAutoPilotNode [send_controller_references]: Polynom Extraction [microsec]: ", stopwatch.get_time(), "\033[0m");
332 
333  std::unique_ptr<PathpolynomType> polyMsg = std::make_unique<PathpolynomType>();
334 
335  polyMsg->header.stamp = this->get_clock()->now();
336  if(m_currentDriveInformationSPtr->polynom->size() == 4) {
337  polyMsg->c[0] = m_currentDriveInformationSPtr->polynom->at(0);
338  polyMsg->c[1] = m_currentDriveInformationSPtr->polynom->at(1);
339  polyMsg->c[2] = m_currentDriveInformationSPtr->polynom->at(2);
340  polyMsg->c[3] = m_currentDriveInformationSPtr->polynom->at(3);
341  } else {
342  polyMsg->c[0] = 0;
343  polyMsg->c[1] = 0;
344  polyMsg->c[2] = 0;
345  polyMsg->c[3] = 0;
346  log_error("[AutopilotNode] Polynom Wrong.");
347  }
348 
349  if(m_currentDriveInformationSPtr->right != nullptr){
350  for(uint32_t i = 0; i < m_currentDriveInformationSPtr->right->size(); i ++){
351  polyMsg->c_r[i] = m_currentDriveInformationSPtr->right->at(i);
352  }
353 
354  polyMsg->max_right = m_currentDriveInformationSPtr->rightPolyMax;
355  polyMsg->min_right = m_currentDriveInformationSPtr->rightPolyMin;
356  polyMsg->right_enabled = true;
357  }
358 
359  if(m_currentDriveInformationSPtr->center != nullptr){
360  for(uint32_t i = 0; i < m_currentDriveInformationSPtr->center->size(); i ++){
361  polyMsg->c_m[i] = m_currentDriveInformationSPtr->center->at(i);
362  }
363 
364  polyMsg->max_center = m_currentDriveInformationSPtr->centerPolyMax;
365  polyMsg->min_center = m_currentDriveInformationSPtr->centerPolyMin;
366  polyMsg->center_enabled = true;
367  }
368 
369  if(m_currentDriveInformationSPtr->left != nullptr){
370  for(uint32_t i = 0; i < m_currentDriveInformationSPtr->left->size(); i ++){
371  polyMsg->c_l[i] = m_currentDriveInformationSPtr->left->at(i);
372  }
373 
374  polyMsg->max_left = m_currentDriveInformationSPtr->leftPolyMax;
375  polyMsg->min_left = m_currentDriveInformationSPtr->leftPolyMin;
376  polyMsg->left_enabled = true;
377  }
378  // Controller Reference
379  std::unique_ptr<ControllerReferenceType> controllerRefMsgUPtr = std::make_unique<ControllerReferenceType>();
380 
381  controllerRefMsgUPtr->header.stamp = this->get_clock()->now();
382  controllerRefMsgUPtr->velocity_reference = m_currentDriveInformationSPtr->velocityReference;
383  controllerRefMsgUPtr->indicator_left = m_currentDriveInformationSPtr->indicatorLeft;
384  controllerRefMsgUPtr->indicator_right = m_currentDriveInformationSPtr->indicatorRight;
385  // controllerRefMsgUPtr->velocity_apply_raw = m_currentDriveInformationSPtr->startParking; // apply this velocity for parking
386 
387  std::unique_ptr<ParkingOperationType> parkingOperationUPtr = std::make_unique<ParkingOperationType>();
388  parkingOperationUPtr->header = polyMsg->header;
389  if(m_currentDriveInformationSPtr->startParking) {
390  parkingOperationUPtr->operation = 2;
391  }
392  else {
393  parkingOperationUPtr->operation = 1; // stop parking node
394  }
395 
396  // publish at same time
397  m_pathpolynomPubSPtr->publish(std::move(polyMsg));
398  m_controllerRefPubSPtr->publish(std::move(controllerRefMsgUPtr));
399  m_parkingOperationPubSPtr->publish(std::move(parkingOperationUPtr));
400 }
401 
402 void AutoPilotNode::on_obstacle_callback(ObstacleListType::SharedPtr msg) {
404  log_warning("AutoPilotNode [on_obstacle_callback]: Obstacle CB - Localizer never received Car Position. Skip.");
405  return;
406  }
407 
408  if(msg->obstacles.size() <= 0) { return; }
409 
410  log("AutoPilotNode: Obstacle Message received. Size: ", msg->obstacles.size());
411 
412  rclcpp::Time msgTimestamp = msg->header.stamp;
413  auto posTpSPtr = m_autopilot.m_localizer.get_position_timepoint_by_time(msgTimestamp);
414  // auto posTpSPtr = m_autopilot.m_localizer.get_latest_position_timepoint();
415 
416  for(auto obstacleTypeObj : msg->obstacles) {
417  m_autopilot.m_mapDataLayer.addOrUpdateStaticObstacle(obstacleTypeObj, posTpSPtr->position / 10, posTpSPtr->orientation, msgTimestamp);
418  }
419 }
420 
421 void AutoPilotNode::on_qr_code_callback(QRCodeDetectType::SharedPtr msg) {
422  log_debug("AutoPilotNode: QRCode Message received. Value: ", msg->detected);
423 
424  if(msg->detected == true) {
426  }
427 
428  if(msg->detected == false && m_qrCodeDetectedSomeTime) {
430  }
431 }
432 
433 void AutoPilotNode::on_stop_line_callback(StopLineType::SharedPtr msg) {
434  log_debug("AutoPilotNode: StopLine Message received. Value: ", msg->stopline_distance);
435  static galaxis::lina::Vector2f positionOffset(0.f,0.f);
436 
437  if(msg->stopline_flag == true) {
438  // additional check for orientation
439  float min = 3.f;
440  float max = 4.f;
441 
442  auto estimatedPositionMM = m_autopilot.m_localizer.get_latest_position_timepoint()->position - positionOffset;
443  float currentOrientation = m_autopilot.m_localizer.get_latest_position_timepoint()->orientation;
444 
445  if(currentOrientation < min || currentOrientation > max) {
446  m_autopilot.m_decision.update_stopline(msg->stopline_distance);
447  }
448  }
449 
450  if(msg->startline_flag == true) {
451  // additional check for orientation
452  float minOrientationForParking = 2.f;
453  float maxOrientationForParking = 4.f;
454 
456  float currentOrientation = m_autopilot.m_localizer.get_latest_position_timepoint()->orientation;
457  if(currentOrientation >= minOrientationForParking && currentOrientation <= maxOrientationForParking) {
458  positionOffset = currentPosition;
460  }
461  }
462 }
463 
464 void AutoPilotNode::on_parking_state_callback(ParkingStateType::SharedPtr msg) {
465  log_debug("AutoPilotNode: ParkingState Message received. Value: ", int(msg->state));
466 
467  switch (msg->state) {
468  case 1:
470  break;
471  case 2:
473  break;
474  case 3:
476  break;
477  case 4:
479  break;
480  case 5:
482  break;
483  default:
484  break;
485  }
486 
487  m_lastParkingState = msg->state;
488 }
489 
491  if(m_mapDataImageDebugPub.getNumSubscribers() == 0) {
492  log("AutoPilotNode [send_map_debug_image]: Skip sending message. Reason: NO Subscriber");
493  return;
494  }
495  if(m_autopilot.m_laneCentersPairVecUPtr == nullptr || m_autopilot.m_linesObject == nullptr) {
496  log_warning("AutoPilotNode [send_map_debug_image]: Cannot send map data (not existing). Skipped.");
497  return;
498  }
499 
500  std::shared_ptr<PositionTimepoint> positionTimepointNow = m_autopilot.m_localizer.get_latest_position_timepoint();
501 
502  std::shared_ptr<sensor_msgs::msg::Image> lineMessageUPtr = std::make_unique<sensor_msgs::msg::Image>();
503 
504  lineMessageUPtr->header.stamp = positionTimepointNow->timestamp;
505 
506  lineMessageUPtr->width = m_autopilot.m_mapDataLayer.m_lookupWindowSizeCMWidth; // m_autopilot.m_linesObject->windowSize[0];
507  lineMessageUPtr->height = m_autopilot.m_mapDataLayer.m_lookupWindowSizeCMHeight + galaxis::autopilot::lookupLookBehindCarCM; // m_autopilot.m_linesObject->windowSize[1];
508  lineMessageUPtr->encoding = sensor_msgs::image_encodings::RGB8;
509  lineMessageUPtr->is_bigendian = 0;
510  lineMessageUPtr->step = lineMessageUPtr->width * 3;
511 
512  lineMessageUPtr->data.clear();
513  lineMessageUPtr->data.resize(lineMessageUPtr->step * lineMessageUPtr->height);
514 
515  int linePointsAmountOnImage = 0;
516 
517  // extract left line points
518  LinePoints<int16_t>* lineMapObjPtr = &m_autopilot.m_linesObject->leftLine;
520 
521  Vector2f shiftVecForLookBehind = Vector2f(0.f, galaxis::autopilot::lookupLookBehindCarCM);
522 
523  for (int i = 0; i < 3; ++i) { // for all 3 lines
524  for(auto& [pointXRaw, pointsYVec] : lineMapObjPtr->getPointsXY()) {
525  for (auto& pointYRaw : pointsYVec) {
526  // rotate point
527  Vector2f vec = Vector2f(pointXRaw, pointYRaw);
528  vec = m_autopilot.m_linesObject->reverseRotationMatrix * vec;
529  // shift for look behind
530  vec += shiftVecForLookBehind;
531 
532  // to integer
533  int pointX = std::round(vec[0]) + lineMessageUPtr->width / 2;
534  int pointY = lineMessageUPtr->height - std::round(vec[1]);
535 
536  //skip if not on image
537  if (pointX < 0 || pointY < 0 || pointX >= static_cast<int>(lineMessageUPtr->width) || pointY >= static_cast<int>(lineMessageUPtr->height)) {
538  continue;
539  }
540 
541  try {
542  int index = lineMessageUPtr->step * pointY + pointX * 3 + pixelByteIndex;
543  if(index < 0 || index >= static_cast<int>(lineMessageUPtr->data.size())) continue;
544 
545  lineMessageUPtr->data[index] = 255;
546 
547  linePointsAmountOnImage++;
548  }
549  catch (const std::exception& ex) {
550  log_warning("AutopilotNode: [send_map_debug_image] Exception thrown: ", ex.what());
551  }
552  }
553  }
554  // switch to next line (l->c->r)
555  if (pixelByteIndex == galaxis::autopilot::imageLLinePixelByteIndex) {
556  lineMapObjPtr = &m_autopilot.m_linesObject->centerLine;
558  }
559  else if (pixelByteIndex == galaxis::autopilot::imageCLinePixelByteIndex) {
560  lineMapObjPtr = &m_autopilot.m_linesObject->rightLine;
562  }
563  else {
564  // break;
565  }
566  }
567 
568  // get lane centers
569  std::vector<galaxis::lina::Vector2f>* vectorPtr = &m_autopilot.m_laneCentersPairVecUPtr->second;
570  bool rightLane = true;
571  for (int i = 0; i < 2; ++i) { // for both lanes
572  for(auto& point : *vectorPtr) {
573  int imgPointX = std::round(point[0] + shiftVecForLookBehind[0]) + lineMessageUPtr->width / 2;
574  int imgPointY = lineMessageUPtr->height - std::round(point[1] + shiftVecForLookBehind[1]);
575 
576  //skip if not on image
577  if (imgPointX < 0 || imgPointY < 0 || imgPointX >= static_cast<int>(lineMessageUPtr->width) || imgPointY >= static_cast<int>(lineMessageUPtr->height)) {
578  continue;
579  }
580 
581  try {
582  int index = lineMessageUPtr->step * imgPointY + imgPointX * 3;
583  if(index < 0 || index + 2 >= static_cast<int>(lineMessageUPtr->data.size())) continue;
584 
585  if(rightLane) {
586  lineMessageUPtr->data[index] = 255;
587  }
588  else {
589  lineMessageUPtr->data[index + 1] = 255;
590  }
591 
592  lineMessageUPtr->data[index + 2] = 255;
593 
594  linePointsAmountOnImage++;
595  }
596  catch (const std::exception& ex) {
597  log_warning("AutopilotNode: [send_map_debug_image] Exception thrown: ", ex.what());
598  }
599  }
600 
601  vectorPtr = &m_autopilot.m_laneCentersPairVecUPtr->first;
602  rightLane = false;
603  }
604 
605  // draw grid for origin
606  Vector2f origin = Vector2f(lineMessageUPtr->width / 2, galaxis::autopilot::lookupLookBehindCarCM);
607  // X
608  for(unsigned int i = 0; i < lineMessageUPtr->height; ++i) {
609  int index = i * lineMessageUPtr->step + origin[0] * 3;
610  if(index < 0 || index + 2 >= static_cast<int>(lineMessageUPtr->data.size())) log_warning("AutoPilotNode [send_map_debug_image]: While sending debug map message. (origin draw grid (X))");
611  lineMessageUPtr->data[index] = 255;
612  lineMessageUPtr->data[index + 1] = 255;
613  lineMessageUPtr->data[index + 2] = 255;
614  }
615  // Y
616  for(unsigned int i = 0; i < lineMessageUPtr->width; ++i) {
617  int index = lineMessageUPtr->step * (lineMessageUPtr->height - galaxis::autopilot::lookupLookBehindCarCM) + 3*i;
618  if(index < 0 || index + 2 >= static_cast<int>(lineMessageUPtr->data.size())) log_warning("AutoPilotNode [send_map_debug_image]: While sending debug map message. (origin draw grid (Y))");
619  lineMessageUPtr->data[index] = 255;
620  lineMessageUPtr->data[index + 1] = 255;
621  lineMessageUPtr->data[index + 2] = 255;
622  }
623 
624  // draws static obstacles
625  std::shared_ptr<std::vector<StaticObstacle>> obstaclesVecSPtr = m_autopilot.m_mapDataLayer.getObstacles(positionTimepointNow->timestamp, false); // TODO clock
626  Eigen::Rotation2Df rotationMat(positionTimepointNow->orientation);
627  for(StaticObstacle const& obstacle : *obstaclesVecSPtr) {
628  Vector2f relObsPos = obstacle.get_position_now() - positionTimepointNow->position / 10;
629  relObsPos = rotationMat * relObsPos;
630  relObsPos += shiftVecForLookBehind;
631 
632  int radiusCM = obstacle.get_width() / 2;
633  for(int y = -radiusCM; y <= radiusCM; y++) {
634  for(int x = -radiusCM; x <= radiusCM; x++) {
635  if(x*x+y*y <= radiusCM*radiusCM) {
636  int imageX = relObsPos[0] + x + lineMessageUPtr->width / 2;
637  int imageY = lineMessageUPtr->height - relObsPos[1] + y;
638  int index = imageY * lineMessageUPtr->step + imageX * 3;
639 
640  //skip if not on image
641  if (imageX < 0 || imageY < 0 || imageX >= static_cast<int>(lineMessageUPtr->width) || imageY >= static_cast<int>(lineMessageUPtr->height)) {
642  continue;
643  }
644 
645  if(index >= 0 && index + 2 <= static_cast<int>(lineMessageUPtr->data.size())) {
646  lineMessageUPtr->data[index] = 255;
647  lineMessageUPtr->data[index + 1] = 255;
648  lineMessageUPtr->data[index + 2] = 255;
649  }
650  }
651  }
652  }
653  }
654 
655  // draw left and right line polynom
656  // left
657  std::vector<Vector2f>& points = *m_autopilot.m_leftLinePolynomPointsVecSPtr;
658  uint8_t r = 249;
659  uint8_t g = 215;
660  uint8_t b = 28;
661 
662  for(int i = 0; i < 2; i++) {
663  if (i == 1) {
665  r = 255;
666  g = 165;
667  b = 0;
668  }
669  for(auto const& point : points) {
670  int imgPointX = std::round(point[0] + shiftVecForLookBehind[0]) + lineMessageUPtr->width / 2;
671  int imgPointY = lineMessageUPtr->height - std::round(point[1] + shiftVecForLookBehind[1]);
672 
673  //skip if not on image
674  if (imgPointX < 0 || imgPointY < 0 || imgPointX >= static_cast<int>(lineMessageUPtr->width) || imgPointY >= static_cast<int>(lineMessageUPtr->height)) {
675  continue;
676  }
677 
678  try {
679  int index = lineMessageUPtr->step * imgPointY + imgPointX * 3;
680  if(index < 0 || index + 2 >= static_cast<int>(lineMessageUPtr->data.size())) continue;
681 
682  if(rightLane) {
683  lineMessageUPtr->data[index] = r;
684  }
685  else {
686  lineMessageUPtr->data[index + 1] = g;
687  }
688 
689  lineMessageUPtr->data[index + 2] = b;
690 
691  linePointsAmountOnImage++;
692  }
693  catch (const std::exception& ex) {
694  log_warning("AutopilotNode: [send_map_debug_image] Exception thrown: ", ex.what());
695  }
696  }
697  }
698 
699  // draw trajectory polynom
700  if(m_currentDriveInformationSPtr != nullptr) {
701  for(int x = -shiftVecForLookBehind[1]; x < lineMessageUPtr->height - shiftVecForLookBehind[1]; ++x) {
702  // evaluate polynom at x
703  int y = m_autopilot.eval_poly(m_currentDriveInformationSPtr->polynom, static_cast<float>(x) * 0.01) * 100; // m to cm
704 
705  // point must be rotated by 90 cc
706  int imgPointX = std::round(-y + shiftVecForLookBehind[0]) + lineMessageUPtr->width / 2;
707  int imgPointY = lineMessageUPtr->height - std::round(x + shiftVecForLookBehind[1]);
708 
709  //skip if not on image
710  if (imgPointX < 0 || imgPointY < 0 || imgPointX >= static_cast<int>(lineMessageUPtr->width) || imgPointY >= static_cast<int>(lineMessageUPtr->height)) {
711  continue;
712  }
713 
714  try {
715  int index = lineMessageUPtr->step * imgPointY + imgPointX * 3;
716  if(index < 0 || index + 2 >= static_cast<int>(lineMessageUPtr->data.size())) continue;
717 
718  lineMessageUPtr->data[index] = 204;
719  lineMessageUPtr->data[index+1] = 204;
720  lineMessageUPtr->data[index+2] = 204;
721 
722  linePointsAmountOnImage++;
723  }
724  catch (const std::exception& ex) {
725  log_warning("AutopilotNode: [send_map_debug_image] Exception thrown: ", ex.what());
726  }
727  }
728  }
729 
730  // publish message
731  m_mapDataImageDebugPub.publish(lineMessageUPtr);
732 
733  log("AutoPilotNode [send_map_debug_image]: Data Layer Image Message sent. LinePointsAmountOnImage: ", linePointsAmountOnImage);
734 }
735 
737  if(m_fullMapDataImageDebugPub.getNumSubscribers() == 0) {
738  log("AutoPilotNode [send_full_map_debug_image]: Skip sending message. Reason: NO Subscriber");
739  return;
740  }
741 
742  MicroStopwatch stopwatch;
743 
744  Vector2i extractionWindow = Vector2i(1400, 1200);
745 
746  auto lineMessageUPtr = std::make_unique<sensor_msgs::msg::Image>();
747 
748  lineMessageUPtr->header.stamp = this->get_clock()->now();
749  lineMessageUPtr->width = extractionWindow[0];
750  lineMessageUPtr->height = extractionWindow[1];
751  lineMessageUPtr->encoding = sensor_msgs::image_encodings::RGB8;
752  lineMessageUPtr->is_bigendian = 0;
753  lineMessageUPtr->step = lineMessageUPtr->width * 3;
754 
755  lineMessageUPtr->data.clear();
756  lineMessageUPtr->data.resize(lineMessageUPtr->step * lineMessageUPtr->height);
757 
758 
759  auto linesObjRaw = m_autopilot.m_mapDataLayer.getLineObject(Vector2f(-700.f, -600.f), 0, 0, extractionWindow);
760 
761  // extract left line points
762  LinePoints<int16_t>* lineObjPtr = &linesObjRaw->leftLine;
764 
765  for (int i = 0; i < 3; ++i) { // for all 3 lines
766  for(auto& [pointXRaw, pointsYVec] : lineObjPtr->getPointsXY()) {
767  for (auto& pointYRaw : pointsYVec) {
768  // rotate point
769  Vector2f vec = Vector2f(pointXRaw, pointYRaw);
770  // vec = linesObjRaw->reverseRotationMatrix * vec; => no need because no rotation
771 
772  // to integer
773  int pointX = std::round(vec[0]) + lineMessageUPtr->width / 2;
774  int pointY = lineMessageUPtr->height - std::round(vec[1]);
775 
776  //skip if out of image
777  if (pointX < 0 || pointY < 0 || pointX >= static_cast<int>(lineMessageUPtr->width) || pointY >= static_cast<int>(lineMessageUPtr->height)) {
778  continue;
779  }
780 
781  try {
782  int index = lineMessageUPtr->step * pointY + pointX * 3 + pixelByteIndex;
783  if(index >= static_cast<int>(lineMessageUPtr->data.size())) continue;
784 
785  lineMessageUPtr->data[index] = 255;
786  }
787  catch (const std::exception& ex) {
788  log_warning("AutoPilotNode: [send_full_map_debug_image] Exception thrown: ", ex.what());
789  }
790  }
791  }
792  // switch to next line (l->c->r)
793  if (pixelByteIndex == galaxis::autopilot::imageLLinePixelByteIndex) {
794  lineObjPtr = &linesObjRaw->centerLine;
796  }
797  else if (pixelByteIndex == galaxis::autopilot::imageCLinePixelByteIndex) {
798  lineObjPtr = &linesObjRaw->rightLine;
800  }
801  else {
802  // break;
803  }
804 
805  }
806 
807  log("AutoPilotNode [send_full_map_debug_image]: Data Layer FULL MAP Image Message sent. Time consumed [ms]: ", stopwatch.get_milliseconds());
808 
809  m_fullMapDataImageDebugPub.publish(std::move(lineMessageUPtr));
810 }
811 
812 rcl_interfaces::msg::SetParametersResult AutoPilotNode::new_parameters_callback(const std::vector<rclcpp::Parameter>& parameters) {
813  log("[AutopilotNode] NEW PARAMETERS");
814 
815  rcl_interfaces::msg::SetParametersResult result;
816  result.successful = true;
817  result.reason = "";
818 
819  for (const auto &param: parameters) {
820  if (param.get_name() == "obstacle.position_diff_for_rerecognition_cm") {
821  if(check_parameter<int>(param, result, 0)) {
823  }
824  }
825  else if (param.get_name() == "obstacle.obstacle_lookup_distance_cm") {
826  if(check_parameter<int>(param, result, 0)) {
828  }
829  }
830  else if (param.get_name() == "obstacle.obstacle_lookup_distance_step_cm") {
831  if(check_parameter<int>(param, result, 0)) {
833  }
834  }
835  else if (param.get_name() == "obstacle.obstacle_to_lane_center_minimum_distance_for_dodge_cm") {
836  if(check_parameter<int>(param, result, 0)) {
838  }
839  }
840  else if (param.get_name() == "obstacle.obstacle_track_time_ms") {
841  if(check_parameter<int>(param, result, 0)) {
842  div_t divres = div(int(param.as_int()), 1000);
843  m_autopilot.m_mapDataLayer.setObstacleTrackTimeDuration(divres.quot, divres.rem * 1e6);
844  }
845  }
846  else if (param.get_name() == "map_data_layer.lookup_window_size_width_cm") {
847  if(check_parameter<int>(param, result, 0, 300.0)) {
849  }
850  }
851  else if (param.get_name() == "map_data_layer.lookup_window_size_height_cm") {
852  if(check_parameter<int>(param, result, 0, 300.0)) {
854  }
855  }
856  // else if (param.get_name() == "map_data_layer.lookup_look_behind_car_cm") {
857  // if(check_parameter<int>(param, result, 0, 100.0)) {
858  // m_autopilot.m_mapDataLayer.setLookupLookBehindCarCM(param.as_int());
859  // }
860  // }
861  else if (param.get_name() == "map_data_layer.grid_cell_threshold_import") {
862  if(check_parameter<int>(param, result, 0, 255)) {
864  }
865  }
866  else if (param.get_name() == "map_data_layer.grid_cell_threshold_extract") {
867  if(check_parameter<int>(param, result, 0, 255)) {
869  }
870  }
871  else if (param.get_name() == "map_data_layer.grid_cell_threshold_decrease_per_step") {
872  if(check_parameter<int>(param, result, 0, 255)) {
874  }
875  }
876  else if (param.get_name() == "map_data_layer.grid_cell_threshold_increase_per_view") {
877  if(check_parameter<int>(param, result, 0, 255)) {
879  }
880  }
881  else if (param.get_name() == "map_data_extraction_postprocessing.cluster_line_eps_cm") {
882  if(check_parameter<int>(param, result, 1, 50)) {
883  m_autopilot.set_line_cluster_eps(param.as_int());
884  }
885  }
886  else if (param.get_name() == "map_data_extraction_postprocessing.cluster_line_min_pts") {
887  if(check_parameter<int>(param, result, 1, 50)) {
888  m_autopilot.set_line_cluster_min_pts(param.as_int());
889  }
890  }
891  else if (param.get_name() == "trajectory_polynom.degree") {
892  if(check_parameter<int>(param, result, 1, 10)) {
893  m_autopilot.set_polynom_degree(param.as_int());
894  }
895  }
896  else if (param.get_name() == "trajectory_polynom.minimum_points_amount") {
897  if(check_parameter<int>(param, result)) {
899  }
900  }
901  else if (param.get_name() == "trajectory_polynom.append_points_behind_amount") {
902  if(check_parameter<int>(param, result, 0)) {
904  }
905  }
906  else if (param.get_name() == "trajectory_polynom.append_points_behind_distance_cm") {
907  if(check_parameter<int>(param, result, 1, 200)) {
909  }
910  }
911  else if (param.get_name() == "decision.velocity_reference_m_s") {
912  if(check_parameter<double>(param, result, 0.0, 3.0)) {
913  m_autopilot.m_decision.set_velocity_reference(param.as_double());
914  }
915  }
916  else if (param.get_name() == "decision.distance_after_switch_back_to_drive_lane_m") {
917  if(check_parameter<double>(param, result, 0.0, 10.0)) {
919  }
920  }
921  else if (param.get_name() == "decision.critical_obstacle_distance_for_lane_changing_cm") {
922  if(check_parameter<int>(param, result, 0, 500)) {
924  }
925  }
926  else if (param.get_name() == "decision.velocity_reference_parking_zone_m_s") {
927  if(check_parameter<double>(param, result, 0, 2)) {
929  }
930  }
931  else if (param.get_name() == "controller_reference.send_sleep_time_micros") {
932  if(check_parameter<int>(param, result, 1, 100000)) {
934  }
935  }
936  else if (param.get_name() == "lane_center_improvement.polynom_evaluation_step_cm") {
937  if(check_parameter<int>(param, result, 1)) {
939  }
940  }
941  else if (param.get_name() == "lane_center_improvement.polynom_evaluation_step_size_cm") {
942  if(check_parameter<int>(param, result, 1, 100)) {
944  }
945  }
946  else if (param.get_name() == "lane_center_improvement.minimum_number_of_clustered_line_points_to_activate") {
947  if(check_parameter<int>(param, result, 0)) {
949  }
950  }
951  else if (param.get_name() == "control_lines.ignore_stopline_in_start_area_radius_mm") {
952  if(check_parameter<double>(param, result, 0, 100000)) {
953  m_stoplineIgnoreAreaRadius = param.as_double();
954  }
955  }
956  else {
957  result.successful = false;
958  result.reason += "[" + param.get_name() + "] UNKNOWN param or NOT IMPLEMENTED; ";
959  }
960  }
961 
962  if(result.successful == false) {
963  log_warning("[AutopilotNode] Failed to set some parameters. Reasons: ", result.reason);
964  }
965 
966  return result;
967 }
Localizer::get_position_timepoint_by_time
std::shared_ptr< PositionTimepoint > get_position_timepoint_by_time(rclcpp::Time &timestamp)
Definition: Localizer.cpp:89
AutoPilotNode::m_sendFullMapDebugMsg
bool m_sendFullMapDebugMsg
Definition: AutoPilotNode.hpp:28
Localizer::get_latest_position_timepoint
std::shared_ptr< PositionTimepoint > get_latest_position_timepoint()
Definition: Localizer.cpp:85
MapDataLayer::getObstacles
std::shared_ptr< std::vector< StaticObstacle > > getObstacles(rclcpp::Time const &timestamp, bool removeOld=true)
Definition: MapDataLayer.cpp:375
Decision::get_current_situationstate
SituationState get_current_situationstate()
Definition: DecisionStateMachine.cpp:339
MapDataLayer::setLookupWindowSizeCMWidth
void setLookupWindowSizeCMWidth(int value)
Definition: MapDataLayer.cpp:51
AutoPilotNode::send_map_debug_image
void send_map_debug_image()
Definition: AutoPilotNode.cpp:490
AutoPilotNode::lane_detection_shared_memory_loop
void lane_detection_shared_memory_loop()
Definition: AutoPilotNode.cpp:202
galaxis::utils::log_error
void log_error(const Args &... args)
Definition: logger.hpp:50
Decision::start_driving
void start_driving()
Definition: DecisionStateMachine.cpp:43
AutoPilot::m_rightLinePolynomPointsVecSPtr
std::shared_ptr< std::vector< Vector2f > > m_rightLinePolynomPointsVecSPtr
Definition: AutoPilot.hpp:123
GalaxisNode::enable_parameters
void enable_parameters(std::function< rcl_interfaces::msg::SetParametersResult(const std::vector< rclcpp::Parameter > &)> callbackFunc)
Definition: GalaxisNode.cpp:69
Decision::get_velocity_reference
float get_velocity_reference() const
Definition: DecisionStateMachine.cpp:333
node_ros_pubsub_wrapper.hpp
AutoPilot::eval_poly
double eval_poly(DynamicPolynom p_polynom, double p_x)
Definition: AutoPilot.cpp:640
AutoPilotNode::m_debugMode
bool m_debugMode
Definition: AutoPilotNode.hpp:26
AutoPilotNode::m_lastParkingState
std::atomic< uint8_t > m_lastParkingState
Definition: AutoPilotNode.hpp:35
AutoPilot::set_min_number_of_clustered_line_points
void set_min_number_of_clustered_line_points(int value)
Definition: AutoPilot.cpp:82
AutoPilotNode::m_laneDetectionSharedMemoryMode
bool m_laneDetectionSharedMemoryMode
Definition: AutoPilotNode.hpp:29
AutoPilotNode::on_qr_code_callback
void on_qr_code_callback(QRCodeDetectType::SharedPtr msg)
Definition: AutoPilotNode.cpp:421
Decision::update_stopline
void update_stopline(float value)
Definition: DecisionStateMachine.cpp:234
AutoPilotNode::m_subscriberQRCodeSPtr
rclcpp::Subscription< QRCodeDetectType >::SharedPtr m_subscriberQRCodeSPtr
Definition: AutoPilotNode.hpp:54
galaxis::autopilot::imageCLinePixelByteIndex
constexpr int imageCLinePixelByteIndex
Definition: AutopilotSettings.hpp:30
AutoPilot::set_obstacle_lookup_distance_step
void set_obstacle_lookup_distance_step(float value)
Definition: AutoPilot.cpp:52
AutoPilotNode::AutoPilotNode
AutoPilotNode()
Definition: AutoPilotNode.cpp:18
galaxis::autopilot::lookupLookBehindCarCM
constexpr int lookupLookBehindCarCM
Definition: AutopilotSettings.hpp:38
AutoPilot::set_traj_points_start_appending_offset
void set_traj_points_start_appending_offset(int value)
Definition: AutoPilot.cpp:67
AutoPilotNode::m_stoplineIgnoreAreaRadius
std::atomic< float > m_stoplineIgnoreAreaRadius
Definition: AutoPilotNode.hpp:75
json
nlohmann::json json
Definition: AutoPilotNode.hpp:21
AutoPilotNode::m_simulationMode
bool m_simulationMode
Definition: AutoPilotNode.hpp:25
settings.hpp
Decision::m_stopAtStartLine
bool m_stopAtStartLine
Definition: DecisionStateMachine.hpp:33
galaxis::ros
Definition: node_ros_pubsub_wrapper.hpp:15
galaxis::utils::log_warning
void log_warning(const Args &... args)
Definition: logger.hpp:41
AutoPilotNode::m_subscriberObstaclesSPtr
rclcpp::Subscription< ObstacleListType >::SharedPtr m_subscriberObstaclesSPtr
Definition: AutoPilotNode.hpp:52
MapDataLayer::setCellLineIncreasePerView
void setCellLineIncreasePerView(uint8_t value)
Definition: MapDataLayer.cpp:69
AutoPilotNode::on_parking_state_callback
void on_parking_state_callback(ParkingStateType::SharedPtr msg)
Definition: AutoPilotNode.cpp:464
com::SharedData::data
uint8_t * data
Definition: SharedMemory.hpp:20
MapDataLayer::getLineObject
std::shared_ptr< LinesObject< int16_t > > getLineObject(Vector2f absolutePositionCM, float lookBehindPosOffsetCM, double absoluteOrientation, Vector2i windowSize)
Definition: MapDataLayer.cpp:250
AutoPilotNode::m_fullMapDataImageDebugPub
image_transport::Publisher m_fullMapDataImageDebugPub
Definition: AutoPilotNode.hpp:62
MapDataLayer::setLookupWindowSizeCMHeight
void setLookupWindowSizeCMHeight(int value)
Definition: MapDataLayer.cpp:54
AutoPilotNode::m_subscriberCarPoseSPtr
rclcpp::Subscription< geometry_msgs::msg::Pose >::SharedPtr m_subscriberCarPoseSPtr
Definition: AutoPilotNode.hpp:51
InParking
@ InParking
Definition: Decision.hpp:23
com::SharedData::dataSize
size_t dataSize
Definition: SharedMemory.hpp:21
AutoPilotNode::m_carposePubSPtr
rclcpp::Publisher< CarPoseEstimatedType >::SharedPtr m_carposePubSPtr
Definition: AutoPilotNode.hpp:45
Decision::set_critical_obstacle_distance_for_lane_changing
void set_critical_obstacle_distance_for_lane_changing(int valueCM)
Definition: DecisionStateMachine.cpp:36
map::classes::LinePoints::getPointsXY
std::map< T, std::vector< T > > & getPointsXY()
Definition: MapClasses.hpp:62
AutoPilotNode::send_controller_references
void send_controller_references()
Definition: AutoPilotNode.cpp:324
MapDataLayer::setCellThresholdExtract
void setCellThresholdExtract(uint8_t value)
Definition: MapDataLayer.cpp:63
file.hpp
AutoPilotNode::m_qrCodeDetectedSomeTime
bool m_qrCodeDetectedSomeTime
Definition: AutoPilotNode.hpp:73
galaxis::utils::read_json_file
shared_ptr< json > read_json_file(std::string path)
Definition: settings.cpp:5
AutoPilot::m_linesObject
std::shared_ptr< LinesObject< int16_t > > m_linesObject
Definition: AutoPilot.hpp:53
AutoPilotNode::on_vci_lane_detection_callback
void on_vci_lane_detection_callback(sensor_msgs::msg::Image::SharedPtr msg)
Definition: AutoPilotNode.cpp:282
GalaxisNode::get_global_settings
json const & get_global_settings()
Definition: GalaxisNode.cpp:119
AutoPilotNode::on_stop_line_callback
void on_stop_line_callback(StopLineType::SharedPtr msg)
Definition: AutoPilotNode.cpp:433
AutoPilotNode::m_autopilot
AutoPilot m_autopilot
Definition: AutoPilotNode.hpp:39
MapDataLayer::updateMap
void updateMap(const sensor_msgs::msg::Image::ConstSharedPtr &laneDetectionSPtr, Vector2f currentAbsoluteCarPositionCM, double currentAbsoluteOrientation)
Definition: MapDataLayer.cpp:83
com::SharedData::tv_sec
int32_t tv_sec
Definition: SharedMemory.hpp:18
AutoPilot::set_polynom_min_points_amount
void set_polynom_min_points_amount(int value)
Definition: AutoPilot.cpp:61
AutoPilotNode::m_controllerReferenceSendSleepTimeMicroSec
int m_controllerReferenceSendSleepTimeMicroSec
Definition: AutoPilotNode.hpp:32
com::SharedData::tv_nsec
uint32_t tv_nsec
Definition: SharedMemory.hpp:19
AutoPilotNode::~AutoPilotNode
~AutoPilotNode()
Definition: AutoPilotNode.cpp:150
AutoPilot::m_localizer
Localizer m_localizer
Definition: AutoPilot.hpp:50
AutoPilot::set_line_cluster_eps
void set_line_cluster_eps(int value)
Definition: AutoPilot.cpp:70
MapDataLayer::setLaneImageConversionFactor
void setLaneImageConversionFactor(float factor)
Definition: MapDataLayer.cpp:72
AutoPilotNode::m_laneDetectionSharedMemory
com::SharedMemory m_laneDetectionSharedMemory
Definition: AutoPilotNode.hpp:69
AutoPilotNode::on_obstacle_callback
void on_obstacle_callback(ObstacleListType::SharedPtr msg)
Definition: AutoPilotNode.cpp:402
galaxis::utils::MicroStopwatch::get_time
long long get_time() const
Definition: clock.cpp:33
com::SharedMemory::is_new_data_available
bool is_new_data_available()
Definition: SharedMemory.cpp:159
Done
@ Done
Definition: Decision.hpp:24
AutoPilotNode::m_laneDetectionImageSize
size_t m_laneDetectionImageSize
Definition: AutoPilotNode.hpp:70
AutoPilotNode::m_parkingOperationPubSPtr
rclcpp::Publisher< ParkingOperationType >::SharedPtr m_parkingOperationPubSPtr
Definition: AutoPilotNode.hpp:46
Decision::set_velocity_reference
void set_velocity_reference(float velocityReference)
Definition: DecisionStateMachine.cpp:24
com::SharedMemory::allocate
bool allocate(size_t sizeBytes)
Definition: SharedMemory.cpp:34
Localizer::add_position_timepoint
void add_position_timepoint(rclcpp::Time &timestamp, galaxis::lina::Vector2f positionMillimeter, double speedMillimeterPerSec, double orientationRad)
Definition: Localizer.cpp:19
AutoPilot::m_leftLinePolynomPointsVecSPtr
std::shared_ptr< std::vector< Vector2f > > m_leftLinePolynomPointsVecSPtr
Definition: AutoPilot.hpp:122
AutoPilotNode::m_lastLaneDetectionUpdate
rclcpp::Time m_lastLaneDetectionUpdate
Definition: AutoPilotNode.hpp:37
MapDataLayer::enableSimulationMode
void enableSimulationMode()
Definition: MapDataLayer.cpp:48
AutoPilotNode::car_pose_publish_loop
void car_pose_publish_loop()
Definition: AutoPilotNode.cpp:152
MapDataLayer::setObstacleTrackTimeDuration
void setObstacleTrackTimeDuration(int sec, int nsec)
Definition: MapDataLayer.cpp:78
galaxis::autopilot::imageLLinePixelByteIndex
constexpr int imageLLinePixelByteIndex
Definition: AutopilotSettings.hpp:29
AutoPilotNode::m_pathpolynomPubSPtr
rclcpp::Publisher< PathpolynomType >::SharedPtr m_pathpolynomPubSPtr
Definition: AutoPilotNode.hpp:43
map::classes::LinePoints
Definition: MapClasses.hpp:19
AutoPilotNode::m_mapDataImageDebugPub
image_transport::Publisher m_mapDataImageDebugPub
Definition: AutoPilotNode.hpp:60
AutoPilotNode::m_poseSendSleepTimeMicroSec
int m_poseSendSleepTimeMicroSec
Definition: AutoPilotNode.hpp:33
galaxis::utils::MicroStopwatch::get_milliseconds
long long get_milliseconds() const
Definition: clock.cpp:37
galaxis::lina::Vector2f
Eigen::Vector2f Vector2f
Definition: linatypes.hpp:14
com::SharedData
Definition: SharedMemory.hpp:17
AutoPilotNode::m_autopilotStatePubSPtr
rclcpp::Publisher< std_msgs::msg::UInt8 >::SharedPtr m_autopilotStatePubSPtr
Definition: AutoPilotNode.hpp:47
AutoPilot::set_line_cluster_min_pts
void set_line_cluster_min_pts(int value)
Definition: AutoPilot.cpp:73
MATH_PI_DOUBLE
constexpr double MATH_PI_DOUBLE
Definition: AutoPilot.hpp:22
MapDataLayer::setObstaclePositionDiffForRerecognition
void setObstaclePositionDiffForRerecognition(float diff)
Definition: MapDataLayer.cpp:75
Decision::set_velocity_reference_parking
void set_velocity_reference_parking(float velocityReference)
Definition: DecisionStateMachine.cpp:29
GalaxisNode
Definition: GalaxisNode.hpp:21
AutoPilotNode::m_currentDriveInformationSPtr
std::shared_ptr< DriveInformation_t > m_currentDriveInformationSPtr
Definition: AutoPilotNode.hpp:65
galaxis::autopilot::realPixelToPositionConversionFactorCM
constexpr float realPixelToPositionConversionFactorCM
Definition: AutopilotSettings.hpp:24
com::SharedMemory::read_mutexed
size_t read_mutexed(com::SharedData &data, size_t sizeToRead)
Definition: SharedMemory.cpp:183
AutoPilot::set_traj_points_to_append_amount
void set_traj_points_to_append_amount(int value)
Definition: AutoPilot.cpp:64
Localizer::add_state
void add_state(rclcpp::Time &timestamp, double speedMillimeterPerSec, double orientationRad)
Definition: Localizer.cpp:30
AutoPilotNode::m_subscriberStopLine
rclcpp::Subscription< StopLineType >::SharedPtr m_subscriberStopLine
Definition: AutoPilotNode.hpp:55
MapDataLayer::setCellThresholdRGBValue
void setCellThresholdRGBValue(uint8_t value)
Definition: MapDataLayer.cpp:60
AutoPilot::get_drive_information
std::shared_ptr< DriveInformation_t > get_drive_information()
Definition: AutoPilot.cpp:87
galaxis::autopilot::imageRLinePixelByteIndex
constexpr int imageRLinePixelByteIndex
Definition: AutopilotSettings.hpp:31
map::classes::StaticObstacle
Definition: MapClasses.hpp:107
galaxis::motorSettings::erpmToVelocity
float erpmToVelocity(float const p_erpm)
returns the velocity in [m/s] for a given ERPM
Definition: motorSettings.cpp:5
AutoPilotNode::m_controllerPublishMtx
std::mutex m_controllerPublishMtx
Definition: AutoPilotNode.hpp:67
AutoPilotNode::send_full_map_debug_image
void send_full_map_debug_image()
Definition: AutoPilotNode.cpp:736
AutoPilotNode.hpp
logger.hpp
MapDataLayer::m_lookupWindowSizeCMHeight
int m_lookupWindowSizeCMHeight
Definition: MapDataLayer.hpp:79
AutoPilotNode::m_subscriberLaneDetectionSub
rclcpp::Subscription< sensor_msgs::msg::Image >::SharedPtr m_subscriberLaneDetectionSub
Definition: AutoPilotNode.hpp:53
Idle
@ Idle
Definition: Decision.hpp:21
AutoPilot::set_obstacle_to_lane_center_min_distance_for_dodge
void set_obstacle_to_lane_center_min_distance_for_dodge(float value)
Definition: AutoPilot.cpp:55
galaxis::utils
Definition: clock.hpp:5
Searching
@ Searching
Definition: Decision.hpp:22
AutoPilotNode::m_subscriberParkingStateSPtr
rclcpp::Subscription< ParkingStateType >::SharedPtr m_subscriberParkingStateSPtr
Definition: AutoPilotNode.hpp:56
galaxis::lina::Vector2i
Eigen::Vector2i Vector2i
Definition: linatypes.hpp:13
AutoPilotNode::on_ecu_measurement_callback
void on_ecu_measurement_callback(MeasurementsType::SharedPtr msg)
Definition: AutoPilotNode.cpp:270
AutoPilot::m_laneCentersPairVecUPtr
std::unique_ptr< std::pair< std::vector< galaxis::lina::Vector2f >, std::vector< galaxis::lina::Vector2f > > > m_laneCentersPairVecUPtr
Definition: AutoPilot.hpp:54
AutoPilot::m_decision
Decision m_decision
Definition: AutoPilot.hpp:51
galaxis::autopilot::simulationPixelToPositionConversionFactorCM
constexpr float simulationPixelToPositionConversionFactorCM
Definition: AutopilotSettings.hpp:26
AutoPilot::set_line_polynom_evaluation_step
void set_line_polynom_evaluation_step(int value)
Definition: AutoPilot.cpp:76
Decision::update_tof
void update_tof(float right, float rear)
Definition: DecisionStateMachine.cpp:264
galaxis::autopilot::simluationCarPositionOffsetToFrontAxisM
const galaxis::lina::Vector2f simluationCarPositionOffsetToFrontAxisM
Definition: AutopilotSettings.hpp:21
Decision::update_starttargetline
void update_starttargetline(float value)
Definition: DecisionStateMachine.cpp:239
galaxis::utils::log
void log(const Args &... args)
Definition: logger.hpp:33
AutoPilotNode::m_controllerRefPubSPtr
rclcpp::Publisher< ControllerReferenceType >::SharedPtr m_controllerRefPubSPtr
Definition: AutoPilotNode.hpp:44
AutoPilotNode::m_measurementSub
rclcpp::Subscription< MeasurementsType >::SharedPtr m_measurementSub
Definition: AutoPilotNode.hpp:50
MapDataLayer::setCellLineDecreasePerView
void setCellLineDecreasePerView(uint8_t value)
Definition: MapDataLayer.cpp:66
MapDataLayer::m_lookupWindowSizeCMWidth
int m_lookupWindowSizeCMWidth
Definition: MapDataLayer.hpp:78
AutoPilotNode::debug_publish_loop
void debug_publish_loop()
Definition: AutoPilotNode.cpp:179
AutoPilotNode::new_parameters_callback
rcl_interfaces::msg::SetParametersResult new_parameters_callback(const std::vector< rclcpp::Parameter > &parameters)
Definition: AutoPilotNode.cpp:812
AutoPilotNode::controller_reference_publish_loop
void controller_reference_publish_loop()
Definition: AutoPilotNode.cpp:169
galaxis::utils::MicroStopwatch
Definition: clock.hpp:10
Localizer::is_empty
bool is_empty()
Definition: Localizer.cpp:15
AutoPilotNode::m_laneDetectionMessage
image_transport::Publisher m_laneDetectionMessage
Definition: AutoPilotNode.hpp:61
AutoPilotNode::on_simulation_pose_callback
void on_simulation_pose_callback(geometry_msgs::msg::Pose::SharedPtr p_message)
Definition: AutoPilotNode.cpp:240
galaxis::utils::log_debug
void log_debug(const Args &... args)
Definition: logger.hpp:62
AutoPilotNode::m_sendLaneDetectionImage
bool m_sendLaneDetectionImage
Definition: AutoPilotNode.hpp:30
MapDataLayer::addOrUpdateStaticObstacle
void addOrUpdateStaticObstacle(ObstacleType const &p_obstacle, Vector2f absolutePositionCM, double currentOrientation, rclcpp::Time const &timestamp)
Definition: MapDataLayer.cpp:391
Decision::set_distance_after_switch_back_lane
void set_distance_after_switch_back_lane(float valueM)
Definition: DecisionStateMachine.cpp:33
AutoPilotNode::m_fakeLineDetectionMode
bool m_fakeLineDetectionMode
Definition: AutoPilotNode.hpp:27
AutoPilot::set_line_polynom_evaluation_step_size
void set_line_polynom_evaluation_step_size(int value)
Definition: AutoPilot.cpp:79
AutopilotSettings.hpp
Decision::set_parking_state
void set_parking_state(ParkingState state)
Definition: DecisionStateMachine.cpp:244
AutoPilot::set_obstacle_lookup_distance
void set_obstacle_lookup_distance(int value)
Definition: AutoPilot.cpp:49
json
nlohmann::json json
Definition: AutoPilotNode.cpp:15
AutoPilot::set_polynom_degree
void set_polynom_degree(int value)
Definition: AutoPilot.cpp:58
AutoPilot::m_mapDataLayer
MapDataLayer m_mapDataLayer
Definition: AutoPilot.hpp:49