From 22d3ee838fa61f770d104635b1d5d3e9af62dd4f Mon Sep 17 00:00:00 2001 From: Brandon Danyluk Date: Mon, 12 Apr 2021 01:09:12 -0600 Subject: [PATCH] Fix SALH With Pro-nav the irratic behaviour of the laser caused the missile to over correct, so we average the position and use that running average for the target --- addons/laser/script_component.hpp | 4 +-- .../functions/fnc_seekerType_SALH.sqf | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/addons/laser/script_component.hpp b/addons/laser/script_component.hpp index b0d9951bf3..450614d68e 100644 --- a/addons/laser/script_component.hpp +++ b/addons/laser/script_component.hpp @@ -2,9 +2,9 @@ #define COMPONENT_BEAUTIFIED Laser #include "\z\ace\addons\main\script_mod.hpp" -// #define DRAW_LASER_INFO + #define DRAW_LASER_INFO // #define DEBUG_MODE_FULL -// #define DISABLE_COMPILE_CACHE + #define DISABLE_COMPILE_CACHE // #define ENABLE_PERFORMANCE_COUNTERS #ifdef DEBUG_ENABLED_LASER diff --git a/addons/missileguidance/functions/fnc_seekerType_SALH.sqf b/addons/missileguidance/functions/fnc_seekerType_SALH.sqf index 09e20e7887..e36d57be6e 100644 --- a/addons/missileguidance/functions/fnc_seekerType_SALH.sqf +++ b/addons/missileguidance/functions/fnc_seekerType_SALH.sqf @@ -16,17 +16,38 @@ * * Public: No */ +#define MAX_AVERAGES 15 params ["", "_args"]; _args params ["_firedEH", "_launchParams", "", "_seekerParams"]; _firedEH params ["","","","","","","_projectile"]; _launchParams params ["","","","","","_laserParams"]; -_seekerParams params ["_seekerAngle", "", "_seekerMaxRange"]; +_seekerParams params ["_seekerAngle", "", "_seekerMaxRange", "", ["_lastPositions", []], ["_lastPositionIndex", 0]]; _laserParams params ["_code", "_wavelengthMin", "_wavelengthMax"]; - private _laserResult = [(getPosASL _projectile), (velocity _projectile), _seekerAngle, _seekerMaxRange, [_wavelengthMin, _wavelengthMax], _code, _projectile] call EFUNC(laser,seekerFindLaserSpot); private _foundTargetPos = _laserResult select 0; TRACE_1("Search", _laserResult); -_foundTargetPos; +// average out any error from laser jump +private _positionSum = [0, 0, 0]; +{ + _positionSum = _positionSum vectorAdd _x; +} forEach _lastPositions; + +if (_foundTargetPos isNotEqualTo [0, 0, 0]) then { + _lastPositions set [_lastPositionIndex % MAX_AVERAGES, _foundTargetPos]; + _seekerParams set [4, _lastPositions]; + _seekerParams set [5, _lastPositionIndex + 1]; +}; + +_positionSum = _positionSum vectorAdd _foundTargetPos; +if (MAX_AVERAGES == count _lastPositions) then { + _positionSum = _positionSum vectorMultiply (1 / (1 + count _lastPositions)); +} else { + _positionSum = _positionSum vectorMultiply (1 / count _lastPositions); +}; + +TRACE_3("laser target found",_foundTargetPos,_positionSum,count _lastPositions); + +_positionSum