gear.c -- Configure an axis' commanded position to be geared off
of another axis
/* gear.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 an axis' commanded position to be geared off of another axis
Axis gearing on the XMP is based off of a pointer, numerator, and denominator.
The pointer points to a source to gear off of. The ratio betweent the lead
and follower axes is set by a ratio of two longs -- a numerator and a
denominator. For example:
Ratio Numerator Denominator
1 1 1
2 2 1
.5 1 2
.1 1 10
10 10 1
The pointer can point to any long in the XMP's memory space. The pointer
method shown in setCommandGear() does not work over TCP/IP.
Warning! This is a sample program to assist in the integration of the
XMP motion controller with your application. It may not contain all
of the logic and safety features that your application requires.
*/
#include <stdio.h>
#include <stdlib.h>
#include "stdmpi.h"
#include "stdmei.h"
#include "apputil.h"
long AxisNumber = 0;
long GearedAxis = 1;
long Numerator = 1;
long Denominator = 1;
Arg argList[] = {
{ "-axisNum", ArgTypeLONG, &AxisNumber, },
{ "-gearedNum", ArgTypeLONG, &GearedAxis, },
{ "-num", ArgTypeLONG, &Numerator, },
{ "-den", ArgTypeLONG, &Denominator, },
{ NULL, ArgTypeINVALID, NULL, }
};
/* 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);
/* 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) || (AxisNumber < 0) || (AxisNumber >= MEIXmpMAX_Motors) ||
(GearedAxis < 0) || (GearedAxis > MEIXmpMAX_Axes - 1) ||
(Denominator == 0))
{
printf("usage: %s %s\n"
"\t\t[-axisNum #(0-%d)]\n"
"\t\t[-gearedNum #(0-%d)]\n"
"\t\t[-num #]\n"
"\t\t[-den # (!=0)]\n",
argv[0],
ArgUSAGE,
MEIXmpMAX_Motors-1,
MEIXmpMAX_Motors-1);
exit(MPIMessageARG_INVALID);
}
}
/* Create and initialize MPI objects */
void programInit(MPIControl *control,
MPIControlType controlType,
MPIControlAddress *controlAddress,
MPIAxis *axis,
long axisNumber)
{
long returnValue;
/* Create motion controller object */
*control =
mpiControlCreate(controlType,
controlAddress);
msgCHECK(mpiControlValidate(*control));
/* Initialize motion controller */
returnValue =
mpiControlInit(*control);
msgCHECK(returnValue);
*axis = mpiAxisCreate(*control, axisNumber);
msgCHECK(mpiAxisValidate(*axis));
}
/* Perform certain cleanup actions and delete MPI objects */
void programCleanup(MPIControl control,
MPIAxis axis)
{
long returnValue;
/* Delete motion controller object */
returnValue =
mpiAxisDelete(axis);
msgCHECK(returnValue);
returnValue =
mpiControlDelete(control);
msgCHECK(returnValue);
}
long setCommandGear(MPIAxis axis,
long gearedAxis,
long numerator,
long denominator)
{
MPIAxisConfig config;
MEIAxisConfig config2;
MPIControl control;
MEIXmpData *firmware; /* pointer to XMP firmware */
MEIPlatform platform;
long returnValue;
void *ptr;
control = mpiAxisControl(axis);
platform = meiControlPlatform(control);
returnValue = meiPlatformValidate(platform);
if(returnValue) return returnValue;
/* Get pointer to XMP firmware */
returnValue =
mpiControlMemory(control,
(void**)&firmware,
NULL);
if(returnValue) return returnValue;
returnValue = mpiAxisConfigGet(axis, &config, &config2);
if(returnValue) return returnValue;
config2.Gear.Ptr = &firmware->Motor[gearedAxis].IO.Encoder[0].Delta;
config2.Gear.Ratio.A = numerator;
config2.Gear.Ratio.B = denominator;
returnValue = mpiAxisConfigSet(axis, &config, &config2);
if(returnValue) return returnValue;
return returnValue;
}
void main(int argc, char *argv[])
{
MPIControl control;
MPIControlType controlType;
MPIControlAddress controlAddress;
MPIAxis axis;
long returnValue;
/* Perform basic command line parsing. (-control -server -port -trace) */
basicParsing(argc,
argv,
&controlType,
&controlAddress);
/* Create and initialize MPI objects */
programInit(&control,
controlType,
&controlAddress,
&axis,
AxisNumber);
returnValue = setCommandGear(axis, GearedAxis, Numerator, Denominator);
msgCHECK(returnValue);
programCleanup(control,
axis);
}
|