ssiEncCfg.c -- Demonstrates SSI encoder configuration for an RMB-10v2
/* ssiEncCfg.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.
*/
/*
:Demonstrates SSI encoder configuration for an RMB-10v2.
This sample program configures the motor's primary encoder for an SSI encoder.
The SSI encoder interface is a clock output with serial data feedback. The
configuration parameters for SSI encoders depend on the manufacturer and
model. Please consult the SSI encoder documentation for details.
This sample program requires an RMB-10v2, with an FPGA image that supports
the SSI encoder interface. The C0FE002C FPGA image supports both incremental
quadrature encoder types and SSI encoder types. Make sure you download the
appropriate FPGA image to your RMB-10v2.
After the SSI encoder is initialized, the motor's feedback position will
be updated automatically by the FPGA and controller's firmware.
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"
#include "..\sqNodeLib\include\mei_rmb.h"
#define MOTOR_NUMBER (0)
#define BAUD_HZ (100000) /* Baud rate in Hz */
#define SSI_INPUT (MPIMotorSsiInputENC_A) /* SSI data input */
#define BIT_COUNT (32) /* SSI encoder data */
#define BROKEN_WIRE_ENABLE (FALSE)
#define PRIMARY_ENCODER (TRUE) /* TRUE = primary, FALSE = secondary */
#define SSI_CLOCK0_OUT (MPIMotorIoConfigIndex0) /* SSI clock output */
/* 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,
MPIMotor *motor,
long motorNumber)
{
long returnValue;
/* Obtain a control handle */
*control =
mpiControlCreate(controlType, controlAddress);
msgCHECK(mpiControlValidate(*control));
/* Initialize the controller */
returnValue =
mpiControlInit(*control);
msgCHECK(returnValue);
*motor =
mpiMotorCreate(*control, motorNumber);
msgCHECK(mpiMotorValidate(*motor));
}
/* Perform certain cleanup actions and delete MPI objects */
void programCleanup(MPIControl *control,
MPIMotor *motor)
{
long returnValue;
/* Delete motor handle */
returnValue =
mpiMotorDelete(*motor);
msgCHECK(returnValue);
*motor = MPIHandleVOID;
/* Delete control handle */
returnValue =
mpiControlDelete(*control);
msgCHECK(returnValue);
*control = MPIHandleVOID;
}
void ssiEncoderInit(MPIControl control,
MPIMotor motor,
long baudRate)
{
MPIMotorConfig motorConfig;
long returnValue;
long encoderIndex;
returnValue =
mpiMotorConfigGet(motor,
NULL,
&motorConfig);
msgCHECK(returnValue);
/* Configure the IO to output the SSI Clock */
motorConfig.Io[SSI_CLOCK0_OUT].Type = MPIMotorIoTypeSSI_CLOCK0;
/* Configre the RMB's feedback type to SSI */
if(PRIMARY_ENCODER) {
encoderIndex = 0;
}
else {
encoderIndex = 1;
}
motorConfig.Encoder[encoderIndex].type = MPIMotorEncoderTypeSSI;
motorConfig.Encoder[encoderIndex].ssiConfig.baudRate = BAUD_HZ;
motorConfig.Encoder[encoderIndex].ssiConfig.bitCount = BIT_COUNT;
motorConfig.Encoder[encoderIndex].ssiConfig.input = SSI_INPUT;
motorConfig.Encoder[encoderIndex].ssiConfig.brokenWireEnable = BROKEN_WIRE_ENABLE;
returnValue =
mpiMotorConfigSet(motor,
NULL,
&motorConfig);
msgCHECK(returnValue);
mpiPlatformConsole("Encoder Configured Successfully\n");
}
int main(int argc,
char *argv[])
{
MPIControl control;
MPIControlType controlType;
MPIControlAddress controlAddress;
MPIMotor motor;
/* Perform basic command line parsing. (-control -server -port -trace) */
basicParsing(argc,
argv,
&controlType,
&controlAddress);
/* Create and initialize MPI objects */
programInit(&control,
controlType,
&controlAddress,
&motor,
MOTOR_NUMBER);
/* Initialize the motor's feedback for an SSI encoder. */
ssiEncoderInit(control,
motor,
BAUD_HZ);
/* Perform certain cleanup actions and delete MPI objects */
programCleanup(&control,
&motor);
return MPIMessageOK;
}
|