[ return ]

mknet



#!/usr/usc/bin/perl
#
#  usage: mknet [-]* 
#
#
#  Read network specification files and generate a corresponding
# network wiring file (to be input into the RS network).
#
#

#     Copyright (C) 1995 Andrew H. Fagg (af0a@robotics.usc.edu)
#     
#     This program is free software; you can redistribute it and/or
#     modify it under the terms of the GNU General Public License
#     as published by the Free Software Foundation; either version 2
#     of the License, or any later version.
#     
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#     
#     You should have received a copy of the GNU General Public License
#     along with this program; if not, write to the Free Software
#     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

require "mknet.defs.pl";
#require "parms.pl";  - now using specialized parameter files.
require "distributed.pl";
require "object.pl";
require "connect.pl";
require "parse.pl";
require "filter.pl";
require "support.pl";
require "dump.pl";
require "f5.pl";
require "grasp.pl";
require "report.pl";

				# Command-line Parameters
$parms = ();
$parms{"d"} = 0;		# Debug mask

				# Database initialization
%objects = ();
%net = ();
%f5 = ();
%aip = ();
%grasp = ();
%ogmap = ();
%mcx = ();


#
#  sub interpret_parms
#
#  Interpret the parameters and stuff them into the %parms
# structure.
#


sub interpret_parms
{
    local($i);

    foreach $i (@ARGV[0..$#ARGV-1]) # Loop through each parm
    {
	if($i =~ /-(\w)(.*)/)	# Expect a - where  is a single 
	{			#  letter.
	    $parms{$1} = $2;
#	    print "$1 = $2\n";
	}
	else			# Not the right format.
	{
	    print "Parameter Error: \"$i\"\n";
	    return 0;
	};
    };
    return 1;
};
############################################################
#  
#

#
#  sub init_joints
#
#  Sets up the map from joint parameter to connector.
#

sub init_joints
{
    local($j, $count);

    $joints{"preferred", "t0"} = "J_T0_pref";
    $joints{"degree", "t0"} = "J_T0_deg";
    $joints{"preferred", "t1"} = "J_T1_pref";
    $joints{"degree", "t1"} = "J_T1_deg";
    $joints{"preferred", "t2"} = "J_T2_pref";
    $joints{"degree", "t2"} = "J_T2_deg";

    $joints{"preferred", "i0"} = "J_I0_pref";
    $joints{"degree", "i0"} = "J_I0_deg";
    $joints{"preferred", "i1"} = "J_I1_pref";
    $joints{"degree", "i1"} = "J_I1_deg";
    $joints{"preferred", "i2"} = "J_I2_pref";
    $joints{"degree", "i2"} = "J_I2_deg";

    $joints{"preferred", "m0"} = "J_M0_pref";
    $joints{"degree", "m0"} = "J_M0_deg";
    $joints{"preferred", "m1"} = "J_M1_pref";
    $joints{"degree", "m1"} = "J_M1_deg";
    $joints{"preferred", "m2"} = "J_M2_pref";
    $joints{"degree", "m2"} = "J_M2_deg";

    $joints{"preferred", "r0"} = "J_R0_pref";
    $joints{"degree", "r0"} = "J_R0_deg";
    $joints{"preferred", "r1"} = "J_R1_pref";
    $joints{"degree", "r1"} = "J_R1_deg";
    $joints{"preferred", "r2"} = "J_R2_pref";
    $joints{"degree", "r2"} = "J_R2_deg";

    $joints{"preferred", "l0"} = "J_L0_pref";
    $joints{"degree", "l0"} = "J_L0_deg";
    $joints{"preferred", "l1"} = "J_L1_pref";
    $joints{"degree", "l1"} = "J_L1_deg";
    $joints{"preferred", "l2"} = "J_L2_pref";
    $joints{"degree", "l2"} = "J_L2_deg";

    $count = 0;
    foreach $j (@JOINTS)
    {
	$joints{"index", $j} = $count;
	++$count;
    };
};

sub init_pads
{
    local($i);

    for($i = 0; $i <= $#PADS+1; ++$i)
    {
	$pads{"index", $PADS[$i]} = $i;
    };
};

sub init_grasp_types
{
    local($i);
    local($counter) = 0;

    foreach $i (@GRASP_TYPES)
    {
	$grasp{"type index", $i} = $counter;
	++$counter;
    };
};

sub init_data_structures
{
    local($i);

				# Set number of columns in each layer to 0 
    foreach $i (@LAYERS)
    {
	$net{"num", $i} = 0;
    }
    &init_joints();
    &init_pads();
    &init_grasp_types();
};


############################################################

				# Check parameters
if(&interpret_parms() == 0 || $#ARGV == -1 || $ARGV[$#ARGV] =~ /-(\w)(.*)/)
{
    print "Usage: mknet [-]* \n";
    exit;
};
				# Base file name
$base = $ARGV[$#ARGV];

				# Confirm there is a parameter file
$parms_fname = $base . ".parms.pl";
if(! -e $parms_fname)
{
    print "Error: no parameter file found.\n";
    exit;
};

require "$parms_fname";
print "Loaded parms file $parms_fname\n";

				# Log file
$fname = $base . ".mknet.log";

open(LOG_FP, ">$fname") || die "Error opening output file $fname.\n$_";


&init_data_structures();	# Initialize

&parse_input_files($base);	# Get specification files

&compute_all_object_coding();	# Compute representations for all objects

&dump_nsl_objects($base);	# Write out the representations in NSL format

&analyze_f5();			# Compute some useful statistics.


&establish_connections($base);	# Make the connections

&parse_f5_mcx_w($base);		# Add connections from f5->mcx (read from
				#   a file).

&filter_connections;		# Filter out duplicates and zero-valued
				#   connections

&dump_net($base);		# Write the network file to disk

&generate_report($base);	# Write out the final report of what happened.

close LOG_FP;


[ return ]