7 m_mapDataLayer(3), m_threadPool(3), m_decision(dynamic_cast<rclcpp::Node*>(p_gNodePtr)) {
88 std::shared_ptr<DriveInformation_t> driveInformationSPtr = std::make_shared<DriveInformation_t>();
91 driveInformationSPtr->positionTimepoint = *positionTimepoint;
96 std::pair<bool,bool> laneVisiblity = std::make_pair<bool, bool>(
false,
false);
113 std::get<0>(laneVisiblity) =
true;
133 std::get<1>(laneVisiblity) =
true;
142 if (std::get<0>(laneVisiblity) ==
false && std::get<1>(laneVisiblity) ==
false) {
145 rclcpp::Duration maxDriveOnOldPoly(0, 750000000);
148 driveInformationSPtr->polynom = std::make_shared<std::vector<double>>();
149 driveInformationSPtr->polynom->push_back(0.f);
150 driveInformationSPtr->polynom->push_back(0.f);
151 driveInformationSPtr->polynom->push_back(0.f);
152 driveInformationSPtr->polynom->push_back(0.f);
158 log_warning(
"AutoPilot: Blindfish mode! Drive straight.");
181 float rotationClockwise = std::atan(gradient);
182 Eigen::Rotation2Df rotationMat(-rotationClockwise);
190 newPoint = rotationMat * newPoint;
196 driveInformationSPtr->positionTimepoint = *positionTimepoint;
204 log_warning(
"AutoPilot: Blindfish mode! Fall back to last polynom.");
223 driveInformationSPtr->timeLastPolynomCalculated = positionTimepoint->timestamp;
228 return driveInformationSPtr;
231 std::unique_ptr<std::pair<std::vector<galaxis::lina::Vector2f>, std::vector<galaxis::lina::Vector2f>>>
AutoPilot::get_lane_centers(std::shared_ptr<PositionTimepoint> positionTimepoint) {
232 std::unique_ptr<std::pair<std::vector<galaxis::lina::Vector2f>, std::vector<galaxis::lina::Vector2f>>> lanesPairVecUPtr = std::make_unique<std::pair<std::vector<galaxis::lina::Vector2f>, std::vector<galaxis::lina::Vector2f>>>();
265 auto leftLaneMutVecPointer = std::make_shared<MutexedVectorPointer<galaxis::lina::Vector2f>>(&lanesPairVecUPtr->first);
266 auto rightLaneMutVecPointer = std::make_shared<MutexedVectorPointer<galaxis::lina::Vector2f>>(&lanesPairVecUPtr->second);
286 return std::move(lanesPairVecUPtr);
289 void AutoPilot::cluster_line_object(std::map<int16_t, std::vector<int16_t>>& linePointsMapInputRef, std::shared_ptr<std::map<int16_t, int16_t>> linePointsOutVecSPtr) {
295 for(
auto& [xKey, xVec]: linePointsMapInputRef) {
300 std::sort(xVec.begin(), xVec.end());
302 int amountOfPoints = 0;
303 int16_t yMedianOfxVec = xVec.at(
static_cast<int>((xVec.size() + 1) / 2) - 1);
306 auto iPointsVecIterator = linePointsMapInputRef.find(i);
308 if(iPointsVecIterator != linePointsMapInputRef.end()) {
309 for(
auto yPoint: iPointsVecIterator->second) {
322 linePointsOutVecSPtr->insert(std::pair<int16_t,int16_t>(xKey, yMedianOfxVec));
330 std::shared_ptr<std::map<int16_t, int16_t>> p_leftLinePointsMapSPtr,
331 std::shared_ptr<std::map<int16_t, int16_t>> p_centerLinePointsMapSPtr,
332 std::shared_ptr<std::map<int16_t, int16_t>> p_rightLinePointsMapSPtr,
339 for(
auto const& leftPointPairRef: *p_leftLinePointsMapSPtr) {
340 auto centerPointPairIt = p_centerLinePointsMapSPtr->find(leftPointPairRef.first);
341 if(centerPointPairIt != p_centerLinePointsMapSPtr->end()) {
342 float difference = centerPointPairIt->second - leftPointPairRef.second;
344 this->
insert_lane_point(p_leftLaneMutexedVecSPtr, leftPointPairRef.first, (leftPointPairRef.second + difference * 0.5f), p_reverseRotationMat, p_yxMapping);
345 this->
insert_lane_point(p_rightLaneMutexedVecSPtr, leftPointPairRef.first, (leftPointPairRef.second + difference * 1.5f), p_reverseRotationMat, p_yxMapping);
348 auto rightPointPairIt = p_rightLinePointsMapSPtr->find(leftPointPairRef.first);
349 if(rightPointPairIt != p_rightLinePointsMapSPtr->end()) {
350 float difference = rightPointPairIt->second - leftPointPairRef.second;
352 this->
insert_lane_point(p_leftLaneMutexedVecSPtr, leftPointPairRef.first, (leftPointPairRef.second + difference * 0.25f), p_reverseRotationMat, p_yxMapping);
353 this->
insert_lane_point(p_rightLaneMutexedVecSPtr, leftPointPairRef.first, (leftPointPairRef.second + difference * 0.75f), p_reverseRotationMat, p_yxMapping);
358 for(
auto const& centerPointPairRef: *p_centerLinePointsMapSPtr) {
359 auto rightPointPairIt = p_rightLinePointsMapSPtr->find(centerPointPairRef.first);
360 if(rightPointPairIt != p_rightLinePointsMapSPtr->end()) {
361 float difference = rightPointPairIt->second - centerPointPairRef.second;
363 this->
insert_lane_point(p_leftLaneMutexedVecSPtr, centerPointPairRef.first, (centerPointPairRef.second - difference * 0.5f), p_reverseRotationMat, p_yxMapping);
364 this->
insert_lane_point(p_rightLaneMutexedVecSPtr, centerPointPairRef.first, (centerPointPairRef.second + difference * 0.5f), p_reverseRotationMat, p_yxMapping);
372 std::shared_ptr<std::map<int16_t, int16_t>> p_leftLinePointsMapSPtr,
373 std::shared_ptr<std::map<int16_t, int16_t>> p_centerLinePointsMapSPtr,
374 std::shared_ptr<std::map<int16_t, int16_t>> p_rightLinePointsMapSPtr,
393 Vector2f point1, point2, pointsDistanceVector, newPointToInsert, newPointToInsertLeft, newPointToInsertRight, toLaneCenterVector;
397 if(p_leftLinePointsMapSPtr->size() > 25) {
399 int leftMin = 10000000;
401 for(
auto const& pointRef: *p_leftLinePointsMapSPtr) {
403 point = p_reverseRotationMat * point;
407 if (point[1] < leftMin) {
410 if (point[1] > leftMax) {
427 pointsDistanceVector = point2 - point1;
428 toLaneCenterVector = pointsDistanceVector.normalized();
429 toLaneCenterVector = rotationLeftLine * toLaneCenterVector;
431 newPointToInsert = point1 + pointsDistanceVector / 2;
433 newPointToInsertLeft = newPointToInsert + toLaneCenterVector * 20;
434 newPointToInsertRight = newPointToInsert + toLaneCenterVector * 60;
435 p_leftLaneMutexedVecSPtr->push_back(
Vector2f(-newPointToInsertLeft[1], newPointToInsertLeft[0]));
436 p_rightLaneMutexedVecSPtr->push_back(
Vector2f(-newPointToInsertRight[1], newPointToInsertRight[0]));
450 if(p_centerLinePointsMapSPtr->size() > 25) {
452 int leftMin = 10000000;
454 for(
auto const& pointRef: *p_centerLinePointsMapSPtr) {
456 point = p_reverseRotationMat * point;
460 if (point[1] < leftMin) {
463 if (point[1] > leftMax) {
481 pointsDistanceVector = point2 - point1;
482 toLaneCenterVector = pointsDistanceVector.normalized();
483 toLaneCenterVector = rotationLeftLine * toLaneCenterVector;
485 newPointToInsert = point1 + pointsDistanceVector / 2;
487 newPointToInsertLeft = newPointToInsert + toLaneCenterVector * -20;
488 newPointToInsertRight = newPointToInsert + toLaneCenterVector * 20;
489 p_leftLaneMutexedVecSPtr->push_back(
Vector2f(-newPointToInsertLeft[1], newPointToInsertLeft[0]));
490 p_rightLaneMutexedVecSPtr->push_back(
Vector2f(-newPointToInsertRight[1], newPointToInsertRight[0]));
504 if(p_rightLinePointsMapSPtr->size() > 25) {
506 int rightMin = 10000000;
508 for(
auto const& pointRef: *p_rightLinePointsMapSPtr) {
510 point = p_reverseRotationMat * point;
514 if (point[1] < rightMin) {
517 if (point[1] > rightMax) {
533 pointsDistanceVector = point2 - point1;
534 toLaneCenterVector = pointsDistanceVector.normalized();
535 toLaneCenterVector = rotationRightLine * toLaneCenterVector;
537 newPointToInsert = point1 + pointsDistanceVector / 2;
539 newPointToInsertLeft = newPointToInsert + toLaneCenterVector * 60;
540 newPointToInsertRight = newPointToInsert + toLaneCenterVector * 20;
542 p_leftLaneMutexedVecSPtr->push_back(
Vector2f(-newPointToInsertLeft[1], newPointToInsertLeft[0]));
543 p_rightLaneMutexedVecSPtr->push_back(
Vector2f(-newPointToInsertRight[1], newPointToInsertRight[0]));
561 Eigen::Rotation2Df
const& p_rotationMat,
562 bool p_reverseInsertion) {
565 if(!p_reverseInsertion) {
575 point = p_rotationMat * point;
578 p_mutVecPointerSPtr->push_back(point);
582 std::tuple<float, float, float, float> laneBlocked = std::make_tuple<float, float, float>(-1, -1, -1, -1);
587 for(
auto& obstacle : *staticObstaclesVectorSPtr) {
588 Vector2f obstaclePos = obstacle.get_position_now();
589 Vector2f distanceToObstacle = obstaclePos - positionTimepointNow->position / 10;
592 Eigen::Rotation2Df rotationMat(positionTimepointNow->orientation);
593 distanceToObstacle = rotationMat * distanceToObstacle;
595 if(distanceToObstacle[1] >= 0) {
600 if(std::get<0>(laneBlocked) < 0) {
601 x = -
eval_poly(std::get<0>(lanePolynom), y / 100 ) * 100 ;
602 laneToObstacleDistance[0] = x - distanceToObstacle[0];
603 laneToObstacleDistance[1] = y - distanceToObstacle[1];
606 std::get<0>(laneBlocked) = y;
611 if(std::get<1>(laneBlocked) < 0) {
612 x = -
eval_poly(std::get<1>(lanePolynom), y / 100) * 100;
613 laneToObstacleDistance[0] = x - distanceToObstacle[0];
614 laneToObstacleDistance[1] = y - distanceToObstacle[1];
617 std::get<1>(laneBlocked) = y;
623 if(distanceToObstacle[0] >= 10 && distanceToObstacle[0] <= 120) {
624 if(std::get<2>(laneBlocked) < 0.f || std::get<2>(laneBlocked) > distanceToObstacle[1]) {
625 std::get<2>(laneBlocked) = distanceToObstacle[1];
628 if(distanceToObstacle[1] <= 120) {
629 if(std::get<3>(laneBlocked) < 0.f || std::get<3>(laneBlocked) > distanceToObstacle[1]) {
630 std::get<3>(laneBlocked) = distanceToObstacle[1];
643 for(
size_t i = 0; i < p_polynom->size(); ++i) {
646 for(
size_t j = 0; j < i; ++j) {
649 value += p_polynom->at(i) * iValue;