ScClose.c -- Transition control from open-loop to closed-loop mode.
/* ScClose.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.
*/
/*
:Transition control from open-loop to closed-loop mode.
On all motors specified by MOTOR_COUNT
and set origin on axes specified by AXIS_COUNT (note - assumes a linear
map of motors and axes).
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 axisNumber = 0;
long motorNumber = 0;
void SetPositionZero(MPIAxis axis);
Arg argList[] = {
{ "-axis", ArgTypeLONG, &axisNumber, },
{ "-motor", ArgTypeLONG, &motorNumber, },
{ NULL, ArgTypeINVALID, NULL, }
};
int
main(int argc,
char *argv[])
{
MPIControl control;/* motion controller handle */
MPIControlType controlType;
MPIControlAddress controlAddress;
MPIAxis axis; /* axis handle */
MPIMotor motor; /* motor handle */
MPIMotorConfig motorConfigXmp;
long returnValue;
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 >= MPIXmpMAX_Axes) ||
(motorNumber >= MPIXmpMAX_Motors)) {
mpiPlatformConsole("usage: %s %s\n"
"\t\t[-axis # (0 .. %d)]\n"
"\t\t[-motion # (0 .. %d)]\n",
argv[0],
ArgUSAGE,
MPIXmpMAX_Axes - 1,
MPIXmpMAX_Motors - 1);
exit(MPIMessageARG_INVALID);
}
printf("Going to closed loop (zeroing position) ...");
/* Create device driver motion controller object */
control =
mpiControlCreate(controlType,
&controlAddress);
msgCHECK(mpiControlValidate(control));
/* Initialize motion controller */
returnValue = mpiControlInit(control);
msgCHECK(returnValue);
/* Create axis objects and zero position */
axis =
mpiAxisCreate(control,
axisNumber);
msgCHECK(mpiAxisValidate(axis));
SetPositionZero(axis);
/* Create motor objects and transition to closed-loop control */
motor =
mpiMotorCreate(control,
motorNumber);
msgCHECK(mpiMotorValidate(motor));
returnValue =
mpiMotorConfigGet(motor,
NULL,
&motorConfigXmp);
msgCHECK(returnValue);
motorConfigXmp.Commutation.Mode = MPIXmpCommModeCLOSED_LOOP;
returnValue =
mpiMotorConfigSet(motor,
NULL,
&motorConfigXmp);
msgCHECK(returnValue);
/* Delete objects */
returnValue = mpiMotorDelete(motor);
msgCHECK(returnValue);
returnValue = mpiAxisDelete(axis);
msgCHECK(returnValue);
returnValue = mpiControlDelete(control);
mpiAssert(returnValue == MPIMessageOK);
return ((int)returnValue);
}
void SetPositionZero(MPIAxis axis)
{
double actualPosition;
double origin;
long returnValue;
returnValue =
mpiAxisActualPositionGet(axis,
&actualPosition);
mpiAssert(returnValue == MPIMessageOK);
returnValue =
mpiAxisOriginGet(axis,
&origin);
mpiAssert(returnValue == MPIMessageOK);
actualPosition += origin;
returnValue =
mpiAxisOriginSet(axis,
actualPosition);
mpiAssert(returnValue == MPIMessageOK);
mpiPlatformSleep(15);
actualPosition = 0;
returnValue =
mpiAxisCommandPositionSet(axis,
actualPosition);
mpiAssert(returnValue == MPIMessageOK);
mpiPlatformSleep(15);
};
|