/* usrlim1.cpp Copyright(c) 1998-2009 by Robotic Systems Integration, Inc. All rights reserved. This software contains proprietary and confidential information of Robotic Systems Integration, Inc. (RSI) and its suppliers. Except as may be set forth in the license agreement under which this software is supplied, disclosure, reproduction, or use with controls other than those provided by RSI or suppliers for RSI is strictly prohibited without the prior express written consent of Robotic Systems Integration. This sample code shows how to configure the XMP controller's User Limits to compare an input bit to a specific pattern. If the pattern matches, then the specified output bit is activated and a User Event is generated to the host. In this case User Limit is created to keep track of the axis Actual Position and when position reaches 7500 counts, the Proportional Gain (Kp) changes to 0.75 times the current value. For any questions regarding this sample code please visit our documentation at www.roboticsys.com Warning! This is a sample program to assist in the integration of your motion controller with your application. It may not contain all of the logic and safety features that your application requires. */ #include "rsi.h" using namespace RSI::RapidCode::SynqNet; //which controller to use? (0 is first PCI controller) #define CONTROLLER_NUMBER 0 // which axis to use? #define AXIS_NUMBER 0 // which user limit to use? #define USER_LIMIT RSIEventTypeLIMIT_USER0 // which condition to use (0 or 1) #define CONDITION 0 // which gain table #define GAIN_TABLE 0 void userLimitGainChangeBasedOnPositionMain() { //RapidCode interface classes MotionController *controller ; Axis *axis ; try { // initialize RsiController class controller = MotionController::CreateFromBoard(CONTROLLER_NUMBER); // initialize RsiAxis class axis = controller->AxisGet(AXIS_NUMBER); // this sample uses Interrupts axis->InterruptEnableSet(true); // set the command/actual position to zero axis->PositionSet(0); long Axis0TriggerPosition = 7500; float ProportionalGain = axis->FilterCoeffGet(RSIFilterGainPIDCoeffGAIN_PROPORTIONAL , GAIN_TABLE) * 0.65; // configure user limit to evaluate input bit axis->UserLimitConditionSet(USER_LIMIT, CONDITION, RSIXmpLimitTypeGT, (long)axis->AddressGet(RSIAxisAddressTypeACTUAL_POSITION), 0xFFFFFFFF, Axis0TriggerPosition); // configure user limit to set OUTPUT_BIT_MASK high when limit is true axis->UserLimitOutputSet(USER_LIMIT, 0, (long)*((long*)&ProportionalGain), (long)&(controller->meiXmpData->ControlLaw.Standard.Coeff0[GAIN_TABLE].f[0]), true); // enable the user limit axis->UserLimitConfigSet(USER_LIMIT, RSIXmpStatusLIMIT, RSIXmpLogicSINGLE , 0.0); axis->MoveVelocity(500, 500); printf("Waiting for axis0 to reach position specified....\n"); // wait for user limit to trigger while(axis->InterruptWait(RSIWaitFOREVER) != USER_LIMIT) { } printf("Axis0 reached specified position. Proportional Gain for axis0 changed!\n"); // disable User Limit axis->UserLimitConfigSet(RSIEventTypeLIMIT_USER0, RSIXmpStatusLIMIT, RSIXmpLogicNEVER , 0.0); } catch (RsiError *rsiError) { printf("Text: %s\n", rsiError->text); } return ; }