Search
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).
Pan-Tilt unit can be controlled in MATLAB using Serial Port I/O.
ser = serial('COM1'); set(ser,'BaudRate',57600); fopen(ser);
ser
fwrite
ptmove(ser, pan_pos, tilt_pos);
pan_pos
tilt_pos
pan_pos==127
tilt_pos==127
function ptmove(ser, pan_pos, tilt_pos, speed) if nargin<4 speed = 3; end sermove(ser, speed, 0, pan_pos); sermove(ser, speed, 1, tilt_pos); end 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]); end
fclose(ser); delete(ser);