Skip to content

Commit

Permalink
fix: fix field boundaries
Browse files Browse the repository at this point in the history
Remove vertices too close to each other to avoid jumps
and thus uncalculable chirality
  • Loading branch information
Peter Vaiko committed Mar 21, 2024
1 parent 492ab50 commit c30ba27
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CourseGenerator/CourseGenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ NewCourseGenerator.cRowWaypointDistance = 10
-- find corners which the vehicle can't make due to its turning radius, without deviating more than
-- cMaxCrossTrackError meters from the vertex in the corner.
NewCourseGenerator.cMaxCrossTrackError = 0.5
-- Maximum cross track error when generating rows parallel to a non-straight field edge. The row will end when
-- the cross track error is bigger than this limit
NewCourseGenerator.cMaxCrossTrackErrorForCurvedRows = 0.15
-- The delta angle above which smoothing kicks in. No smoothing around vertices with a delta
-- angle below this
NewCourseGenerator.cMinSmoothingAngle = math.rad(15)
Expand Down
4 changes: 2 additions & 2 deletions CourseGenerator/CurvedPathHelper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ end
function CurvedPathHelper.findLongestStraightSection(boundary, ix, radiusThreshold, section)
local i, n, j = ix, 1
-- max one round only (n <) self:at(currentIx):getXte(r)
while n < #boundary and boundary:at(i):getXte(radiusThreshold) < cg.cMaxCrossTrackError do
while n < #boundary and boundary:at(i):getXte(radiusThreshold) < cg.cMaxCrossTrackErrorForCurvedRows do
section:append((boundary:at(i)):clone())
i = i - 1
n = n + 1
end
section:reverse()
j, n = ix + 1, 1
while n < #boundary and boundary:at(j):getXte(radiusThreshold) < cg.cMaxCrossTrackError do
while n < #boundary and boundary:at(j):getXte(radiusThreshold) < cg.cMaxCrossTrackErrorForCurvedRows do
section:append((boundary:at(j)):clone())
j = j + 1
n = n + 1
Expand Down
1 change: 1 addition & 0 deletions CourseGenerator/FieldworkCourseHelper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function FieldworkCourseHelper.createUsableBoundary(originalBoundary, clockwise)
local usableBoundary = originalBoundary:clone()
-- some field scans are not perfect and have sudden direction changes which screws up the clockwise calculation
usableBoundary:removeGlitches()
usableBoundary:ensureMinimumEdgeLength(cg.cMinEdgeLength)
if usableBoundary:isClockwise() ~= clockwise then
-- all headlands are generated in the same direction as the field boundary,
-- so if it does not match the required cw/ccw, reverse it
Expand Down
10 changes: 8 additions & 2 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,12 @@ local function drawFields()
local unpackedVertices = f:getUnpackedVertices()
if #unpackedVertices > 2 then
love.graphics.polygon('line', unpackedVertices)
for _, v in ipairs(f:getBoundary()) do
for i, v in ipairs(f:getBoundary()) do
if v:getRadius() < 10 then
love.graphics.setColor(debugColor)
else
love.graphics.setColor(fieldBoundaryColor)
end
love.graphics.points(v.x, v.y)
end
for _, i in ipairs(f:getIslands()) do
Expand Down Expand Up @@ -571,7 +576,8 @@ local function highlightPathAroundVertex(v)
end

local function highlightPathToNextRow(vertices)
for i, v in ipairs(vertices) do
for i = 1, #vertices - 1 do
local v = vertices[i]
if v:getAttributes():isRowEnd() then
local innermostHeadland = course:findPathToNextRow(v:getAttributes():getAtBoundaryId(),
v, course:getPath()[v.ix + 1], turningRadius:get())
Expand Down

0 comments on commit c30ba27

Please sign in to comment.