Pan-Tilt unit Megarobot

Pan-Tilt Unit consits of two drives AI-701 manufactured by Megarobotics. Drive AI-701 form a servo which is controlled by commands via RS-232 interface. The servo directly interprets commands. There is no intermediary control unit between the PC and the drive.

There are two drives always connected to the one computer via RS-232 bus. Recipient of the control command is determined by the identification number (ID). The azimuth drive (horizontal) has ID == 0, and the drive for the elevation (vertical) has ID == 1. Do not change the ID – you can easily cause malfunction of the device. For the same reasons, it is also prohibited to change the speed of the serial communication interface (baud rate).

  • Manufacturer (MEGAROBOT.NET) provides also manual AI-701.
  • For simple testing, one can use the “AI MOTOR - Tool v1.26”, which is already installed in the workplace.
  • We encourage the student to read a short description of the “Zacínáme s AI-MOTORem”, provided by (MEGAROBOT.NET), where the first step of working with the drive in that program are described.

How to control the PT unit

Pan-Tilt unit can be controlled in MATLAB using Serial Port I/O.

  1. Pan-Tilt is initialized by the following sequence of commands
    ser = serial('COM1');
  2. You can control the PT unit by writing corresponding control bytes (see manuál) to the file ser using command fwrite.
  3. To simplify the PT control the following function is provided:
    ptmove(ser, pan_pos, tilt_pos);
    where pan_pos corresponds to the absolute rotation angle around vertical axis, tilt_pos corresponds to the absolute rotation angle around horizontal axis. Range of values for pan_pos and tilt_pos is from 0 to 254. It covers approximately 80 degrees in a given direction. To set the unit into the initial position (i.e. the position, where camera optical axis is perpendicular to the LCD screen) use the following values pan_pos==127, tilt_pos==127.
    function ptmove(ser, pan_pos, tilt_pos, speed)
        if nargin<4
            speed = 3;
        sermove(ser, speed, 0, pan_pos);
        sermove(ser, speed, 1, tilt_pos);
    function sermove(ser, speed, pantilt, pos)
        b1 = uint8(hex2dec('ff'));
        b2 = uint8(bitshift(uint8(speed), 5) + uint8(pantilt));
        b3 = min(max(uint8(pos), uint8(0)), uint8(254));
        b4 = uint8(bitand(bitxor(b2, b3), uint8(hex2dec('7f'))));
        fwrite(ser, [b1 b2 b3 b4]);
  4. In the end, the communication is closed as follows:
help/common/robot_pan_tilt_megarobot_en.txt · Last modified: 2018/02/03 10:49 (external edit)