userLimitDigitalInputAction.cpp

Configure an axis' User Limit to perform an error action, when an input bit is triggered.

/* userLimitDigitalOutputAction.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.

 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 SqNode to use for I/O?
#define IO_NODE_NUMBER 1

// 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 input bit?
#define INPUT_BIT_NUMBER  7    



void userLimitDigitalOutputActionMain()
{
  // RapidCode interface classes
  MotionController  *controller;
  Axis        *axis;
  IO          *io;
  IOPoint       *digitalInput;

  try
  {
    // initialize MotionController class
    controller = MotionController::CreateFromBoard(CONTROLLER_NUMBER);

    // initialize RsiAxis class
    axis = controller->AxisGet(AXIS_NUMBER);
  
    // initialize the I/O class
    io = controller->IOGet(IO_NODE_NUMBER);

    digitalInput->CreateDigitalInput(io, INPUT_BIT_NUMBER);

    // configure user limit to evaluate input bit
    axis->UserLimitConditionSet(USER_LIMIT, 
                  CONDITION,
                  RSIXmpLimitTypeBIT_CMP,
                  digitalInput->AddressGet(),
                  digitalInput->MaskGet(),
                  digitalInput->MaskGet());
      
    // enable the user limit, generate ESTOP_ABORT action when input is turned on
    axis->UserLimitConfigSet(USER_LIMIT, (RSIXmpStatus)(RSIXmpStatusLIMIT | RSIXmpStatusESTOP_ABORT), RSIXmpLogicSINGLE , 0.0);

    printf("Waiting for the input bit to go high...\n");
    printf("Press any key to exit.\n");

    // wait for user limit to trigger
     while(controller->OS->KeyGet(RSIWaitPOLL) < 0)
     {
       printf("User Limit state is %d\r", axis->UserLimitStateGet(USER_LIMIT));
       controller->OS->Sleep(1);
     }


    // disable User Limit
    axis->UserLimitConfigSet(USER_LIMIT, RSIXmpStatusLIMIT, RSIXmpLogicNEVER , 0.0);


  }
  catch (RsiError *rsiError)
  {
    printf("Text:  %s\n", rsiError->text);
  }
}