A small console utility that allows a user to plug a USB Xbox controller and an RS485-to-USB adapter into their computer and generate Pelco-D compliant pan-tilt-zoom (PTZ) commands for a closed-circuit-television (CCTV) camera.
Tested and used on Linux. Should work on MacOS. No support for Windows.
Serial port and joystick libraries are supposed to support all platforms.
Most features are completed. However, this program is tailored to/tested against a no-name brand of camera I use. In particular, the open menu command may vary by manufacturer.
- Mapping Xbox controls to Pelco-D commands.
- pan X/Y
- zoom in/out
- iris open/close
- open menu (default command is set preset 95. manufacturers may differ)
- Pelco-D address +/-
- Command-line options
- Set initial Pelco-D address.
- Set serial port baud rate.
- Select serial port by name/path.
- Select joystick by number.
- Record commands to text file.
- Playback commands from stdin.
- Override playback address with command line option.
- Refactor controller definitions to support a variety of PC controllers.
- Customize controller mappings via config file.
CCTV Pan-Tilt-Zoom via Xbox Controller
Usage:
cctv-ptz [-v] [-a ADDRESS] [-s FILE] [-j JOYSTICK] [-r FILE] [-b BAUD] [-m MAXSPEED]
cctv-ptz playback [-a ADDRESS] [-s FILE] [-b BAUD] [-v]
cctv-ptz -h
cctv-ptz -V
Options:
-a, --address ADDRESS - Pelco-D address 0-256. (default = 0)
-b, --baud BAUD - set baud rate of serial port. (default = 9600)
-j, --joystick JOYSTICK - use joystick NUM (e.g. /dev/input/jsNUM). (default = 0)
-m, --maxspeed MAXSPEED - set max speed setting 0-100. (default = 100)
-s, --serial FILE - assign serial port for rs485 output. (default = /dev/sttyUSB0)
-r, --record FILE - record rs485 commands to file. (default = /dev/null)
-v, --verbose - prints Pelco-D commands to stdout.
-h, --help - print this help message.
-V, --version - print version info.
Controller Layout
Controller Command
---------- ------
Left Analog
Up (unused)
Down (unused)
Left Left
Right Right
Right Analog
Up Up
Down Down
Left (unused)
Right (unused)
Directional Pad
Up (unused)
Down (unused)
Left (unused)
Right (unused)
A Iris Open
B Iris Close
X Decrement Address
Y Increment Address
Left Bumper Zoom Out
Right Bumper Zoom In
Start Menu (Go to Preset 95)
Back Reset recording start time
Left Trigger Add a "left" mark to recording file
Right Trigger Add a "right" mark to recording file
Find near the top of main.go
the ptz struct
. Modify the initialization
values to map the controller inputs to commands. The xbox struct
defines
names for the controller inputs.
The Pelco-D protocol effectively limits playback to a dead-reckoning system. Small variations in timing or camera speed will amplify into large errors over time. YMMV.