Evgenii Legotckoi
Evgenii LegotckoiApril 12, 2016, 7:26 a.m.

PTZ-camera control. Protocol Pelco-P

In the previous article I was considered an option to work with Pelco-D protocol, and now look to work with Pelco-P protocol - a modified variation of the previous PTZ-camera control protocol, which is also developed by the same name by Pelco. Also used over the RS482 / 485 interface for communicating with cameras equipped with servo drives.

Pelco-P protocol also has a set of standard commands, as well as advanced instruction set. Let us consider how we can work with standard commands. Protocol Pelco-P Let us examine the example of the abstract and the abstract command source SDK, which receives the message for onward transmission to its RS485 interface.

Therefore there is a protocol by which data is transmitted, and further understand the data transmitted to the SDK, which sends a message already in the RS485 transmission path. Below is a picture in which there is a yellow square. It is in this function and will form the necessary us the message you want to convey in the SDK.


Message Structure

The checksum is the sum for the exclusive OR, ie XOR, byte from the 1 st to 7 th. As you can see in this protocol using 8 bytes to transmit the message, instead of 7, as in Pelco-D.

It should be noted that the protocol Pelco-P addressing starts with 1 and 0. That is, the first address will be transmitted as #00, but the most interesting is that the PTZ camera settings, the address will be listed as 01, it is necessary to consider this point when developing layer for a given protocol.

PAN and TILT commands

Examples of commands

Rotation to left: A0 00 00 04 20 00 AF 2B
Rotation to right: A0 00 00 02 20 00 AF 2D
Tilt up: A0 00 00 08 00 20 AF 27
Tilt down: A0 00 00 10 00 20 AF 3F
Stop all activities: A0 00 00 00 00 00 AF 0F

Sample code

In this abstract code was created in a vacuum, such a situation that the function of these values fall:

  • address;
  • PanSpeed - rotation speed with the direction, from - 100 to +100;
  • TiltSpeed - Tilt speed with the direction, from -100 to +100;
  • ZoomSpeed - Zoom speed with direction, from -100 to +100. Why so submitted data for Zuma - is a question for me, given that Pelco is no speed setting, but that is what it is.

But SDK has already formed a team takes a pointer to an array of data, and an indication of the length of the array. The result is the following code.

void ptzCmd(int addressPTZ, int panSpeed, int tiltSpeed, int zoomSpeed)
{
    unsigned char *dataPelco;
    unsigned char address, data1, data2, data3, data4, checkSum;
    address = data1 = data2 = data3 = data4 = checkSum = 0x00;

    dataPelco = (unsigned char*) malloc(8);
    memset(dataPelco,0,8);

    address = (unsigned char)addressPTZ;
    --address;
    if(pan < 0) {
        data2 |= 0x04;
        pan *= (-1);
    } else if(pan > 0) {
        data2 |= 0x02;
    }
    data3 = pan*63/100;

    if(tilt < 0) {
        data2 |= 0x10;
        tilt *= (-1);
    } else if(tilt > 0) {
        data2 |= 0x08;
    }
    data4 = tilt*63/100;

    if(zoom < 0) {
        data2 |= 0x40;
    } else if(zoom > 0) {
        data2 |= 0x20;
    }

    checkSum ^= 0xA0;
    checkSum ^= address;
    checkSum ^= data1;
    checkSum ^= data2;
    checkSum ^= data3;
    checkSum ^= data4;
    checkSum ^= 0xAF;

    dataPelco[0] = 0xA0;
    dataPelco[1] = address;
    dataPelco[2] = data1;
    dataPelco[3] = data2;
    dataPelco[4] = data3;
    dataPelco[5] = data4;
    dataPelco[6] = 0xAF;
    dataPelco[7] = checkSum;

    sdk_write_pelco_cmd(8, dataPelco); // 8 - length of message
    free(dataPelco);
}
We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
d
  • dsfs
  • April 26, 2024, 2:56 p.m.

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:80points,
  • Rating points4
d
  • dsfs
  • April 26, 2024, 2:45 p.m.

C++ - Test 002. Constants

  • Result:50points,
  • Rating points-4
d
  • dsfs
  • April 26, 2024, 2:35 p.m.

C++ - Test 001. The first program and data types

  • Result:73points,
  • Rating points1
Last comments
k
kmssrFeb. 9, 2024, 5:43 a.m.
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
EVA
EVADec. 25, 2023, 9:30 p.m.
Boost - static linking in CMake project under Windows Ошибка LNK1104 часто возникает, когда компоновщик не может найти или открыть файл библиотеки. В вашем случае, это файл libboost_locale-vc142-mt-gd-x64-1_74.lib из библиотеки Boost для C+…
J
JonnyJoDec. 25, 2023, 7:38 p.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
G
GvozdikDec. 19, 2023, 8:01 a.m.
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
G
GarApril 22, 2024, 3:46 p.m.
Clipboard Как скопировать окно целиком в clipb?
DA
Dr Gangil AcademicsApril 20, 2024, 5:45 p.m.
Unlock Your Aesthetic Potential: Explore MSC in Facial Aesthetics and Cosmetology in India Embark on a transformative journey with an msc in facial aesthetics and cosmetology in india . Delve into the intricate world of beauty and rejuvenation, guided by expert faculty and …
a
a_vlasovApril 14, 2024, 4:41 p.m.
Мобильное приложение на C++Qt и бэкенд к нему на Django Rest Framework Евгений, добрый день! Такой вопрос. Верно ли следующее утверждение: Любое Android-приложение, написанное на Java/Kotlin чисто теоретически (пусть и с большими трудностями) можно написать и на C+…
Павел Дорофеев
Павел ДорофеевApril 14, 2024, 12:35 p.m.
QTableWidget с 2 заголовками Вот тут есть кастомный QTableView с многорядностью проект поддерживается, обращайтесь
f
fastrexApril 4, 2024, 2:47 p.m.
Вернуть старое поведение QComboBox, не менять индекс при resetModel Добрый день! У нас много проектов в которых используется QComboBox, в версии 5.5.1, когда модель испускает сигнал resetModel, currentIndex не менялся. В версии 5.15 при resetModel происходит try…

Follow us in social networks