Skip to content

Commit

Permalink
Realign track to drive target. (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnwop committed Mar 4, 2019
1 parent 0e77355 commit e02617a
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -52,6 +52,9 @@ In the menu you can set the offset line. If the offset is not `0` a red line wil
### Shift track
Hit `alt + page up` and `alt + page down` in order to shift the track left and right. If you hold down the key the shifting of the track will speed up.

### Realign track
Hit `alt + home` in order to realign the track with the vehicle.

### Terrain angle snapping
If you're not able to create straight lines yourself you can enable angle snapping in the menu. This will align the AB lines with the terrain.

Expand Down
4 changes: 4 additions & 0 deletions modDesc.xml
Expand Up @@ -41,6 +41,7 @@
<action name="GS_ENABLE_STEERING" axisType="HALF"/>
<action name="GS_AXIS_WIDTH" axisType="FULL"/>
<action name="GS_AXIS_SHIFT" axisType="FULL"/>
<action name="GS_AXIS_REALIGN" axisType="HALF"/>
</actions>

<inputBinding>
Expand All @@ -64,5 +65,8 @@
<binding device="KB_MOUSE_DEFAULT" input="KEY_lalt KEY_pageup" axisComponent="+"/>
<binding device="KB_MOUSE_DEFAULT" input="KEY_lalt KEY_pagedown" axisComponent="-"/>
</actionBinding>
<actionBinding action="GS_AXIS_REALIGN">
<binding device="KB_MOUSE_DEFAULT" input="KEY_lalt KEY_home"/>
</actionBinding>
</inputBinding>
</modDesc>
42 changes: 36 additions & 6 deletions src/vehicles/GlobalPositioningSystem.lua
Expand Up @@ -84,6 +84,7 @@ function GlobalPositioningSystem:onRegisterActionEvents(isActiveForInput, isActi
insert(self:addActionEvent(spec.actionEvents, InputAction.GS_AXIS_WIDTH, self, GlobalPositioningSystem.actionEventWidth, false, true, true, true, nil, nil, true))
insert(self:addActionEvent(spec.actionEvents, InputAction.GS_ENABLE_STEERING, self, GlobalPositioningSystem.actionEventEnableSteering, false, true, false, true, nil, nil, true))
insert(self:addActionEvent(spec.actionEvents, InputAction.GS_AXIS_SHIFT, self, GlobalPositioningSystem.actionEventShift, false, true, true, true, nil, nil, true))
insert(self:addActionEvent(spec.actionEvents, InputAction.GS_AXIS_REALIGN, self, GlobalPositioningSystem.actionEventRealign, false, true, false, true, nil, nil, true))

for _, actionEventId in ipairs(nonDrawnActionEvents) do
g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_VERY_LOW)
Expand Down Expand Up @@ -383,7 +384,7 @@ function GlobalPositioningSystem.updateDelayedNetworkInputs(self, dt)
spec.shiftControl.changeCurrentDelay = spec.shiftControl.changeDelay

local dir = MathUtil.sign(lastShiftParallelValue)
GlobalPositioningSystem.shiftParallel(data, dt, dir)
GlobalPositioningSystem.shiftTrackParallel(data, dt, dir)

spec.shiftControl.forceFinalPush = true
end
Expand Down Expand Up @@ -891,16 +892,34 @@ function GlobalPositioningSystem.guideSteering(vehicle, dt)
DriveUtil.accelerateInDirection(vehicle, drivable_spec.axisForward, dt)
end

function GlobalPositioningSystem.shiftParallel(data, dt, direction)
---Shifts the created track parallel
---@param data table
---@param dt number
---@param direction number
function GlobalPositioningSystem.shiftTrackParallel(data, dt, direction)
local snapFactor = Utils.getNoNil(data.snapDirectionMultiplier, 1.0)
local lineDirX, lineDirZ, lineX, lineZ = unpack(data.snapDirection)

lineX = lineX + (snapFactor * dt * 0.001 * lineDirZ) * direction
lineZ = lineZ + (snapFactor * dt * 0.001 * lineDirX) * direction

data.snapDirection = { lineDirX, lineDirZ, lineX, lineZ }
end

---Realigns the created track to the current drive target
---@param self table
---@param data table
function GlobalPositioningSystem.realignTrack(self, data)
local snapFactor = Utils.getNoNil(data.snapDirectionMultiplier, 1.0)
local lineDirX, lineDirZ, lineX, lineZ = unpack(data.snapDirection)
local transX, _, transZ = unpack(data.driveTarget)

-- Todo: take self.guidanceData.offsetWidth in account?
lineX = lineX + (snapFactor * dt / 1000 * lineDirZ) * direction
lineZ = lineZ + (snapFactor * dt / 1000 * lineDirX) * direction
lineX = transX + snapFactor * data.offsetWidth * lineDirZ
lineZ = transZ - snapFactor * data.offsetWidth * lineDirX

-- Todo: store what we offset?
data.snapDirection = { lineDirX, lineDirZ, lineX, lineZ }

self:updateGuidanceData(data, false, false)
end

--- Action events
Expand Down Expand Up @@ -935,6 +954,17 @@ function GlobalPositioningSystem.actionEventShift(self, actionName, inputValue,
spec.lastInputValues.shiftParallelValue = inputValue
end

function GlobalPositioningSystem.actionEventRealign(self, actionName, inputValue, callbackState, isAnalog)
local data = self:getGuidanceData()

if not data.isCreated then
g_currentMission:showBlinkingWarning(g_i18n:getText("guidanceSteering_warning_createTrackFirst"), 2000)
return
end

GlobalPositioningSystem.realignTrack(self, data)
end

function GlobalPositioningSystem.actionEventSetABPoint(self, actionName, inputValue, callbackState, isAnalog)
local spec = self:guidanceSteering_getSpecTable("globalPositioningSystem")

Expand Down
1 change: 1 addition & 0 deletions translations/translation_cz.xml
Expand Up @@ -11,6 +11,7 @@
<text name="input_GS_SHOW_UI" text="Zobrazit menu GPS"/>
<text name="input_GS_SET_AUTO_WIDTH" text="Auto šířka"/>

<text name="input_GS_AXIS_REALIGN" text="Realign track"/>
<text name="input_GS_AXIS_SHIFT_1" text="Posunout stopu doprava"/>
<text name="input_GS_AXIS_SHIFT_2" text="Posunout stopu doleva"/>
<text name="input_GS_AXIS_WIDTH_1" text="Zvýšit šířku"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_de.xml
Expand Up @@ -11,6 +11,7 @@
<text name="input_GS_SHOW_UI" text="Zeige Guidance Steering Menü"/>
<text name="input_GS_SET_AUTO_WIDTH" text="Automatische Breite"/>

<text name="input_GS_AXIS_REALIGN" text="Realign track"/>
<text name="input_GS_AXIS_SHIFT_1" text="Nach rechts verschieben"/>
<text name="input_GS_AXIS_SHIFT_2" text="Nach links verschieben"/>
<text name="input_GS_AXIS_WIDTH_1" text="Breite erhöhen"/>
Expand Down
3 changes: 2 additions & 1 deletion translations/translation_en.xml
Expand Up @@ -11,6 +11,7 @@
<text name="input_GS_SHOW_UI" text="Show guidance steering menu"/>
<text name="input_GS_SET_AUTO_WIDTH" text="Auto width"/>

<text name="input_GS_AXIS_REALIGN" text="Realign track"/>
<text name="input_GS_AXIS_SHIFT_1" text="Shift track right"/>
<text name="input_GS_AXIS_SHIFT_2" text="Shift track left"/>
<text name="input_GS_AXIS_WIDTH_1" text="Increase track width"/>
Expand All @@ -24,7 +25,7 @@
<!--Warnings-->
<text name="guidanceSteering_warning_dropDistance" text="Drive at least 15m in order to set point B. Current traveled distance: %.2f"/>
<text name="guidanceSteering_warning_setWidth" text="Please set a working width first!"/>
<text name="guidanceSteering_warning_createTrackFirst" text="Please create or load a track first before enabling guidance steering!"/>
<text name="guidanceSteering_warning_createTrackFirst" text="Please create or load a track first!"/>

<!--GUI-->
<text name="guidanceSteering_ui_settings" text="Guidance settings"/>
Expand Down
2 changes: 1 addition & 1 deletion translations/translation_es.xml
Expand Up @@ -11,7 +11,7 @@
<text name="input_GS_SHOW_UI" text="Mostrar Menú GPS"/>
<text name="input_GS_SET_AUTO_WIDTH" text="Ancho Auto"/>

<!--TODO: input_GS_AXIS_SHIFT-->
<text name="input_GS_AXIS_REALIGN" text="Realign track"/>
<text name="input_GS_AXIS_SHIFT_1" text="Mover hacia la derecha"/>
<text name="input_GS_AXIS_SHIFT_2" text="Mover hacia la izquierda"/>
<text name="input_GS_AXIS_WIDTH_1" text="Aumentar ancho de trabajo"/>
Expand Down
2 changes: 1 addition & 1 deletion translations/translation_fr.xml
Expand Up @@ -11,7 +11,7 @@
<text name="input_GS_SHOW_UI" text="Afficher le menu de guidage"/>
<text name="input_GS_SET_AUTO_WIDTH" text="Largeur automatique"/>

<!--TODO: input_GS_AXIS_SHIFT-->
<text name="input_GS_AXIS_REALIGN" text="Realign track"/>
<text name="input_GS_AXIS_SHIFT_1" text="Déplacer la ligne vers la droite"/>
<text name="input_GS_AXIS_SHIFT_2" text="Déplacer la ligne vers la gauche"/>
<text name="input_GS_AXIS_WIDTH_1" text="Augmenter la largeur des lignes"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_it.xml
Expand Up @@ -11,6 +11,7 @@
<text name="input_GS_SHOW_UI" text="Mostra menu Guidance Steering"/> <!-- Show guidance steering menu -->
<text name="input_GS_SET_AUTO_WIDTH" text="Larghezza automatica"/> <!-- Auto width -->

<text name="input_GS_AXIS_REALIGN" text="Realign track"/>
<text name="input_GS_AXIS_SHIFT_1" text="Sposta traccia a destra"/> <!-- Shift track right -->
<text name="input_GS_AXIS_SHIFT_2" text="Sposta traccia a sinistra"/> <!-- Shift track left -->
<text name="input_GS_AXIS_WIDTH_1" text="Aumenta larghezza traccia"/> <!-- Increase track width -->
Expand Down
1 change: 1 addition & 0 deletions translations/translation_nl.xml
Expand Up @@ -11,6 +11,7 @@
<text name="input_GS_SHOW_UI" text="Laat stuurbegeleidings menu zien"/>
<text name="input_GS_SET_AUTO_WIDTH" text="Automatische werkbreedte"/>

<text name="input_GS_AXIS_REALIGN" text="Realign track"/>
<text name="input_GS_AXIS_SHIFT_1" text="Verschuif naar rechts"/>
<text name="input_GS_AXIS_SHIFT_2" text="Verschuif naar links"/>
<text name="input_GS_AXIS_WIDTH_1" text="Werkbreedte vergroten"/>
Expand Down
3 changes: 2 additions & 1 deletion translations/translation_pl.xml
Expand Up @@ -10,14 +10,15 @@
<!--Inputs-->
<text name="input_GS_SHOW_UI" text="Pokaż menu ustawień nawigacji"/>
<text name="input_GS_SET_AUTO_WIDTH" text="Automatyczna szerokość"/>

<text name="input_GS_AXIS_REALIGN" text="Realign track"/>
<text name="input_GS_AXIS_SHIFT" text="Przesunięcie ścieżki"/>
<text name="input_GS_AXIS_WIDTH" text="Zmiana szerokości"/>
<text name="input_GS_AXIS_SHIFT_1" text="Przesuń ścieżkę w prawo"/>
<text name="input_GS_AXIS_SHIFT_2" text="Przesuń ścieżkę w lewo"/>
<text name="input_GS_AXIS_WIDTH_1" text="Zwiększ szerokość"/>
<text name="input_GS_AXIS_WIDTH_2" text="Zmniejsz szerokość"/>


<text name="input_GS_ENABLE_STEERING" text="Automatyczne sterowanie"/>
<text name="input_GS_SETPOINT" text="Ustaw punkt nawigacji"/>
<text name="input_GS_TOGGLE_TERRAIN_ANGLE_SNAP" text="Wyrównaj do kąta terenu"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_ru.xml
Expand Up @@ -11,6 +11,7 @@
<text name="input_GS_SHOW_UI" text="Показать меню автоподруливания"/>
<text name="input_GS_SET_AUTO_WIDTH" text="Автоширина"/>

<text name="input_GS_AXIS_REALIGN" text="Realign track"/>
<text name="input_GS_AXIS_SHIFT_1" text="Смещение трека вправо"/>
<text name="input_GS_AXIS_SHIFT_2" text="Смещение трека влево"/>
<text name="input_GS_AXIS_WIDTH_1" text="Увеличить ширину трека"/>
Expand Down

0 comments on commit e02617a

Please sign in to comment.