PTZ-camera control. Pelco-D protocol

Pelco, Pelco-D, PTZ, камера, протокол

Pelco-D - is a PTZ-camera control protocol developed by the same name by Pelco. As a rule, used over RS482/485 interface for communicating with cameras equipped with servo drives.

Pelco-D protocol has in the arsenal of a set of standard commands, as well as advanced instruction set. This article will look at how to work with a standard set of commands. Protocol Pelco-D 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. This reservation was made deliberately, because it is such a challenge recently stood in front of me.

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

Post Pelco-D protocol consists of 7 bytes. Let us analyze the value of each byte:

  1. Byte synchronization - always has #FF value in hexadecimal;
  2. Address - address byte PTZ-camera or any other device on the RS485 / 482 line;
  3. Command 1 - the first byte standard commands Pelco-D;
  4. Command 2 - the second byte standard commands Pelco-D;
  5. Data 1 - byte rotation speed camera left / right, is from #00 to #3F;
  6. Data 2 - speed bytes tilt the camera up / down, is from #00 to #3F;
  7. Checksum - is an 8-bit bytes by the sum of the 2nd to 6th.

Standard set of commands

To send the message must be necessary to form two teams messages. If the data will not be passed on, then it will be necessary to set the zero value bit responsible for this or that functionality.

Consider the structure of commands.

Sense bit charge is meaning of bits 3 and 4. When the bit is lifted, the set bits 3 and 4 have the camera and the auto scan switch, respectively, otherwise raised by bits 3 and 4 have the shutdown. Bits 5 and 6 are reserved and should be set to 0. Other settings are responsible for the diaphragm (Iris), Focus (Focus), Zoom (Zoom), Tilt (Tilt), Rotate (PAN). To enable these parameters should be set to activate the corresponding bits in the unit.

Examples of commands

Rotation to left: FF 01 00 04 00 00 05
Rotation to right: FF 01 00 02 00 00 03
Tilt up: FF 01 00 08 00 00 09
Tilt down: FF 01 00 10 00 00 11
Zoom +: FF 01 00 20 00 00 21
Zoom -: FF 01 00 40 00 00 41

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, command1, command2, data1, data2, checkSum;
    address = command1 = command2 = data1 = data2 = checkSum = 0x00;

    dataPelco = (unsigned char*) malloc(7);

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

    if(tiltSpeed < 0) {
        command2 |= 0x10;
        tiltSpeed *= (-1);
    } else if(tiltSpeed > 0) {
        command2 |= 0x08;
    data2 = (unsigned char)tiltSpeed*63/100;

    if(zoomSpeed < 0) {
        command2 |= 0x40;
    } else if(zoomSpeed > 0) {
        command2 |= 0x20;
    checkSum = address + command1 + command2 + data1 + data2;
    checkSum %= 100;

    dataPelco[0] = 0xFF;
    dataPelco[1] = address;
    dataPelco[2] = command1;
    dataPelco[3] = command2;
    dataPelco[4] = data1;
    dataPelco[5] = data2;
    dataPelco[6] = checkSum;

    sdk_write_pelco_cmd(7, dataPelco); // 7 - это длина сообщения
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.
Support the author Donate


Only authorized users can post comments.
Please, Log in or Sign up
Looking for a Job?
25,000.00 руб. - 30,000.00 руб.
Разработчик Qt/C++
Barnaul, Altai Krai, Russia

For registered users on the site there is a minimum amount of advertising

Sept. 17, 2019, 7:51 a.m.
Julija Aleksandrova

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

  • Result:33points,
  • Rating points-10
Sept. 17, 2019, 7:36 a.m.
Julija Aleksandrova

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

  • Result:10points,
  • Rating points-10
Sept. 16, 2019, 10:47 a.m.
Viktor Dzen'kiv

C++ - Test 002. Constants

  • Result:75points,
  • Rating points2
Last comments
Sept. 17, 2019, 5:07 a.m.
Misha Lebedev

Кстати интересные темы нашёл тут Может что полезного тоже Евгений найдёте
Sept. 17, 2019, 3:50 a.m.
Misha Lebedev

Доброго времени суток. Спасибо за хороший ответ, У меня ситуация така что в галлереи будет несколько миллионов фотографий с фильтрами и тегами , и я опасаюсь за производительност . Это ос…
Sept. 17, 2019, 2:23 a.m.
Evgenij Legotskoj

Добрый день. Да, я тоже читал ту статью в своё время и согласен с тем, что внешние ключи гораздо лучше, чем GenericForeignKey. Выборки в ряде случае работают быстрее. Но лично мне про…
Sept. 14, 2019, 4:08 p.m.
Misha Lebedev

Приветствую вас Евгений , давно наблюда за развитием вашего замечательного портала, много полезно тут нашел , переодически зачитываюсь. Теперь по сушеству, делаю портал и там идеально ложи…
Sept. 10, 2019, 3:38 p.m.
Evgenij Legotskoj

function view для модели Article и LikeDislike.LIKE будет выглядеть так def like(request, pk): obj = Article.objects.get(pk=pk) try: likedislike = LikeDislike.objects.get(cont…
Now discuss on the forum
Sept. 17, 2019, 4:02 a.m.

Да, действительно нужно дебажить, по другому не словить исключение. Уже решил проблему, был выход за предел массива, не правильные входные данные, так что всегда проверяйте размер массива.
Sept. 17, 2019, 2:39 a.m.
Evgenij Legotskoj

Добрый день! На удалённом сервере вряд ли. Этот класс из core модуля, а удалённый сервер - это ещё и network модуль нужно подтягивать. Тут на удалэнном сервере нужно делать программу…
Sept. 17, 2019, 2:30 a.m.
Evgenij Legotskoj

Добрый день! Попробуйте toHex() А также создние QString с помощью from методов. Может быть QString::fromLatin1(). В документации на QString почти два десятка методов from, один из них…
Sept. 16, 2019, 12:54 p.m.

Однозначно PostgreSql не ниже 10 ки.
Sept. 16, 2019, 6:09 a.m.

прочитайте QMAKE_POST_LINK += "~/Qt/5.12.0/clang_64/bin/macdeployqt $${TARGET}.app $$escape_expand( \\n\\t )"
© EVILEG 2015-2019
Recommend hosting TIMEWEB