Last active
September 3, 2021 01:01
-
-
Save joshooaj/179598ea46a60290ef64a4570d36f8cf to your computer and use it in GitHub Desktop.
An example of how to send PTZ commands using MilestonePSTools, complete with reusable functions. May move these into MilestonePSTools later on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-PtzAbsolutePosition { | |
| [CmdletBinding()] | |
| [OutputType([VideoOS.Platform.Messaging.PTZGetAbsoluteRequestData])] | |
| param( | |
| # Specifies the FQID of the PTZ camera. Tip: If you have a "Camera" object, you need a "CameraItem" object instead. Use Get-PlatformItem to get the *Item object for the associated camera. The FQID property can be found attached to this. | |
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | |
| [VideoOS.Platform.FQID]$Fqid | |
| ) | |
| process { | |
| Send-MipMessage -MessageId ([VideoOS.Platform.Messaging.MessageId+Control]::PTZGetAbsoluteRequest) -DestinationEndpoint $fqid -UseEnvironmentManager | |
| } | |
| } | |
| function Start-PtzMovement { | |
| [CmdletBinding()] | |
| param( | |
| # Specifies the FQID of the PTZ camera. Tip: If you have a "Camera" object, you need a "CameraItem" object instead. Use Get-PlatformItem to get the *Item object for the associated camera. The FQID property can be found attached to this. | |
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | |
| [VideoOS.Platform.FQID]$Fqid, | |
| # Specifies a direction where -1 -eq left and 1 -eq right. A value of 0 means the camera will not move on this axis. | |
| [Parameter()] | |
| [ValidateSet(-1, 0, 1)] | |
| [int]$Pan = 0, | |
| # Specifies a direction where -1 -eq up and 1 -eq down. A value of 0 means the camera will not move on this axis. | |
| [Parameter()] | |
| [ValidateSet(-1, 0, 1)] | |
| [int]$Tilt = 0, | |
| # Specifies a direction where -1 -eq zoom out and 1 -eq zoom in. A value of 0 means the camera will not move on this axis. | |
| [Parameter()] | |
| [ValidateSet(-1, 0, 1)] | |
| [int]$Zoom = 0, | |
| # Specifies the speed of movement as a value between 0 and 1. A value of 0 means no movement. Default value is 0.5. | |
| [Parameter()] | |
| [ValidateRange(0, 1)] | |
| [double]$PanSpeed = 0.5, | |
| # Specifies the speed of movement as a value between 0 and 1. A value of 0 means no movement. Default value is 0.5. | |
| [Parameter()] | |
| [ValidateRange(0, 1)] | |
| [double]$TiltSpeed = 0.5, | |
| # Specifies the speed of movement as a value between 0 and 1. A value of 0 means no movement. Default value is 0.5. | |
| [Parameter()] | |
| [ValidateRange(0, 1)] | |
| [double]$ZoomSpeed = 0.5 | |
| ) | |
| process { | |
| $data = [VideoOS.Platform.Messaging.PTZMoveStartCommandData2]@{ | |
| Pan = $Pan | |
| PanSpeed = $PanSpeed | |
| Tilt = $Tilt | |
| TiltSpeed = $TiltSpeed | |
| Zoom = $Zoom | |
| ZoomSpeed = $ZoomSpeed | |
| } | |
| $mipMessage = @{ | |
| MessageId = [VideoOS.Platform.Messaging.MessageId+Control]::PTZMoveStartCommand | |
| DestinationEndpoint = $Fqid | |
| Data = $data | |
| UseEnvironmentManager = $true | |
| } | |
| Send-MipMessage @mipMessage | |
| } | |
| } | |
| function Stop-PtzMovement { | |
| [CmdletBinding()] | |
| [OutputType([VideoOS.Platform.Messaging.PTZGetAbsoluteRequestData])] | |
| param( | |
| # Specifies the FQID of the absolute (Type 1) PTZ camera. Tip: If you have a "Camera" object, you need a "CameraItem" object instead. Use Get-PlatformItem to get the *Item object for the associated camera. The FQID property can be found attached to this. | |
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | |
| [VideoOS.Platform.FQID]$Fqid | |
| ) | |
| process { | |
| Send-MipMessage -MessageId ([VideoOS.Platform.Messaging.MessageId+Control]::PTZMoveStopCommand) -DestinationEndpoint $fqid -UseEnvironmentManager | |
| } | |
| } | |
| function Move-PtzCamera { | |
| [CmdletBinding()] | |
| param( | |
| # Specifies the FQID of the PTZ camera. Tip: If you have a "Camera" object, you need a "CameraItem" object instead. Use Get-PlatformItem to get the *Item object for the associated camera. The FQID property can be found attached to this. | |
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | |
| [VideoOS.Platform.FQID]$Fqid, | |
| # Specifies the FQID of the PTZ camera. Tip: If you have a "Camera" object, you need a "CameraItem" object instead. Use Get-PlatformItem to get the *Item object for the associated camera. The FQID property can be found attached to this. | |
| [Parameter(Mandatory)] | |
| [ValidateSet('Down', 'DownLeft', 'DownRight', 'Home', 'Left', 'Right', 'Up', 'UpLeft', 'UpRight', 'ZoomIn', 'ZoomOut')] | |
| [string]$Direction | |
| ) | |
| process { | |
| $mipMessage = @{ | |
| MessageId = [VideoOS.Platform.Messaging.MessageId+Control]::PTZMoveCommand | |
| DestinationEndpoint = $Fqid | |
| Data = $Direction | |
| UseEnvironmentManager = $true | |
| } | |
| Send-MipMessage @mipMessage | |
| } | |
| } | |
| function Move-PtzCameraAbsolute { | |
| [CmdletBinding()] | |
| param( | |
| # Specifies the FQID of the PTZ camera. Tip: If you have a "Camera" object, you need a "CameraItem" object instead. Use Get-PlatformItem to get the *Item object for the associated camera. The FQID property can be found attached to this. | |
| [Parameter(Mandatory)] | |
| [VideoOS.Platform.FQID]$Fqid, | |
| # Specifies a Pan value as a double, in a range from -1 to 1. | |
| [Parameter(ValueFromPipelineByPropertyName)] | |
| [ValidateRange(-1, 1)] | |
| [double]$Pan = [double]::NaN, | |
| # Specifies a Tilt value as a double, in a range from -1 to 1. | |
| [Parameter(ValueFromPipelineByPropertyName)] | |
| [ValidateRange(-1, 1)] | |
| [double]$Tilt = [double]::NaN, | |
| # Specifies a Zoom value as a double, in a range from -1 to 1. | |
| [Parameter(ValueFromPipelineByPropertyName)] | |
| [ValidateRange(-1, 1)] | |
| [double]$Zoom = [double]::NaN, | |
| # Specifies the speed of movement as a value between 0 and 1. A value of 0 means no movement. Default value is 0.5. | |
| [Parameter()] | |
| [ValidateRange(0, 1)] | |
| [double]$Speed = 0.5, | |
| # Specifies that the command should be sent, even if it matches the coordinates of the last command sent | |
| [Parameter()] | |
| [switch]$AllowRepeats | |
| ) | |
| process { | |
| $data = [VideoOS.Platform.Messaging.PTZMoveAbsoluteCommandData]@{ | |
| Pan = $Pan | |
| Tilt = $Tilt | |
| Zoom = $Zoom | |
| Speed = $Speed | |
| AllowRepeats = $AllowRepeats.IsPresent | |
| } | |
| $mipMessage = @{ | |
| MessageId = [VideoOS.Platform.Messaging.MessageId+Control]::PTZMoveAbsoluteCommand | |
| DestinationEndpoint = $Fqid | |
| Data = $data | |
| UseEnvironmentManager = $true | |
| } | |
| Send-MipMessage @mipMessage | |
| } | |
| } | |
| # While working with PowerShell by hand, this is a useful way to get a "CameraItem" object which has the FQID property we need | |
| $cameraItem = Select-Camera -OutputAsItem | |
| # Alternatively, if you had a Camera object from Get-Camera, you could do... | |
| $camera = Get-Camera -Id $cameraItem.FQID.ObjectId # Ignore this line - I'm just converting the CameraItem to a Camera object here | |
| $cameraItem = $camera | Get-PlatformItem # This cmdlet can help take an object from Get-Camera or Get-Microphone, and find the matching *Item object using [videoos.platform.configuration]::Instance.GetItem instead of the Configuration API | |
| # Another alternative, if you already know the ID of the camera you want, you can use Get-PlatformItem directly... | |
| $id = $camera.Id.ToLower() | |
| $cameraItem = Get-PlatformItem -SearchText "Camera[$id]" | |
| # Not sure what happens here if the camera is not an absolute PTZ camera | |
| $position = $cameraItem | Get-PTZAbsolutePosition | |
| $position | |
| # Here we start panning to the right until we eventually call Stop-PtzMovement. You can provide Pan, Tilt, and Zoom values and independent speeds for each axis, though not all cameras support simultaneous PTZ | |
| $cameraItem | Start-PtzMovement -Pan 1 | |
| Start-Sleep -Seconds 5 | |
| $cameraItem | Stop-PtzMovement | |
| # To make small incremental movements in 8 directions (like a D-pad with diagonal support), you can call Move-PtzCamera and the camera will move a small amount and stop on it's own | |
| $cameraItem | Move-PtzCamera -Direction Home | |
| # Move the camera to absolute position coordinates -1, 0, 0, sleep, then quickly move it back to the first position we found it in before any PTZ commands. | |
| Move-PtzCameraAbsolute -Pan -1 -Tilt 0 -Zoom 0 -Fqid $cameraItem.FQID -Speed 1 | |
| Start-Sleep -Seconds 5 | |
| $position | Move-PtzCameraAbsolute -Fqid $cameraItem.FQID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment