Example 5 - a gear program, Example 5 - a gear program -15 – Rockwell Automation 2098-IPD-xxx Ultra5000 C Programming using the Motion Library User Manual

Page 27

Advertising
background image

Publication 2098-PM001E-EN-P — July 2002

Programming Motion Control in C

1-15

Example 5 - A Gear Program

#include <motion.h>

#define

ADCCHANNEL

1

/* Analog input chnl 1 */

/* This program uses analog input channel 1 to determine

the gearing ratio. The purpose of comparing the old ratio

to new is to avoid resetting the gear ratio when it has

not changed. */

int main (void)

{

float OldRatio, NewRatio;

InitMotionLibrary();

AxisEnable();

GearEnable();

OldRatio = 0;

while (!StopRequested())

{

NewRatio = AnalogInputGetVoltage(ADCCHANNEL);

if (NewRatio != OldRatio) {

GearSetRatio(NewRatio);

OldRatio = NewRatio;

}

}

GearDisable();

AxisDisable();

return 0;

}

Advertising