|
234 | 234 |
|
235 | 235 | function AIDriveStrategyCombineCourse:getDriveData(dt, vX, vY, vZ) |
236 | 236 | self:handlePipe(dt) |
| 237 | + self:measureBackDistance() |
237 | 238 | Markers.refreshMarkerNodes(self.vehicle, self.measuredBackDistance) |
238 | 239 | if self.temporaryHold:get() then |
239 | 240 | self:setMaxSpeed(0) |
@@ -2058,34 +2059,48 @@ end |
2058 | 2059 | --- Proximity |
2059 | 2060 | ------------------------------------------------------------------------------------------------------------------------ |
2060 | 2061 |
|
2061 | | -AIDriveStrategyCombineCourse.maxBackDistance = 10 |
| 2062 | +AIDriveStrategyCombineCourse.maxBackDistance = 20 |
2062 | 2063 |
|
2063 | 2064 | function AIDriveStrategyCombineCourse:getMeasuredBackDistance() |
2064 | 2065 | return self.measuredBackDistance |
2065 | 2066 | end |
2066 | 2067 |
|
2067 | 2068 | --- Determine how far the back of the combine is from the direction node |
2068 | | --- TODO: attached/towed harvesters |
2069 | 2069 | function AIDriveStrategyCombineCourse:measureBackDistance() |
2070 | | - self.measuredBackDistance = 0 |
2071 | | - -- raycast from a point behind the vehicle forward towards the direction node |
2072 | | - local nx, ny, nz = localDirectionToWorld(AIUtil.getDirectionNode(self.vehicle), 0, 0, 1) |
2073 | | - local x, y, z = localToWorld(AIUtil.getDirectionNode(self.vehicle), 0, 1.5, -self.maxBackDistance) |
2074 | | - raycastAll(x, y, z, nx, ny, nz, self.maxBackDistance, 'raycastBackCallback', self) |
| 2070 | + -- check and adjust every 10 seconds, mainly for the towed harvesters which may be at an angle when |
| 2071 | + -- the driver starts and our raycast may miss it. |
| 2072 | + if not self.lastBackMeasurementDue then |
| 2073 | + self.lastBackMeasurementDue = CpTemporaryObject(true) |
| 2074 | + end |
| 2075 | + if not self.lastBackMeasurementDue:get() then |
| 2076 | + return |
| 2077 | + end |
| 2078 | + self.lastBackMeasurementDue:set(false, 10000) |
| 2079 | + self.measuredBackDistance = self.measuredBackDistance or 0 |
| 2080 | + local previousMeasuredBackDistance = self.measuredBackDistance |
| 2081 | + -- raycast from a point behind the vehicle forward towards the direction node, in different heights as harvesters |
| 2082 | + -- can be very tricky, such as the Oxbo, which we'll get no hits at all at exactly 1.5 meters... |
| 2083 | + for height = 1.3, 2.5, 0.2 do |
| 2084 | + local nx, ny, nz = localDirectionToWorld(AIUtil.getDirectionNode(self.vehicle), 0, 0, 1) |
| 2085 | + -- use the tool offset, that should cover offset towed harvesters as well |
| 2086 | + local x, y, z = localToWorld(AIUtil.getDirectionNode(self.vehicle), |
| 2087 | + self.settings.toolOffsetX:getValue(), height, -self.maxBackDistance) |
| 2088 | + raycastAll(x, y, z, nx, ny, nz, self.maxBackDistance, 'raycastBackCallback', self, CpUtil.getVehicleCollisionFlags()) |
| 2089 | + end |
| 2090 | + if previousMeasuredBackDistance ~= self.measuredBackDistance then |
| 2091 | + self:debug('Measured back distance changed from %.1f to %.1f m', previousMeasuredBackDistance, self.measuredBackDistance) |
| 2092 | + end |
2075 | 2093 | end |
2076 | 2094 |
|
2077 | 2095 | -- I believe this tries to figure out how far the back of a combine is from its direction node. |
2078 | 2096 | function AIDriveStrategyCombineCourse:raycastBackCallback(hitObjectId, x, y, z, distance, nx, ny, nz, subShapeIndex) |
2079 | 2097 | if hitObjectId ~= 0 then |
2080 | 2098 | local object = g_currentMission:getNodeObject(hitObjectId) |
2081 | | - if object and object == self.vehicle then |
| 2099 | + if object and object.getRootVehicle and object:getRootVehicle() == self.vehicle then |
2082 | 2100 | local d = self.maxBackDistance - distance |
2083 | 2101 | if d > self.measuredBackDistance then |
2084 | 2102 | self.measuredBackDistance = d |
2085 | | - self:debug('Measured back distance is %.1f m', self.measuredBackDistance) |
2086 | 2103 | end |
2087 | | - else |
2088 | | - return true |
2089 | 2104 | end |
2090 | 2105 | end |
2091 | 2106 | end |
|
0 commit comments