.

     

MPI Application Template
template.c
 

motionCam.c -- Perform a single shot cam motion.
/* motionCam.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.
 */

/*

:Perform a single shot cam motion.

This is a simple program to demonstrate how to execute a cammed motion.
The following axis is defined by AXIS_NUMBER_SLAVE, the master axis by 
AXIS_NUMBER_MASTER.  After the program is executed, command a motion
on the master axis with another program, or with Motion Console.  


Warning!  This is a sample program to assist in the longegration 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 <math.h>
#include "stdmpi.h"
#include "stdmei.h"
#include "apputil.h"

#define MOTION_NUMBER_SLAVE      (0)
#define AXIS_NUMBER_SLAVE     (0)
#define AXIS_NUMBER_MASTER    (1)

/* 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);
    }
}


/* Create and initialize MPI objects */
void programInit(MPIControl         *control,
                 MPIControlType      controlType,
                 MPIControlAddress  *controlAddress,
                 MPIMotion          *motionSlave,
                 long                motionNumberSlave,
                 MPIAxis            *axisSlave,
                 long                axisNumberSlave)
{
    long            returnValue;

    /* Create motion controller object */
    *control =
        mpiControlCreate(controlType,
                         controlAddress);

    returnValue = mpiControlValidate(*control);
   msgCHECK(returnValue);

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

    /* Create axis object */
    *axisSlave =
        mpiAxisCreate(*control,
                      axisNumberSlave);

    returnValue = mpiAxisValidate(*axisSlave);
   msgCHECK(returnValue);

    /* Create motion supervisor object with axis */
    *motionSlave =
        mpiMotionCreate(*control,
                        motionNumberSlave,       /* motion supervisor number */
                        *axisSlave);             /* axis object handle */

    returnValue = mpiMotionValidate(*motionSlave);
   msgCHECK(returnValue);
}


/* Perform certain cleanup actions and delete MPI objects */
void programCleanup(MPIControl      *control,
                    MPIMotion       *motionSlave,
                    MPIAxis         *axisSlave)
{
    long    returnValue;


    /* Delete motion supervisor object */
    returnValue =
        mpiMotionDelete(*motionSlave);
    msgCHECK(returnValue);

    /* Delete axis object */
    returnValue =
        mpiAxisDelete(*axisSlave);
    msgCHECK(returnValue);

   /* Delete motion controller object */
    returnValue =
        mpiControlDelete(*control);
    msgCHECK(returnValue);
}


/* Command a simple single shot cam. */
long simpleCamMove(MPIMotion  motion,
                    MPIAxis      axis,
               long     axisNumberMaster)
{
   long           returnValue;   /* MPI library return value */

   MPIMotionParams      motionParams;
   MPIAxisConfig     mpiAxisConfig;

   double masterDistances[] = { 50,  100, 50,  50,  50 };
   double slavePositions1[] = { 200, 200, 100, 100, 0 };
   double * slavePositions[] = { slavePositions1 };

   /* Select the Master Position Source */
   returnValue = mpiAxisConfigGet( axis, &mpiAxisConfig, NULL );
   msgCHECK(returnValue);

   mpiAxisConfig.master.type   = MPIAxisMasterTypeAXIS_ACTUAL_POSITION;
   mpiAxisConfig.master.number = axisNumberMaster;

   returnValue = mpiAxisConfigSet( axis, &mpiAxisConfig, NULL );
   msgCHECK(returnValue);

   /* Start the slaves cam motion. */
   motionParams.cam.pointCount = 5;
   motionParams.cam.slavePosition = slavePositions;
   motionParams.cam.masterDistance = masterDistances;

   returnValue = mpiMotionStart( motion, MPIMotionTypeCAM_LINEAR, &motionParams );
   msgCHECK(returnValue);

   return returnValue;
}


int main(int    argc,
         char   *argv[])
{
    MPIControl          control;    /* motion controller object handle */
    MPIControlType      controlType;
    MPIControlAddress   controlAddress;
    MPIMotion           motionSlave;     /* motion object handle */
    MPIAxis             axisSlave;       /* axis object handle */

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

    /* Create and initialize MPI objects */
    programInit(&control,
                controlType,
                &controlAddress,
                &motionSlave,
                MOTION_NUMBER_SLAVE,
                &axisSlave,
                AXIS_NUMBER_SLAVE);

    /* Command simple motion */
    simpleCamMove(motionSlave,
                   axisSlave,
               AXIS_NUMBER_MASTER);

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

    return MPIMessageOK;
}


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