.

     

MPI Application Template
template.c
 

stoprate.c -- Set deceleration rate for MPIActionSTOP and MPIActionE_STOP.
/* stoprate.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.
 */

/*

:Set deceleration rate for MPIActionSTOP and MPIActionE_STOP.

This sample code demonstrates how to configure the MPIActionSTOP and
MPIActionE_STOP deceleration rates for a given Motion objectr.  Unless
specified at the command line, the DEFAULT deceleration rates will be used.

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.

*/

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

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

#include "apputil.h"

#if defined(ARG_MAIN_RENAME)
#define main    stoprateMain

argMainRENAME(main, stoprate)
#endif

/* Define STOP and ESTOP rates in seconds */
#define STOP_RATE_DEFAULT   ((float)3.0)
#define ESTOP_RATE_DEFAULT  ((float)1.0)

/* Command line arguments and defaults */
long    motionNumber    = 0;
float   stopRate        = STOP_RATE_DEFAULT;
float   eStopRate       = ESTOP_RATE_DEFAULT;

Arg argList[] = {
    {   "-motion",  ArgTypeLONG,    &motionNumber,  },
    {   "-stop",    ArgTypeFLOAT,   &stopRate,      },
    {   "-estop",   ArgTypeFLOAT,   &eStopRate,     },

    {   NULL,       ArgTypeINVALID, NULL,   }
};

int
    main(int    argc,
         char   *argv[])
{

    MPIControl  control;        /* Motion controller handle */
    MPIMotion   motion;         /* Motion supervisor handle */

    MPIMotionConfig     motionConfig;   /* Motion supervisor configuration */

    long    returnValue;            /* Return value from library */

    MPIControlType      controlType;
    MPIControlAddress   controlAddress;

    long    argIndex;

    argIndex =
        argControl(argc,
                   argv,
                   &controlType,
                   &controlAddress);

    /* Parse command line for application-specific arguments */
    while (argIndex < argc) {
        long    argIndexNew;

        argIndexNew = argSet(argList, argIndex, argc, argv);

        if (argIndexNew <= argIndex) {
            argIndex = argIndexNew;
            break;
        }
        else {
            argIndex = argIndexNew;
        }
    }

    /* Check for unknown/invalid command line arguments */
    if ((argIndex < argc) ||
        (motionNumber >= MPIXmpMAX_MSs)) {
        mpiPlatformConsole("usage: %s %s\n"
                           "\t\t[-motion # (0 .. %d)]\n"
                           "\t\t[-stop (%f)]\n"
                           "\t\t[-estop (%f)]\n",
                           argv[0],
                           ArgUSAGE,
                           MPIXmpMAX_MSs - 1,
                           STOP_RATE_DEFAULT,
                           ESTOP_RATE_DEFAULT);
        exit(MPIMessageARG_INVALID);
    }

    /* Create controller object */
    control =
        mpiControlCreate(controlType,
                         &controlAddress);
    msgCHECK(mpiControlValidate(control));

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

    /* Create motion object */
    motion =
        mpiMotionCreate(control,
                        motionNumber,
                        MPIHandleVOID);
    msgCHECK(mpiMotionValidate(motion));

    /* Read current motion supervisor configuration */
    returnValue =
        mpiMotionConfigGet(motion,
                           &motionConfig,
                           NULL);
    msgCHECK(returnValue);

    printf("OLD: motion %d: stopRate %f eStopRate %f\n",
            motionNumber,
            motionConfig.decelTime.stop,
            motionConfig.decelTime.eStop);

    /* Set new STOP and E_STOP deceleration rates */
    motionConfig.decelTime.stop  = stopRate;
    motionConfig.decelTime.eStop = eStopRate;

    returnValue =
        mpiMotionConfigSet(motion,
                           &motionConfig,
                           NULL);
    msgCHECK(returnValue);

    printf("NEW: motion %d: stopRate %f eStopRate %f\n",
            motionNumber,
            stopRate,
            eStopRate);

    /* Delete objects */

    returnValue = mpiMotionDelete(motion);
    msgCHECK(returnValue);

    returnValue = mpiControlDelete(control);
    msgCHECK(returnValue);

    return ((int)returnValue);
}


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