customHome.cpp
Homing routine that captures the hardware position, sets the originand then moves back to home.
#include "rsi.h"
using namespace RSI::RapidCode::SynqNet;
#define AXIS_NUMBER 0
#define CAPTURE_TYPE RSICaptureTypePOSITION
#define CAPTURE_SOURCE RSICaptureSourceHOME
#define CAPTURE_TRIGGER_EDGE RSICaptureEdgeFALLING
#define CAPTURE_FEEDBACK_AXIS_NUMBER AXIS_NUMBER
#define CAPTURE_ENCODER RSIMotorEncoderPRIMARY
#define CAPTURE_GLOBAL_TRIGGER false
#define VELOCITY 5000
#define ACCELERATION 80000
#define DECELERATION 80000
#define POSITION 0
void PrintCaptureState(Axis *axis)
{
char* text;
long captureState = axis->CaptureStateGet();
switch(captureState)
{
case RSICaptureStateIDLE:
text = "IDLE";
break;
case RSICaptureStateARMED:
text = "ARMED";
break;
case RSICaptureStateCAPTURED:
text = "CAPTURED";
break;
default:
text = "UNKNOWN";
break;
}
printf("Capture State is: %s\n",text );
}
void customHomeMain()
{
try
{
MotionController *controller ;
Axis *axis ;
double capturedPosition;
controller = MotionController::CreateFromBoard(0);
axis = controller->AxisGet( AXIS_NUMBER);
axis->CaptureArm(false);
axis->CaptureConfigSet(CAPTURE_TYPE, CAPTURE_SOURCE, CAPTURE_TRIGGER_EDGE,
CAPTURE_FEEDBACK_AXIS_NUMBER, CAPTURE_ENCODER,
CAPTURE_GLOBAL_TRIGGER);
axis->Abort();
axis->ClearFaults();
axis->AmpEnableSet(true);
axis->CaptureArm(true);
PrintCaptureState(axis);
printf("Looking for Home...\n\n");
axis->HomeActionSet(RSIActionSTOP);
axis->InterruptEnableSet(true);
axis->MoveVelocity(VELOCITY, ACCELERATION);
while (axis->InterruptWait(RSIWaitFOREVER) != RSIEventTypeMOTION_DONE)
{
}
PrintCaptureState(axis);
if(axis->CaptureStateGet() == RSICaptureStateCAPTURED)
{
capturedPosition = ( axis->CapturePositionGet() - axis->OriginPositionGet());
printf("\nCaptured Position: %lf\n\n", capturedPosition);
axis->OriginPositionSet(axis->CapturePositionGet());
}
else
{
printf("The Capture never triggered.\n");
}
axis->HomeActionSet(RSIActionNONE);
axis->ClearFaults();
axis->AmpEnableSet(true);
printf("Moving back to origin...\n\n");
axis->MoveTrapezoidal(POSITION, VELOCITY, ACCELERATION, DECELERATION);
}
catch (RsiError *err)
{
printf("%s\n", err->text);
}
}