diff --git a/MainForm_Commands.cs b/MainForm_Commands.cs index 8997f4de..de38e907 100644 --- a/MainForm_Commands.cs +++ b/MainForm_Commands.cs @@ -178,7 +178,8 @@ private void CheckJoystick() { } var d = Math.Sqrt((x*x) + (y*y)); - if (d > 20) + + if (d > 2) //20) { angle = Math.Atan2(y, x); } @@ -199,7 +200,7 @@ private void CheckJoystick() { } cw.Calibrating = true; - cw.PTZ.SendPTZDirection(angle); + cw.PTZ.SendPTZDirection(angle, x, y); if (!cw.PTZ.DigitalPTZ) _needstop = _sentdirection = true; } diff --git a/PTZController.cs b/PTZController.cs index 29b3a967..eeffa13d 100644 --- a/PTZController.cs +++ b/PTZController.cs @@ -111,7 +111,7 @@ internal PTZSettings2Camera PTZSettings } } - internal bool DigitalPTZ => PTZSettings == null; + internal bool DigitalPTZ => _cameraControl.Camobject.ptz == -1; public PTZController(CameraWindow cameraControl) @@ -163,7 +163,7 @@ public void ResetONVIF() _ptzSettings = null; } - public void SendPTZDirection(double angle) + public void SendPTZDirection(double angle, int xPos = 0, int yPos = 0) { if (_cameraControl.Camobject.settings.ptzrotate90) { @@ -232,8 +232,8 @@ public void SendPTZDirection(double angle) if (cmd != Enums.PtzCommand.Stop) { //ignore - continuous - if (_lastCommand == cmd) - return; + //if (_lastCommand == cmd) + // return; } } switch (_cameraControl.Camobject.ptz) @@ -254,7 +254,7 @@ public void SendPTZDirection(double angle) ProcessPelco(cmd, false); return; case -5://ONVIF - ProcessOnvif(cmd); + ProcessOnvif(cmd, xPos, yPos); break; case -6: //none - ignore @@ -370,7 +370,7 @@ internal bool DigitalZoom } - public void SendPTZCommand(Enums.PtzCommand command) + public void SendPTZCommand(Enums.PtzCommand command, int x= 0, int y= 0) { if (_cameraControl.Camera == null) return; @@ -751,16 +751,49 @@ void IAMMove(VideoCaptureDevice d, CameraControlProperty p, int i) private Enums.PtzCommand _lastOnvifCommand = Enums.PtzCommand.Center; private DateTime _lastOnvifCommandSent = DateTime.MinValue; + private float _lastPanSpeed = 0.0f; + private float _lastTiltSpeed = 0.0f; - void ProcessOnvif(Enums.PtzCommand command) + void ProcessOnvif(Enums.PtzCommand command, int xPos=0, int yPos=0) { + + var panSpeed = (float)0.5; + var tiltSpeed = (float)0.5; + if (!_cameraControl.ONVIFConnected) return; - if (command == _lastOnvifCommand && _lastOnvifCommandSent > DateTime.UtcNow.AddSeconds(-4)) + if (xPos != 0) + { + xPos = Math.Abs(xPos); + if (xPos > 100) + xPos = 100; + if (xPos < 0) + xPos = 0; + + panSpeed = (float)(0.5 * (1 + (Math.Tanh((xPos - 50)/ 20)) )); + + } + + if (yPos != 0) + { + yPos = Math.Abs(yPos); + if (yPos > 100) + yPos = 100; + if (yPos < 0) + yPos = 0; + + tiltSpeed = (float)(0.5 * (1 + (Math.Tanh((yPos - 50) / 20)))); + } + + if (command == _lastOnvifCommand && _lastOnvifCommandSent > DateTime.UtcNow.AddSeconds(-4) && + panSpeed == _lastPanSpeed && tiltSpeed == _lastTiltSpeed) return; _lastOnvifCommand = command; _lastOnvifCommandSent = DateTime.UtcNow; + _lastPanSpeed = panSpeed; + _lastTiltSpeed = tiltSpeed; + var od = _cameraControl?.ONVIFDevice; var ptz = od?.PTZ; @@ -775,8 +808,8 @@ void ProcessOnvif(Enums.PtzCommand command) try { _lastCommand = command; - var panSpeed = (float)0.5; - var tiltSpeed = (float)0.5; + //var panSpeed = (float)0.5; + //var tiltSpeed = (float)0.5; var zoomSpeed = (float)1; switch (command) {