MotionController Axis MultiAxis IO IOPoint NetworkNode RsiError
Sample Apps Changelog

RapidCode API

UserLimitGainChangeBasedOnPosition.cpp

User Limit Gain Change Based on Position sample application.

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.

Precondition
This sample code presumes that the user has set the tuning paramters(PID, PIV, etc.) prior to running this program so that the motor can rotate in a stable manner.
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" // Import our RapidCode Library.
#include "HelperFunctions.h" // Import our SampleApp helper functions.
using namespace RSI::RapidCode;
// which axis to use?
const int AXIS_NUMBER = 0;
// which user limit to use?
const int USER_LIMIT = 0;
// which condition to use (0 or 1)
const int CONDITION = 0;
// which gain table
const int GAIN_TABLE = 0;
void UserLimitGainChangeBasedOnPositionMain()
{
//RapidCode interface classes
MotionController *controller;
Axis *axis;
try
{
SampleAppsCPP::HelperFunctions::StartTheNetwork(controller); // [Helper Function] Initialize the network.
// initialize RsiController class
SampleAppsCPP::HelperFunctions::CheckErrors(controller);
// initialize RsiAxis class
Axis *axis = controller->AxisGet(AXIS_NUMBER);
SampleAppsCPP::HelperFunctions::CheckErrors(axis);
// this sample uses Interrupts
controller->InterruptEnableSet(true);
// set the command/actual position to zero
axis->PositionSet(0);
double Axis0TriggerPosition = 7500.0;
double ProportionalGain = axis->FilterCoeffGet(RSIFilterGainPIDCoeffGAIN_PROPORTIONAL, GAIN_TABLE) * 0.65;
// configure user limit to evaluate input bit
controller->UserLimitConditionSet(USER_LIMIT,
CONDITION,
Axis0TriggerPosition);
// configure user limit to set OUTPUT_BIT_MASK high when limit is true
// 64-bit output not supported
//controller->UserLimitOutputSet(USER_LIMIT,
// 0,
// (uint64)*((uint64*)&ProportionalGain),
// (long)axis->AddressGet(RSIAxisAddressType::RSIAxisAddressTypeFILTER_GAIN_KP)
// true);
// set the configuration
axis->MoveVelocity(500, 500);
printf("Waiting for axis0 to reach position specified....\n");
// wait for user limit to trigger
{
}
printf("Axis0 reached specified position. Proportional Gain for axis0 changed!\n");
// disable User Limit
controller->UserLimitDisable(USER_LIMIT);
// stop velocity move
axis->Stop();
}
catch (RsiError const& rsiError)
{
printf("Text: %s\n", rsiError.text);
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
return;
}