motorfeedback.cpp

Reads the primary and secondary feedback for a motor.

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

 motorfeedback : Reasd the primary and secondary feedback for a motor.

 The function axis->EncoderPositionGet() retrieves raw encoder position for an axis. The encoder 
 position is not scaled by the origin. The encoder position is sometimes called 'motor feedback position.'
 To get actual position retrieved by controller please take a look at axis->ActualPositionGet()

 For any questions regarding this sample code please visit our documentation at 
 www.roboticsys.com/rapidcode

 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;


void motorfeedbackMain(int argc, char   *argv[])
{
  try
  {
    MotionController    *controller ;
    Axis        *axis ;

    // initialize MotionController class
    controller = MotionController::CreateFromBoard(0);  
    //Init(controller, number) used to initialize Axis X and Y respectively. 
    axis = controller->AxisGet(0);

    //returns the motor type
    printf("Motor Type   : ");
    switch(axis->MotorTypeGet()) 
    {
      case RSIMotorTypeSERVO : 
        printf("Servo\n"); 
        break;
      
      case RSIMotorTypeSTEPPER : 
        printf("Stepper\n"); 
        break;
      
      case RSIMotorTypePHANTOM: 
        printf("Phantom\n"); 
        break;
      
      default:
        printf("Invalid\n");
        break;
    }
        
    //returns the type of encoder being used 
    printf("Encoder Type : ");
    switch(axis->EncoderTypeGet())
    {
      case RSIMotorEncoderTypeQUAD_AB :
        printf("QUAD_AB\n");
        break;

      case RSIMotorEncoderTypeDRIVE :
        printf("DRIVE\n");
        break;
      
      case RSIMotorEncoderTypeSSI :
        printf("SSI\n");
        break;
      
      default:
        printf("Invalid\n");
        break;
    }
      
    printf("\n");
    while (controller->OS->KeyGet(RSIWaitPOLL) < 0)
    {
      //returns the raw encoder position for an axis
      printf("\rPrimary: %12.0lf Secondary: %12.0lf", 
              axis->EncoderPositionGet(RSIMotorEncoderPRIMARY),
              axis->EncoderPositionGet(RSIMotorEncoderSECONDARY));
    }
    printf("\n");
    
  }
  catch (RsiError *err)
  {
    printf("%s\n", err->text);
  }
}