|
14 | 14 | * |
15 | 15 | * Public: No |
16 | 16 | */ |
17 | | -// arbitrary constant |
18 | | -#define PROPORTIONALITY_CONSTANT 20 |
19 | 17 | params ["_args", "_timestep", "_seekerTargetPos", "_profileAdjustedTargetPos", "_targetData", "_navigationParams"]; |
20 | | -_args params ["_firedEH"]; |
| 18 | +_args params ["_firedEH", "_launchParams", "_flightParams"]; |
21 | 19 | _firedEH params ["","","","","","","_projectile"]; |
| 20 | +_flightParams params ["_missilePitchRate", "_missileYawRate"]; |
| 21 | +_launchParams params ["","_targetLaunchParams"]; |
| 22 | +_targetLaunchParams params ["", "", "_launchPos"]; |
22 | 23 |
|
23 | | -_navigationParams params ["_yawChange", "_pitchChange", "_lastPitch", "_lastYaw", "_initialPitch", "_pitchUp", "_lastYawRateDifference"]; |
| 24 | +_navigationParams params ["_pid_pitch", "_pid_yaw", "_launchTime", "_pitchChange", "_yawChange", "_initialPitch", "_initialYaw"]; |
| 25 | +private _elapsedTime = CBA_missionTime - _launchTime; |
| 26 | +private _expectedPitch = _initialPitch + _elapsedTime * _pitchChange; |
| 27 | +private _expectedYaw = _initialYaw + _elapsedTime * _yawChange; |
24 | 28 |
|
25 | | -// for some reason we need to multiply this. I don't know why, but it just works |
26 | | -_pitchChange = _pitchChange * 1.5; |
27 | | -_yawChange = _yawChange * 1.5; |
| 29 | +private _position = getPosASLVisual _projectile vectorDiff _launchPos; |
28 | 30 |
|
29 | | -((velocity _projectile) call CBA_fnc_vect2polar) params ["", "_currentYaw", "_currentPitch"]; |
| 31 | +private _distance = 0.01 max vectorMagnitude _position; |
30 | 32 |
|
31 | | -private _pitchRate = if (_timestep == 0) then { |
32 | | - 0 |
33 | | -} else { |
34 | | - (_currentPitch - _lastPitch) / _timestep |
35 | | -}; |
36 | | -_navigationParams set [2, _currentPitch]; |
| 33 | +_profileAdjustedTargetPos params ["", "", "_heightOffset"]; |
| 34 | +private _expectedPosition = ([_distance, _expectedYaw, _expectedPitch] call CBA_fnc_polar2vect) vectorAdd [0, 0, _heightOffset]; |
| 35 | +private _offset = _position vectorDiff _expectedPosition; |
37 | 36 |
|
38 | | -private _pitchModifier = if (_pitchChange == 0) then { |
39 | | - 1 |
40 | | -} else { |
41 | | - abs (_pitchRate / _pitchChange) |
42 | | -}; |
43 | | -private _desiredPitchChange = (_pitchChange - _pitchRate) * PROPORTIONALITY_CONSTANT * _pitchModifier; |
44 | | -_desiredPitchChange = _desiredPitchChange + _pitchUp * (_initialPitch - _currentPitch) * PROPORTIONALITY_CONSTANT * _pitchModifier; |
| 37 | +private _offsetProjectileSpace = _projectile vectorWorldToModelVisual _offset; |
45 | 38 |
|
46 | | -private _yawRate = if (_timestep == 0) then { |
47 | | - 0 |
48 | | -} else { |
49 | | - (_currentYaw - _lastYaw) / _timestep |
50 | | -}; |
51 | | -_navigationParams set [3, _currentYaw]; |
| 39 | +private _pitchCommand = _pitchChange + ([_pid_pitch, _offsetProjectileSpace select 2] call CBA_pid_fnc_update); |
| 40 | +private _yawCommand = _yawChange + ([_pid_yaw, _offsetProjectileSpace select 0] call CBA_pid_fnc_update); |
52 | 41 |
|
53 | | -private _yawRateDifference = _yawChange - _yawRate; |
54 | | -_navigationParams set [6, _yawRateDifference]; |
| 42 | +#ifdef DRAW_NLAW_INFO |
| 43 | +private _projectilePosition = getPosASLVisual _projectile; |
| 44 | +drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,1,1], [0, 0, 0.75] vectorAdd ASLtoAGL _projectilePosition, 0.75, 0.75, 0, format ["%1", _position], 1, 0.025, "TahomaB"]; |
| 45 | +drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,1,1], [0, 0, 0.50] vectorAdd ASLtoAGL _projectilePosition, 0.75, 0.75, 0, format ["%1 m/s", vectorMagnitude velocity _projectile], 1, 0.025, "TahomaB"]; |
| 46 | +drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,1,1], [0, 0, 0.25] vectorAdd ASLtoAGL _projectilePosition, 0.75, 0.75, 0, format ["pCmd [%1] yCmd: [%2]", _pitchCommand, _yawCommand], 1, 0.025, "TahomaB"]; |
| 47 | +drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,1,1], [0, 0, -0.25] vectorAdd ASLtoAGL _projectilePosition, 0.75, 0.75, 0, format ["%1secs", _elapsedTime], 1, 0.025, "TahomaB"]; |
55 | 48 |
|
56 | | -private _desiredYawChange = _yawRateDifference * PROPORTIONALITY_CONSTANT + _yawRateDifference * 2; |
| 49 | +drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,1,1], ASLtoAGL (_launchPos vectorAdd _expectedPosition), 0.75, 0.75, 0, format ["Expected Position"], 1, 0.025, "TahomaB"]; |
| 50 | +drawLine3D [ASLtoAGL _launchPos, ASLtoAGL (_launchPos vectorAdd _expectedPosition), [1, 0, 0, 1], 6]; |
| 51 | +drawLine3D [ASLtoAGL _projectilePosition, ASLtoAGL (_projectilePosition vectorAdd _offset), [0, 0, 1, 1], 6]; |
57 | 52 |
|
58 | | -#ifdef DRAW_NLAW_INFO |
59 | | -private _yawModifier = if (_yawChange == 0) then { |
60 | | - 1 |
61 | | -} else { |
62 | | - abs (_yawRate / _yawChange) |
63 | | -}; |
64 | | -drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,1,1], ASLToAGL getPosASLVisual _projectile, 0.75, 0.75, 0, format ["dP [%1] dY: [%2]", _desiredPitchChange, _desiredYawChange], 1, 0.025, "TahomaB"]; |
65 | | -drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,1,1], [0, 0, 1] vectorAdd ASLToAGL getPosASLVisual _projectile, 0.75, 0.75, 0, format ["pitch proportional [%1] yaw proportional [%2]", _pitchModifier, _yawModifier], 1, 0.025, "TahomaB"]; |
| 53 | +hintSilent format ["pCmd [%1]\nyCmd: [%2]\n\n%3 err\n%4secs", _pitchCommand, _yawCommand, vectorMagnitude _offset, _elapsedTime]; |
66 | 54 | #endif |
67 | 55 |
|
68 | | -TRACE_4("nlaw pitch/yaw info",_currentPitch,_lastPitch,_currentYaw,_lastYaw); |
69 | | -TRACE_6("nlaw navigation",_yawChange,_desiredYawChange,_pitchChange,_desiredPitchChange,_yawRate,_pitchRate); |
70 | | - |
71 | | -_projectile vectorModelToWorldVisual [_yawChange + _desiredYawChange, 0, _pitchChange + _desiredPitchChange] |
| 56 | +_projectile vectorModelToWorldVisual [_yawCommand, 0, _pitchCommand] |
0 commit comments