.

     

MPI Application Template
template.c
 

comp.c -- Configure Axis Compensation Tables
/* comp.c */

/* Copyright(c) 1991-2006 by Motion Engineering, Inc.  All rights reserved.
 *
 * This software  contains proprietary and  confidential information  of
 * Motion Engineering Inc., and its suppliers.  Except as may be set forth
 * in the license agreement under which  this software is supplied, use,
 * disclosure, or  reproduction is prohibited without the prior express
 * written consent of Motion Engineering, Inc.
 */

/*

:Configure a 2D Axis Compensation Table

configures controller compensation table, creates compensator object, 
configures for 2-dimension compensation and loads the compensation table 
using a statically defined compensation table.  The table is then read 
back and displayed to stdout.

Warning!  This is a sample program to assist in the integration of an
 MEI motion controller with your application.  It may not contain all
 of the logic and safety features that your application requires.

The msgCHECK(...) macros used in the following sample code are intended
 to convey our strong belief that ALL error return codes should be checked.
 Actual application code should use specific error handling techniques (other
 than msgCHECKs) best suited to your internal error recovery methods.

*/

#include <stdlib.h>
#include <stdio.h>

#include "stdmpi.h"
#include "stdmei.h"

#include "apputil.h"

#define COMPENSATOR_NUMBER    (0)
#define COMPENSATOR_DIMENSION (2)

#define AXIS_X_NUMBER      (1)
#define AXIS_X_RANGE_START (0)
#define AXIS_X_RANGE_END   (200000)
#define AXIS_X_POINT_DELTA (50000)

#define AXIS_Y_NUMBER      (0)
#define AXIS_Y_RANGE_START (25000)
#define AXIS_Y_RANGE_END   (225000)
#define AXIS_Y_POINT_DELTA (10000)

#define AXIS_Z_NUMBER      (2)

#define X_DIM ((long)(AXIS_X_RANGE_END-AXIS_X_RANGE_START)/AXIS_X_POINT_DELTA + 1)
#define Y_DIM ((long)(AXIS_Y_RANGE_END-AXIS_Y_RANGE_START)/AXIS_Y_POINT_DELTA + 1)

long compensatorTable[Y_DIM][X_DIM] =
{
   {  0,    0,    0,    0,    0, },
   {  100,  200,  -200, -100, 0, },
   {  200,  400,  -400, -200, 0  },
   {  300,  600,  -600, -300, 0  },
   {  400,  800,  -800, -400, 0  },
   {  500,  1000, -1000,   -500, 0  },
   {  600,  1200, -1200,   -600, 0  },
   {  700,  1400, -1400,   -700, 0  },
   {  800,  1600, -1600,   -800, 0  },
   {  900,  1800, -1800,   -900, 0  },
   {  1000, 2000, -2000,   -1000,   0  },
   {  900,  1800, -1800,   -900, 0  },
   {  800,  1600, -1600,   -800, 0  },
   {  700,  1400, -1400,   -700, 0  },
   {  600,  1200, -1200,   -600, 0  },
   {  500,  1000, -1000,   -500, 0  },
   {  400,  800,  -800, -400, 0  },
   {  300,  600,  -600, -300, 0  },
   {  200,  400,  -400, -200, 0  },
   {  100,  200,  -200, -100, 0  },
   {  0,    0,    0,    0,    0  },
};


/* Perform basic command line parsing. (-control -server -port -trace) */
void basicParsing(int                    argc,
                  char                  *argv[],
                  MPIControlType        *controlType,
                  MPIControlAddress     *controlAddress)
{
    long argIndex;

    /* Parse command line for Control type and address */
    argIndex = argControl(argc, argv, controlType, controlAddress);

    /* Check for unknown/invalid command line arguments */
    if (argIndex < argc) {
        fprintf(stderr,"usage: %s %s\n", argv[0], ArgUSAGE);
        exit(MPIMessageARG_INVALID);
    }
}

void compensatorTableConfigure(MPIControl control)
{
    MPIControlConfig config;

   long returnValue;

   returnValue =
      mpiControlConfigGet(control,
                     &config,
                     NULL);
   msgCHECK(returnValue);

   /* configure first compensator table size so our 2D array will fit */
   config.compensatorCount = 1;
   config.compensatorPointCount[0] = Y_DIM * X_DIM;

   /* 
     * WARNING: this is a low-level configuration that will 
    * reinitialize the controller's dynamic memory buffers! 
    * Only preform this operation at system initialization.
    */
   returnValue =
      mpiControlConfigSet(control,
                     &config,
                     NULL);
   msgCHECK(returnValue);
}

/* Create and initialize MPI objects */
void programInit(MPIControl         *control,
                 MPIControlType      controlType,
                 MPIControlAddress  *controlAddress,
             MPICompensator      *compensator,
             long          compensatorNumber)
{
    long    returnValue;

    /* Obtain a control handle */
    *control =
        mpiControlCreate(controlType, controlAddress);
    msgCHECK(mpiControlValidate(*control));

    /* Initialize the controller */
    returnValue =
        mpiControlInit(*control);
    msgCHECK(returnValue);

   compensatorTableConfigure(*control);

   /* create a compensator object */
   *compensator =
      mpiCompensatorCreate(*control, compensatorNumber);
   msgCHECK(mpiCompensatorValidate(*compensator));
}

/* Perform certain cleanup actions and delete MPI objects */
void programCleanup(MPIControl     *control,
               MPICompensator *compensator)
{
    long    returnValue;

   /* Delete compensator handle */
    returnValue =
        mpiCompensatorDelete(*compensator);
    msgCHECK(returnValue);

    /* Delete control handle */
    returnValue =
        mpiControlDelete(*control);
    msgCHECK(returnValue);

    *control = MPIHandleVOID;
}

void compensatorConfigure(MPICompensator compensator)
{
    MPICompensatorConfig config;
   long returnValue;

   returnValue =
      mpiCompensatorConfigGet(compensator,
                        &config,
                        NULL);
   msgCHECK(returnValue);

   config.dimensionCount = COMPENSATOR_DIMENSION;

   /* configure first compensating (input) axis */
   config.inputAxis[0].axisNumber        = AXIS_X_NUMBER;
   config.inputAxis[0].range.positionMin = AXIS_X_RANGE_START;
   config.inputAxis[0].range.positionMax = AXIS_X_RANGE_END;
   config.inputAxis[0].positionDelta     = AXIS_X_POINT_DELTA;

   /* configure second compensating (input) axis */
   config.inputAxis[1].axisNumber        = AXIS_Y_NUMBER;
   config.inputAxis[1].range.positionMin = AXIS_Y_RANGE_START;
   config.inputAxis[1].range.positionMax = AXIS_Y_RANGE_END;
   config.inputAxis[1].positionDelta     = AXIS_Y_POINT_DELTA;

   /* configure compensated (out) axis */
   config.outputAxisNumber = AXIS_Z_NUMBER;

   returnValue =
      mpiCompensatorConfigSet(compensator,
                        &config,
                        NULL);
   msgCHECK(returnValue);
}

void compensatorLoad(MPICompensator compensator)
{
   long returnValue;

   returnValue =
      mpiCompensatorTableSet(compensator,
                        (long*)compensatorTable);
   msgCHECK(returnValue);
}

void compensatorDisplay(MPICompensator compensator)
{
   long table[Y_DIM][X_DIM];
   long x, y;
   long returnValue;

   returnValue =
      mpiCompensatorTableGet(compensator,
                        (long*)table);
   msgCHECK(returnValue);

   for (y=0; y<Y_DIM; y++) {
      printf("{  ");
      for (x=0; x<X_DIM; x++) {
         printf("%5.1d,\t", table[y][x]);
      }
      printf("},\n");
   }
}

int main(int     argc,
         char   *argv[])
{
    MPIControl          control;
    MPIControlType      controlType;
    MPIControlAddress   controlAddress;

   MPICompensator    compensator;

    /* Perform basic command line parsing. (-control -server -port -trace) */
    basicParsing(argc,
                 argv,
                 &controlType,
                 &controlAddress);

    /* Create and initialize MPI objects */
    programInit(&control,
                controlType,
                &controlAddress,
            &compensator,
            COMPENSATOR_NUMBER);

    compensatorConfigure(compensator);

    compensatorLoad(compensator);

   compensatorDisplay(compensator);

    /* Perform certain cleanup actions and delete MPI objects */
    programCleanup(&control, &compensator);

    return MPIMessageOK;
}


      
       Legal Notice  |  Tech Email  |  Feedback
      
Copyright ©
2001-2009 Motion Engineering