hardwareLimits.cpp

Configure positive and negative hardware limit inputs.

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

 There are four configurations available for a motor's positive and negative hardware limit inputs:
  1) Event Action   (action such as RSIActionE_STOP, RSIActionNONE, etc...)
  2) Event Trigger  (trigger polarity such as active HIGH and active LOW)
  3) Direction Flag ("ENABLED" will cause the command direction of motion to
                     qualify the events, "DISABLED" will ignore direction,
                     based solely on the limit input state)
  4) Duration       (the limit condition will exist for
                     a programmable number of seconds before an
                     event occurs)

 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;

#define AXIS_NUMBER             0
#define ACTIVE_HIGH             1
#define ACTIVE_LOW              0
#define ENABLED               1
#define DISABLED              0
#define HW_POS_DURATION_TIME        1 //value in seconds
#define HW_NEG_DURATION_TIME        2 //value in seconds


void hardwareLimitsMain()
{
  try
  {
    MotionController    *controller ;
    Axis        *axis ;

    // initialize MotionController class
    controller = MotionController::CreateFromBoard(0);  
    
    // initialize Axis class  
    axis = controller->AxisGet( AXIS_NUMBER);

    //To change HW_POS_LIM characteristics:
    axis->HardwarePosLimitActionSet(RSIActionE_STOP);
    printf("\n HW_Pos_limit Action set to E_STOP\n");

    axis->HardwarePosLimitTriggerStateSet(ACTIVE_HIGH);
    printf("\n HW_Pos_limit TriggerState set to ACTIVE_HIGH\n");

    axis->HardwarePosLimitDurationSet(HW_POS_DURATION_TIME);
    printf("\n HW_Pos_limit Duration set to 1.0 second\n");

    axis->HardwarePosLimitDirectionSensitiveSet(ENABLED);
    printf("\n HW_Pos_limit Direction set to POSITIVE\n");


    //To change the HW_NEG_LIM characteristics. Inputs to methods are defined above.
    axis->HardwareNegLimitActionSet(RSIActionE_STOP);
    printf("\n\n HW_Neg_limit Action set to E_STOP\n"); 

    axis->HardwareNegLimitTriggerStateSet(ACTIVE_HIGH);
    printf("\n HW_Neg_limit TriggerState set to ACTIVE_HIGH\n");    

    axis->HardwareNegLimitDurationSet(HW_NEG_DURATION_TIME);
    printf("\n HW_Neg_limit Duration set to 1.0 second\n");   

    axis->HardwareNegLimitDirectionSensitiveSet(ENABLED);
    printf("\n HW_Neg_limit Direction set to POSITIVE\n");  
  }
  catch (RsiError *err)
  {
    printf("%s\n", err->text);
  }
}