[amsat-bb] Automated station using PERL

Andrew Rich vk4tec at people.net.au
Tue Jan 1 17:03:37 PST 2008


I have made a script that asks predict where GO-32 is.

It runs once a second.

It works out if it has to turn off the battery charger and engage the radio.

The script also uses a file to simulate rotator position (till I get the
hardware setup).

It makes a diciscion to turn on and off any of 8 relays, hanging off the
parrallel port. (Power ON/OFF , Rotator CW/CCW)

I figured I have to have some sort of computer controlling the rotators, so
push the process control back to the PC instead of the outboard controller.

In this case, any old A/D would do for the rotator sense.

Next after that will be frequency control.

That is the beauty of LINUX, it is a one stop shop.


--------------------------------------------------------------
sat_controller.pl ----------------------------------------------------------
-----------------------

#!/usr/bin/perl
#
# sat_controller.pl
#
# Andrew Rich VK4TEC - January 2008;
#
# Turn on and off power to rack and control a rotator
#
use Socket;
my $port = 1210;
my ($predict_server, $satellite);
while ()
{
open (sat,"/maint/scripts/sat_pwr_control.sat");
while (<sat>)
{
chop;
$satellite = $_;
}
close (sat);
#
# Ask predict where the satellite is
#
$predict_server = "localhost";
my ($d1, $d2, $d3, $d4, $rawserver) = gethostbyname($predict_server);
my $serveraddr = pack("Sna4x8", 2, $port, $rawserver);
my $prototype = getprotobyname('udp');
socket(SOCKET,2,SOCK_DGRAM,$prototype) || die("No Socket\n");
$| = 1;  # no buffering
$SIG{ALRM} = \&time_out;
#alarm(10);  # Force exit if no response from server
print "Satellite: $satellite\n";
send(SOCKET, "GET_SAT $satellite\0" , 0 , $serveraddr) or die("UDP send
failed $!\n");
my $server_response = '';  # required by recv function
recv(SOCKET, $server_response, 100, 0) or die "UDP recv failed $!\n";
my ($name, $lon, $lat, $az, $el, $aos_seconds, $foot) = split /\n/,
$server_response;
my $aos_time_date = gmtime($aos_seconds);
close(SOCKET);
print "Azimuth: $az\n";
print "Elevation: $el\n";
#
# Work out if we need to power up the rack
#
if ($el =~ m/-/)
{
#system ("/maint/scripts/lptout 128");
print "Power Relay: OFF\n";
}
else
{
#system ("/maint/scripts/lptout 64");
print "Power Relay: ON\n";
}
#
# Turn a rotator
#
open (rot_pos_file , "/maint/scripts/sat_controller.pos");
while (<rot_pos_file>)
{
$rotpos = $_;
}
close (rot_pos);
print "ROT_POS: $rotpos\n";
$diff = $rotpos - $az;
print "DIFF: $diff\n";
if ($diff > 5)
{
if ($diff =~ m/-/)
{
system ("/maint/scripts/lptout 1");
print "MOTOR: CW\n";
$rotpos = $rotpos +5;
open (rot_pos , "> /maint/scripts/sat_controller.pos");
print rot_pos $rotpos;
close (rot_pos_file);
}
else
{
system ("/maint/scripts/lptout 2");
print "MOTOR: CCW\n";
$rotpos = $rotpos -5;
open (rot_pos_file , "> /maint/scripts/sat_controller.pos");
print rot_pos_file $rotpos;
close (rot_pos_file);
}
}
sleep 1;
system ("/maint/scripts/lptout 0");
print "\n";
sleep 1;
}
sub time_out
{
die "Server not responding for satellite $satellite\n";
}


----------------------------------------------------------------------------
Andrew Rich VK4TEC
vk4tec at people.net.au
http://www.tech-software.net




More information about the AMSAT-BB mailing list