Calculate an updated drive vector for the rover based on the current pose using the pure pursuit control law.
60 {
61
62 if (m_vReferencePath.empty())
63 {
64
65 LOG_WARNING(logging::g_qSharedLogger, "PurePursuitController::Calculate: Reference path is empty. Cannot calculate drive powers.");
66
67 return DriveVector{0.0, 0.0};
68 }
69
70
72
73
74 if (m_nCurrentReferencePathTargetIndex >= static_cast<int>(m_vReferencePath.size()) - 2)
75 {
76
78 geoops::UTMCoordinate stSecondToLastPoint = m_vReferencePath[m_vReferencePath.size() - 2].GetUTMCoordinate();
80
81
82 double dSegmentX = stLastPoint.dEasting - stSecondToLastPoint.dEasting;
83 double dSegmentY = stLastPoint.dNorthing - stSecondToLastPoint.dNorthing;
84 double dSegmentLenSq = dSegmentX * dSegmentX + dSegmentY * dSegmentY;
85
86
87 double dRoverVectorX = stRoverPos.dEasting - stSecondToLastPoint.dEasting;
88 double dRoverVectorY = stRoverPos.dNorthing - stSecondToLastPoint.dNorthing;
89
90
91 double dNormalDistance = 0.0;
92 if (dSegmentLenSq > 1e-6)
93 {
94 dNormalDistance = (dRoverVectorX * dSegmentX + dRoverVectorY * dSegmentY) / dSegmentLenSq;
95 }
96
97
98 if (dNormalDistance >= 1.0 || std::hypot(dRoverVectorX, dRoverVectorY) < 0.5)
99 {
100
102 return DriveVector{dHeadingToLastWaypoint, 0.0};
103 }
104 }
105
106
108
109
112
113
114 double dTargetMathDeg = std::atan2(dDeltaY, dDeltaX) * (180.0 / M_PI);
115
116
117 double dAbsoluteHeadingGoal = std::fmod(90.0 - dTargetMathDeg + 360.0, 360.0);
118
119 return DriveVector{dAbsoluteHeadingGoal, dMaxSpeed};
120 }
geoops::Waypoint FindLookaheadWaypoint(const geoops::UTMCoordinate &stCurrentPosition)
Searches forward from the current target index to find a point that is at least the lookahead distanc...
Definition PurePursuitController.cpp:266
int FindClosestWaypointIndex(const geoops::UTMCoordinate &stCurrentPosition)
Finds the closest waypoint index in the path to the current position, enforcing topological blinders ...
Definition PurePursuitController.cpp:212
GeoMeasurement CalculateGeoMeasurement(const GPSCoordinate &stCoord1, const GPSCoordinate &stCoord2)
The shortest path between two points on an ellipsoid at (lat1, lon1) and (lat2, lon2) is called the g...
Definition GeospatialOperations.hpp:553
const geoops::UTMCoordinate & GetUTMCoordinate() const
Accessor for the geoops::UTMCoordinate member variable.
Definition GeospatialOperations.hpp:767
This struct stores/contains information about a UTM coordinate.
Definition GeospatialOperations.hpp:211
This struct is used by the WaypointHandler class to store location, size, and type information about ...
Definition GeospatialOperations.hpp:423
const geoops::UTMCoordinate & GetUTMCoordinate() const
Accessor for the geoops::UTMCoordinate member variable.
Definition GeospatialOperations.hpp:508