.

     

MPI Application Template
template.c
 

motorfbak.c -- Read the primary and secondary feedback for a motor
/* motorfbak.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.
 */

/*

:Read the primary and secondary feedback for a motor.

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    motorfbakMain

argMainRENAME(main, motorfbak)
#endif

/* Command line arguments and defaults */
long  motorNumber     = 0;

Arg argList[] = {
    {   "-motor",   ArgTypeLONG,    &motorNumber,   },
    {   NULL,       ArgTypeINVALID, NULL,   }
};

int
    main(int    argc,
         char   *argv[])
{
    MPIControl       control;    /* motion controller handle */
    MPIMotor         motor;      /* motor handle(s) */
   MPIMotorFeedback  feedback;

   MPIControlType      controlType;
    MPIControlAddress   controlAddress;

   long  argIndex;
    long    returnValue;    /* return value from library */

    /* Parse command line for Control type and address */
    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) ||
        (motorNumber >= MEIXmpMAX_Motors)) {
        meiPlatformConsole("usage: %s %s\n"
                           "\t\t[-motor # (0 .. %d)]\n",
                            argv[0],
                            ArgUSAGE,
                            MEIXmpMAX_Motors - 1);
        exit(MPIMessageARG_INVALID);
    }

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

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

    /* Create motor object using motorNumber on controller */
    motor =
        mpiMotorCreate(control,
                       motorNumber);
    msgCHECK(mpiMotorValidate(motor));

    meiPlatformConsole("(Press any key to quit)\nMotor %ld \n", motorNumber);

    while (meiPlatformKey(MPIWaitPOLL) <= 0) {
      /* Read the motor's feedback */
      returnValue =
         mpiMotorFeedback(motor,
                      &feedback);
      msgCHECK(returnValue);

      meiPlatformConsole("\rPrimary: %12.0lf Secondary: %12.0lf",
                     feedback[MPIMotorEncoderPRIMARY],
                     feedback[MPIMotorEncoderSECONDARY]);
    }
   meiPlatformConsole("\n");

    returnValue = mpiMotorDelete(motor);
    msgCHECK(returnValue);

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

    return ((int)returnValue);
}


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