motMod1.c -- Point to Point trapezoidal profile motion with end point
modification.
/* motMod1.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.
*/
/*
:Point to Point trapezoidal profile motion with end point modification.
This is a simple program to demonstrate how to start a trapezoidal profile
motion on a single axis. During the execution of the motion, the target
position (end point), velocity, accel, decel are modified. The controller
automatically re-calculates the motion profile, using the modified
trajectory parameters.
The mpiMotionModify(...) function modifies a presently executing motion
profile. If mpiMotionModify(...) is called when no motion is executing,
the error code, MPIMotionMessageIDLE will be returned, and no motion
will be commanded. This error code let's the application know that there
was no motion to be modified.
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.
The msgCHECK(...) macros used in the following sample code are intended
to convey our strong belief that ALL error return codes should be checked.
Actual application code should use specific error handling techniques (other
than msgCHECKs) best suited to your internal error recovery methods.
*/
#include <stdlib.h>
#include <stdio.h>
#include "stdmpi.h"
#include "stdmei.h"
#include "apputil.h"
#define MOTION_NUMBER (0)
#define AXIS_NUMBER (0)
/* Motion Start Parameters */
#define TARGET_POSITION (10000.0)
#define VELOCITY (10000.0)
#define ACCELERATION (100000.0)
#define DECELERATION (100000.0)
/* Motion Modify Parameters */
#define MODIFY_POSITION (-1000.0) /* new target position */
#define MODIFY_VELOCITY (5000.0) /* new velocity */
#define MODIFY_ACCELERATION (75000.0) /* new deceleration */
#define MODIFY_DECELERATION (50000.0) /* new deceleration */
#define WAIT_TIME (500) /* delay to modify move, (msec) */
/* 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);
/* Check for unknown/invalid command line arguments */
if (argIndex < argc) {
fprintf(stderr,"usage: %s %s\n", argv[0], ArgUSAGE);
exit(MPIMessageARG_INVALID);
}
}
/* Create and initialize MPI objects */
void programInit(MPIControl *control,
MPIControlType controlType,
MPIControlAddress *controlAddress,
MPIMotion *motion,
long motionNumber,
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);
/* Create axis object */
*axis =
mpiAxisCreate(*control,
axisNumber);
msgCHECK(mpiAxisValidate(*axis));
/* Create motion supervisor object with axis */
*motion =
mpiMotionCreate(*control,
motionNumber, /* motion supervisor number */
*axis); /* axis object handle */
msgCHECK(mpiMotionValidate(*motion));
}
/* Perform certain cleanup actions and delete MPI objects */
void programCleanup(MPIControl *control,
MPIMotion *motion,
MPIAxis *axis)
{
long returnValue;
/* Delete motion supervisor object */
returnValue =
mpiMotionDelete(*motion);
msgCHECK(returnValue);
/* Delete axis object */
returnValue =
mpiAxisDelete(*axis);
msgCHECK(returnValue);
/* Delete motion controller object */
returnValue =
mpiControlDelete(*control);
msgCHECK(returnValue);
}
/* Command simple trapezoidal motion */
long simpleTrapMove(MPIMotion motion,
double goalPosition,
double velocity,
double acceleration,
double deceleration)
{
MPIMotionParams params; /* Motion parameters */
MPITrajectory trajectory; /* Trajectory information */
long returnValue; /* MPI library return value */
/* Setup trajectory structure */
trajectory.velocity = velocity;
trajectory.acceleration = acceleration;
trajectory.deceleration = deceleration;
/* Setup parameters structure */
params.trapezoidal.trajectory = &trajectory;
params.trapezoidal.position = &goalPosition;
/* Start motion */
returnValue =
mpiMotionStart(motion,
MPIMotionTypeTRAPEZOIDAL,
¶ms);
msgCHECK(returnValue);
return returnValue;
}
/* Modify motion with a simple trapezoidal motion profile */
long simpleTrapModify(MPIMotion motion,
double goalPosition,
double velocity,
double acceleration,
double deceleration)
{
MPIMotionParams params; /* Motion parameters */
MPITrajectory trajectory; /* Trajectory information */
long returnValue; /* MPI library return value */
/* Setup trajectory structure */
trajectory.velocity = velocity;
trajectory.acceleration = acceleration;
trajectory.deceleration = deceleration;
/* Setup parameters structure */
params.trapezoidal.trajectory = &trajectory;
params.trapezoidal.position = &goalPosition;
/* Start motion */
returnValue =
mpiMotionModify(motion,
MPIMotionTypeTRAPEZOIDAL,
¶ms);
msgCHECK(returnValue);
return returnValue;
}
int main(int argc,
char *argv[])
{
MPIControl control; /* motion controller object handle */
MPIControlType controlType;
MPIControlAddress controlAddress;
MPIMotion motion; /* motion object handle */
MPIAxis axis; /* axis object handle */
/* Perform basic command line parsing. (-control -server -port -trace) */
basicParsing(argc,
argv,
&controlType,
&controlAddress);
/* Create and initialize MPI objects */
programInit(&control,
controlType,
&controlAddress,
&motion,
MOTION_NUMBER,
&axis,
AXIS_NUMBER);
printf("\nMotionStart...\n");
/* Command simple motion */
simpleTrapMove(motion,
TARGET_POSITION,
VELOCITY,
ACCELERATION,
DECELERATION);
mpiPlatformSleep(WAIT_TIME); /* delay */
printf("\nMotionModify...\n");
/* Modify motion with a simple trapezoidal motion profile */
simpleTrapModify(motion,
MODIFY_POSITION,
MODIFY_VELOCITY,
MODIFY_ACCELERATION,
MODIFY_DECELERATION);
/* Perform certain cleanup actions and delete MPI objects */
programCleanup(&control,
&motion,
&axis);
return MPIMessageOK;
}
|