This documentation was implemented by following the explanation provided by http://ryeng.name/blog/3. The goal is, a Rot2Prog output can be sensed by establishing a serial communication based on Matlab software.
To achieved this purpose, you can prepare the equipment as follow :
- - A Personal Computer (Matlab Installed)
- - Rot2Prog controller
- - Of course, matlab code.
The established code is capable of sending the command to controller to move the antenna into a desired azimuth and elvation. The code is also capable of sensing the current azimuth and elevation position.
Fig.1 Equipment used
This is the main code : (main.m)clc
clear
stscmd = hex2dec({'57','00','00','00','00','00','00','00','00','00','00','1F','20'})' ;
stpcmd = hex2dec({'57','00','00','00','00','00','00','00','00','00','00','0F','20'})' ;
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
s = serial('COM3');
set(s,'BaudRate',600,'Parity','None','Timeout', 1);
% Sending command to controller to move the antenna to agiven Az El position
Az = 175 ;
El = 1 ;
fopen(s);
cmd = gotobin(Az,El);
fwrite(s,cmd);
fclose(s);
fopen(s);
% Reading the last Az and El position
fwrite(s,stscmd);
o = fread(s,12) ;
iAz = (o(2)*100) + (o(3)*10) + (o(4)*1) + (o(5)*0.1) - 360 ;
iEl = (o(7)*100) + (o(8)*10) + (o(9)*1) + (o(10)*0.1) - 360 ;
fclose(s);
the gotobin function is consit of the code as showed below :
Supporting code : (gotobin.m)
function cmd = gotobin (Az, El)
cmd = hex2dec({'57','00','00','00','00','02','00','00','00','00','00','2F','20'})' ;
encf = 48 ;
Az = (Az+360) * 2 ;
d = 1000 ; r = mod(Az, d) ; H1 = (Az - r) / d ; Az = Az-(H1*d) ; H1 = encf + H1 ;
d = 100 ; r = mod(Az, d) ; H2 = (Az - r) / d ; Az = Az-(H2*d) ; H2 = encf + H2 ;
d = 10 ; r = mod(Az, d) ; H3 = (Az - r) / d ; Az = Az-(H3*d) ; H3 = encf + H3 ;
d = 1 ; r = mod(Az, d) ; H4 = (Az - r) / d ; H4 = encf + H4 ;
El = (El+360) * 2 ;
d = 1000 ; r = mod(El, d) ; V1 = (El - r) / d ; El = El - (V1*d) ; V1 = encf + V1 ;
d = 100 ; r = mod(El, d) ; V2 = (El - r) / d ; El = El - (V2*d) ; V2 = encf + V2 ;
d = 10 ; r = mod(El, d) ; V3 = (El - r) / d ; El = El - (V3*d) ; V3 = encf + V3 ;
d = 1 ; r = mod(El, d) ; V4 = (El - r) / d ; V4 = encf + V4 ;
cmd(1, 2:5) = [H1 H2 H3 H4] ;
cmd(1, 7:10) = [V1 V2 V3 V4] ;
Please, share after you implement this code. I still continuing to implement this to a GUI application.
Cheers!!