.

     

MPI Application Template
template.c
 

ScView.c -- Display commutation parameters
/* ScView.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.
 */


/*

:Display commutation parameters

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"

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

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

    {   NULL,       ArgTypeINVALID, NULL,   }
};

char *modeLabel[] = {
    "MPIXmpCommModeNONE",
    "MPIXmpCommModeCLOSED_LOOP",
    "MPIXmpCommModeOPEN_LOOP",
    "MPIXmpCommModeSIMULATE",
};

int
    main(int    argc,
         char   *argv[])
{
    MPIControl      control;        /* motion controller handle */
    MPIMotor        motor;          /* motor */
    MPIMotorConfig  motorConfig;    /* motor config structure */

    long    returnValue;    /* return value from library */

    MPIControlType      controlType;
    MPIControlAddress   controlAddress;

    long    argIndex;

    /* 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 >= MPIXmpMAX_Motors)) {
        mpiPlatformConsole("usage: %s %s\n"
                           "\t\t[-motor # (0 .. %d)]\n",
                            argv[0],
                            ArgUSAGE,
                            MPIXmpMAX_Motors - 1);
        exit(MPIMessageARG_INVALID);
    }

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

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

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

    returnValue =
        mpiMotorConfigGet(motor,
                          NULL,
                          &motorConfig);
    msgCHECK(returnValue);

    printf("Motor %ld:\n",
            motorNumber);

    printf("\tCommutation Mode = %ld (%s)\n",
            motorConfig.Commutation.Mode,
            modeLabel[motorConfig.Commutation.Mode]);

    printf("\tCommutation Length = %ld\n",
            motorConfig.Commutation.Length);

    printf("\tCommutation Scale = %f\n",
            motorConfig.Commutation.Scale);

    printf("\tCommutation Phase Delta = %ld\n",
            motorConfig.Commutation.PhaseDelta);

    printf("\tCommutation Theta = %ld\n",
            motorConfig.Commutation.Theta);

    if (motorConfig.Commutation.Length != 0) {

        double  phaseAngle;
        long tableIndex;

        tableIndex =
            ((long)(motorConfig.Commutation.Theta *
              motorConfig.Commutation.Scale)) &
             (MPIXmpCOMM_TABLE_SIZE - 1);

        phaseAngle =
             (double)tableIndex * 360.0/
             (double)MPIXmpCOMM_TABLE_SIZE;

        printf("\tPhase angle = %lf degrees\n",
                phaseAngle);
    }

    /* Delete objects */
    returnValue = mpiMotorDelete(motor);
    msgCHECK(returnValue);

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

    return ((int)returnValue);
}


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