MotionController Axis MultiAxis IO IOPoint NetworkNode RsiError
Sample Apps Changelog

RapidCode API

AxisStatus.cpp

Axis Status sample application.

Learn how to use:
1) axis->StateGet
2) axis->SourceGet
3) axis->SourceNameGet
4) axis->StatusBitGet

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.
#include <string>
using namespace RSI::RapidCode;
void PrintSource(Axis* axis, RSISource source)
{
printf("\nThe source of the axis error is: %s ", axis->SourceNameGet(source)); // SourceNameGet will return the first status bit which is set on an Axis or Multiaxis->
}
void PrintState(RSIState state)
{
printf("\nYour Axis is in state: %i", state);
}
void AxisStatusMain()
{
// Constants
const int AXIS_NUMBER = 0; // Specify which axis/motor to control.
char rmpPath[] = "C:\\RSI\\X.X.X\\";
// Initialize MotionController class.
SampleAppsCPP::HelperFunctions::CheckErrors(controller); // [Helper Function] Check that the controller has been initialized correctly.
SampleAppsCPP::HelperFunctions::StartTheNetwork(controller); // [Helper Function] Initialize the network.
Axis *axis = controller->AxisGet(AXIS_NUMBER); // Initialize the axis->
SampleAppsCPP::HelperFunctions::CheckErrors(axis); // [Helper Function] Check that the controller has been initialized correctly.
try
{
// CHECK AXIS STATE
RSIState state = axis->StateGet(); // StateGet will return RSIState enum name of the current state of the Axis or Multiaxis-> (Ex: RSIStateERROR)
RSISource source; // Declare a RSISource variable.
switch (state)
{
PrintState(state);
break;
source = axis->SourceGet(); // SourceGet will return the RSISource enum name of the first status bit that is active. (Ex: RSISourceAMP_FAULT)
PrintState(state);
PrintSource(axis, source);
break;
default:
printf("");
break;
}
// or USE STATUS BIT GET
bool isAmpFault_Active = axis->StatusBitGet(RSIEventType::RSIEventTypeAMP_FAULT); // StatusBitGet returns the state of a status bit, true or false.
bool isPositionErrorLimitActive = axis->StatusBitGet(RSIEventType::RSIEventTypeLIMIT_ERROR);
bool isHWNegativeLimitActive = axis->StatusBitGet(RSIEventType::RSIEventTypeLIMIT_HW_NEG);
bool isHWPostiveLimitActive = axis->StatusBitGet(RSIEventType::RSIEventTypeLIMIT_HW_POS); // This can be done for all RSIEventTypes
}
catch (RsiError const& err)
{
printf("\n%s\n", err.text); // If there are any exceptions/issues this will be printed out.
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
system("pause"); // Allow time to read Console.
}