The entire simulation program has been broken into a large number of modules. Each of these modules has a set of basic functions to perform. The modules must communicate with the other modules as well. This communication has been simplified by globalizing a number of basic definitions. These definitions include global constants, variables, and functions.
All of these definitions have been placed in a single include file, which will be included at the top of the main program. Thus, these definitions will be global to all other modules.
There are a number of functions which are to be used globally. The neural network subroutines are incorporated as part of the global definition, so that they may be used by any program module. Some function names have been defined in this block, for global functions which exist in the modules (C++ would be nice for this). These functions are defined this way to allow complete sharing between modules, while still allowing the functions to be stored in separate modules. The modules which have their function names in this block are the endpoint buffer management functions, the algorithmic path planning functions, and the neural network path planning functions. The user interface subroutines will be defined at the user interface level. (Note: this is clarified in the user interface program description)
There are a number of global variables defined. These variables define file names, default values, work variables, and miscellaneous option flags. A number of ‘flags’ are defined globally so that they may be used to pass options between the program modules. A set of labelled constants are also defined to ease the assignment of flags. This means that the program will specify ‘elbow = ELBOW_UP’ instead of ‘elbow = 1’. This makes the code much easier to read, and write.
A data structure is defined which will be used through most of the path planning subroutines. This structure will allow trajectories to be stored. Paths may be stored as sequential lists of trajectories. This structure keeps position, velocity, acceleration and torque. As well, it also records output errors for neural networks, and will maintain coordinates in joint and cartesian space. This structure is very memory intensive, but can store path planner output, as well as neural network training sets in the same file.
The definition file follows, and is commented. These comments will be of use for general understanding. The actual use of the definitions will become clear as the other program modules are examined, in the subsequent Appendices.
* ROBOT TRAJECTORY GENERAL DEFINITIONS PROGRAM
* This code is intended to provide general definitions used by all modules
* of this program. These definitions include constants, variables, and
#include "/usr/people/hugh/neural/netter.c" /* Neural Network Subroutines */
#define NEW 2 /* Internal Control codes */
#define CASE_1 1 /* Motion Planning Algorithm Types */
#define MEAN_ERROR 0 /* Different types of Control Output */
#define T_POSITION 5 /* Different Graphs Available */
#define ELBOW_UP 1 /* Internal flags for elbow up/down */
#define JOINT_1 1 /* Internal flags for data to plot */
#define LEN_1 0.5 /* Physical parameters for robot */
#define LEN_2 0.5 /* including joint lengths, mass etc.*/
#define LENGTH_1 100 /* Robot Link lengths in pixels */
#define VMAX_T1 10.0 /* Maximum actuator values, assuming */
#define VMAX_T2 10.0 /* Symmetry for negative and positive */
#define AMAX_T1 10.0 /* values, these are typically used */
#define AMAX_T2 10.0 /* in combinations */
double T_STEP = .5; /* Default Controller Time step */
#define PI 3.141592654 /* Obvious */
#define BUFFER_SIZE 150 /* Size of the buffer of endpoints */
#define TRAIN_SET 1200 /* training set size */
void b_delete(), /* These are the functions contained in */
b_down(), /* the include file "rt_fun.c" */
void nt_trajectory(), /* These are the functions cont- */
nt_save(), /* ained in the include file */
typedef struct { /* This structure may be used to */
double t1_start; /* describe path end_points */
typedef struct { /* This structure is intended for */
double x_target; /* description of paths, based upon */
double y_target; /* trajectories */
double t2_error; } train_data;
typedef struct { /* A description for joint config */
double theta_2; } joint_coordinates;
trajectory buffer[BUFFER_SIZE], /* Stores Path Endpoints */
current; /* Keeps current endpoints */
train_data t_set[TRAIN_SET+1]; /* Keeps data for path training */
int buffer_point = 0, /* Points to current line in buffer[] */
end_of_buffer = 0, /* Points to end of data in buffer[] */
batch_mode = 0, /* Can quit prints, if a batch job */
x_y_flag = 0, /* Will flag joint or cart on screen */
end_train = 0, /* Indicates end of data in t_set[] */
trace_flag = 0, /* Flag for path trace just done */
n_width = 20, /* Default network width */
n_layers = 3, /* Default network layers */
n_iterations = 100, /* Default training iterations */
n_type = SIGMOID, /* Network starts with sigmoid activ. */
n_output = POSITION, /* Network output is position */
n_bias = 0, /* No bias applied to neurons */
n_position = 0, /* No position input to network */
n_velocity = 0, /* No velocity input to network */
n_acceleration = 0, /* No acceleration input to network */
n_target = 0, /* No target input to network */
n_difference = 0, /* No difference error input to net */
n_torque = 0, /* No torque input to network */
t_number = CASE_1, /* Tajectory planner is max velocity */
train_up = 0, /* Disable joint limits of arm */
train_alt = 0, /* Will train without path reversal */
train_opt = 0, /* Will train with optimal path */
train_flag = 0, /* Will be set when net is training */ train_sim = 0, /* Will be set when joints finish simul.*/
test_flag = 0, /* Set when test network steady state */
net_loaded_flag = 0, /* Set when a network is loaded */
elbow_flag = 0, /* Will indicate elbow up/down */
joints_plot = JOINT_1, /* Will plot joint # 1 */
data_plot = POSITION; /* Will plot position of joints */
char file[100] = {"test.net"}, /* default network file */
b_file[100] = {"test.rt"}, /* default trajectory file */
dater_file[100] = {"test.data"},/* data dump file */
run_title[100] = {"Neural Network Test Algorithm\000"},
str_1[100] = {"20"}, /* Net width string */
str_2[100] = {"3"}, /* Net layers string */
str_3[100] = {"100"}, /* Training iter. string */
str_4[100] = {"0.8"}, /* Learning Rate string */
str_5[100] = {"0.8"}, /* Smoothing rate string */
str_6[100] = {"test.train"}, /* Default training set file */
str_7[100] = {"0.5"}; /* Time step default time */
double theta1= 90.0, /* Start angles for manipulator */
x_global, /* x & y position of end effector */
net_average_error, /* Variables for keeping statistics */
net_deviation, /* of current data errors */
n_smooth = 0.8, /* smoothing rate for training */
n_learn = 0.8; /* learning rate for training */
double in1_1[TRAIN_SET], in2_1[TRAIN_SET], /* memory for training */
in1_2[TRAIN_SET], in2_2[TRAIN_SET],
in1_3[TRAIN_SET], in2_3[TRAIN_SET],