gear.cpp

Configure an axis' commanded position to be geared off of another axis

/* gear.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.
 
 Axis gearing on the XMP is based off of a Axis, RSIAxisMasterType, numerator, and denominator.
 The Axis points to a master axis to gear to. The RSIAxisMasterType specifies what feedback source to gear to. The ratio betweent the lead
 and follower axes is set by a ratio of two longs -- a numerator and a
 denominator. For example:

 Ratio   Numerator   Denominator
   1        1           1
   2        2           1
   0.5      1           2
   0.1      1           10
   10       10          1

 Function used is GearingEnable(Axis* masterAxis, RSIAxisMasterType gearingSource, long numerator, long denominator)
 User has two options from gearingSource declared above:
 1. RSIAxisMasterType::RSIGearingSourceCOMMAND_POSITION -> Gear to command position
 2. RSIAxisMasterType::RSIGearingSourceACTUAL_POSITION  -> Gear to actual position
 
 For any questions regarding this sample code please visit our documentation at www.roboticsys.com
 or call us at (219)926-3630.

 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 RSI_BOARD       0
#define X0_AXIS         0
#define X1_AXIS         1

#define VELOCITY        1000.0
#define ACCELERATION      10000.0
#define DECELERATION      10000.0
#define JERK_PERCENT      100.0


void gearMain()
{
  try
  {
    MotionController  *controller;
    Axis        *axisX0;
    Axis        *axisX1;

    // Create and initialize RsiController class (PCI board).
    controller = MotionController::CreateFromBoard(RSI_BOARD);  
    
    // Get Axis X0 and X1 respectively.
    axisX0 = controller->AxisGet(X0_AXIS); 
    axisX1 = controller->AxisGet(X1_AXIS);
    

    // zero the positions (in case the program is run multiple times)
    axisX0->PositionSet(0.0);
    axisX1->PositionSet(0.0);
    
    //Clear Faults and Enable Amplifiers
    axisX0->ClearFaults();
    axisX1->ClearFaults();

    axisX0->AmpEnableSet(true);
    axisX1->AmpEnableSet(true);
    
    //Perform Gearing
    printf("\nTesting for Gearing\n");
    
    // configure X1 axis to be a slave to X0 axis (-1:1 ratio)
    axisX1->GearingEnable(axisX0, RSIAxisMasterTypeAXIS_COMMANDED_POSITION, -1, 1);

    // perform a S-curve motion on master axis
    axisX0->MoveSCurve(2500, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);

    axisX0->MotionDoneWait()
      ;

    printf("Testing for GearingRatioChange\n");
    
    // change the slave's gear ratio   (-2:1 ratio)
    axisX1->GearingRatioChange(-2, 1);
    
    // move the master again
    axisX0->MoveSCurve(4000, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT); 
    axisX0->MotionDoneWait()
      ;

    //disable Gearing on slave
    axisX1->GearingDisable();


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