AxisConfig.cs

This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires.

using RSI.RapidCode.dotNET; // Import our RapidCode Library.
using NUnit.Framework;
using System;
namespace SampleAppsCS
{
[TestFixture]
[Category("SoftwareSample")]
public class AxisConfig : SampleAppTestBase
{
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void AxisSettling()
{
int POSITION_TOLERANCE_FINE_DEFAULT = (int)axis.PositionToleranceFineGet();
int POSITION_TOLERANCE_COARSE_DEFAULT = (int)axis.PositionToleranceCoarseGet();
int VELOCITY_TOLERANCE_DEFAULT = (int)axis.VelocityToleranceGet();
int SETTLING_TIME_DEFAULT = (int)axis.SettlingTimeGet();
//@[AxisSettling]
//---ARRRANGE---
const int POSITION_TOLERANCE_FINE = 200; // Specify the fine position tolerance.
const int POSITION_TOLERANCE_COARSE = 300; // Specify the coarse position tolerance.
const int VELOCITY_TOLERANCE = 12000; // Specify the velocity tolerance.
const int SETTLING_TIME = 5; // Specify the settling time.
//---ACT---
axis.PositionToleranceFineSet(POSITION_TOLERANCE_FINE); // Set fine position tolerance.
axis.PositionToleranceCoarseSet(POSITION_TOLERANCE_COARSE); // Set coarse position tolerance.
axis.VelocityToleranceSet(VELOCITY_TOLERANCE); // Set velocity tolerance.
axis.SettlingTimeSet(SETTLING_TIME); // Set settling time.
//---ASSERT---
Assert.That(axis.PositionToleranceFineGet(), Is.EqualTo(POSITION_TOLERANCE_FINE), "The getter function should return a value equal to POSITION_TOLERANCE_FINE");
Assert.That(axis.PositionToleranceCoarseGet(), Is.EqualTo(POSITION_TOLERANCE_COARSE), "The getter function should return a value equal to POSITION_TOLERANCE_COARSE");
Assert.That(axis.VelocityToleranceGet(), Is.EqualTo(VELOCITY_TOLERANCE), "The getter function should return a value equal to VELOCITY_TOLERANCE");
Assert.That(axis.SettlingTimeGet(), Is.EqualTo(SETTLING_TIME), "The getter function should return a value equal to SETTLING_TIME");
//@[AxisSettling]
axis.PositionToleranceFineSet(POSITION_TOLERANCE_FINE_DEFAULT); // Set fine position tolerance.
axis.PositionToleranceCoarseSet(POSITION_TOLERANCE_COARSE_DEFAULT); // Set coarse position tolerance.
axis.VelocityToleranceSet(VELOCITY_TOLERANCE_DEFAULT); // Set velocity tolerance.
axis.SettlingTimeSet(SETTLING_TIME_DEFAULT);
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void ConfigAmpFault()
{
RSIAction RSIAction_DEFAULT = axis.AmpFaultActionGet(); // Set the action that will occur when there is an amp fault.
bool Trigger_DEFAULT = axis.AmpFaultTriggerStateGet(); //Set the state of the amp fault.
double AMP_FAULT_DURATION_TIME_DEFAULT = axis.AmpFaultDurationGet(); //Set the duration required before the Amp Fault event triggers.
//@[ConfigAmpFault]
//---ARRANGE---
const double AMP_FAULT_DURATION_TIME = 1; //value in seconds
//---ACT---
axis.AmpEnableSet(false); // Disable the amp
axis.AmpFaultActionSet(RSIAction.RSIActionABORT); // Set the action that will occur when there is an amp fault.
axis.AmpFaultTriggerStateSet(false); //Set the state of the amp fault.
axis.AmpFaultDurationSet(AMP_FAULT_DURATION_TIME); //Set the duration required before the Amp Fault event triggers.
//---ASSERT---
Assert.That(axis.AmpEnableGet(), Is.EqualTo(false), "The getter function should return a value equal to false");
Assert.That(axis.AmpFaultActionGet(), Is.EqualTo(RSIAction.RSIActionABORT), "The getter function should return a value equal to RSIActionABORT");
Assert.That(axis.AmpFaultTriggerStateGet(), Is.EqualTo(false), "The getter function should return a value equal to false");
Assert.That(axis.AmpFaultDurationGet(), Is.EqualTo(AMP_FAULT_DURATION_TIME), "The getter function should return a value equal to AMP_FAULT_DURATION_TIME");
//@[ConfigAmpFault]
//---RESET---
axis.AmpFaultActionSet(RSIAction_DEFAULT); // Set the action that will occur when there is an amp fault.
axis.AmpFaultTriggerStateSet(Trigger_DEFAULT); //Set the state of the amp fault.
axis.AmpFaultDurationSet(AMP_FAULT_DURATION_TIME_DEFAULT); //Set the duration required before the Amp Fault event triggers.
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void SetUserUnits()
{
// Other Variables
double currentUserUnits = axis.UserUnitsGet();
//@[SetUserUnits]
// Constants
const int ENCODER_RESOLUTION_BITS = 20; // The number of bits defining the encoder resolution
// Specify your counts per unit / user units. (the motor used in this sample app has 1048576 encoder pulses per revolution)
double USER_UNITS = Math.Pow(2, ENCODER_RESOLUTION_BITS); //1048576 Setting the user units to this value will result in a commanded position of 1 spinning the motor 1 full revolution
axis.UserUnitsSet(USER_UNITS); // SET YOUR USER UNITS!
axis.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
//---ASSERT---
Assert.That(axis.UserUnitsGet(), Is.EqualTo(USER_UNITS)); // Verify that your user units were changed!
//@[SetUserUnits]
Assert.That(axis.UserUnitsGet(),Is.EqualTo( 1048576)); // Verify that your user units were changed!
axis.UserUnitsSet(Constants.USER_UNITS); // Restore Default
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void StopRate()
{
// Constants
const double STOP_RATE = 1.2; // Specify the default STOP rate in seconds.
const double ESTOP_RATE = 1.3; // Specify the default ESTOP rate in seconds.
const double ESTOP_DECELERATION_RATE_T = 1.5; // Specify the default ESTOP deceleration rate in seconds.
axis.StopTimeSet(STOP_RATE); // Set the default STOP time to STOP_RATE_DEFAULT secs.
axis.EStopTimeSet(ESTOP_RATE); // Set the default ESTOP time to ESTOP_RATE_DEFAULT secs.
axis.EStopDecelerationSet(ESTOP_DECELERATION_RATE_T); // Set the default ESTOP time to ESTOP_DECELERATION_RATE secs.
Assert.That(axis.StopTimeGet(), Is.EqualTo(STOP_RATE)); // Verify that your user units were changed!
Assert.That(axis.EStopTimeGet(), Is.EqualTo(ESTOP_RATE)); // Verify that your user units were changed!
Assert.That(axis.EStopDecelerationGet(), Is.EqualTo(ESTOP_DECELERATION_RATE_T)); // Verify that your user units were changed!
//@[StopRate]
// Constants
const double STOP_RATE_DEFAULT = 1.0; // Specify the default STOP rate in seconds.
const double ESTOP_RATE_DEFAULT = 0.05; // Specify the default ESTOP rate in seconds.
const double ESTOP_DECELERATION_RATE = 1000; // Specify the default ESTOP deceleration rate in seconds.
axis.StopTimeSet(STOP_RATE_DEFAULT); // Set the default STOP time to STOP_RATE_DEFAULT secs.
axis.EStopTimeSet(ESTOP_RATE_DEFAULT); // Set the default ESTOP time to ESTOP_RATE_DEFAULT secs.
axis.EStopDecelerationSet(ESTOP_DECELERATION_RATE); // Set the default ESTOP time to ESTOP_DECELERATION_RATE secs.
//@[StopRate]
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void HardwareLimits()
{
var defaultTriggerState = axis.HardwarePosLimitTriggerStateGet();
//@[HardwareLimits]
// Constants
const bool ACTIVE_HIGH = true; // Constant for active high.
const bool ACTIVE_LOW = false; // Constant for active low.
const double HW_POS_DURATION_TIME = 0.01; // Positive limit duration. (in seconds)
const double HW_NEG_DURATION_TIME = 0.01; // Negative limit duration. (in seconds)
// Change Hardware POSITIVE (+) Limit characteristics.
//---ACT---
axis.HardwarePosLimitActionSet(RSIAction.RSIActionE_STOP); // Set the positive limit action to E_STOP.
axis.HardwarePosLimitTriggerStateSet(ACTIVE_HIGH); // Set the positive limit trigger state to ACTIVE_HIGH.
axis.HardwarePosLimitDurationSet(HW_POS_DURATION_TIME); // Set the positive limit duration to 0.01 seconds.
//---ASSERT---
Assert.That(axis.HardwarePosLimitActionGet(), Is.EqualTo(RSIAction.RSIActionE_STOP), "Hardware Positive Limit Action should be set to RSIAction.RSIActionE_STOP");
Assert.That(axis.HardwarePosLimitTriggerStateGet(), Is.EqualTo(ACTIVE_HIGH), "Hardware Positive Limit TriggerState should be set to ACTIVE_HIGH");
Assert.That(axis.HardwarePosLimitDurationGet(), Is.EqualTo(HW_POS_DURATION_TIME), "Hardware Positive Limit Duration set to HW_POS_DURATION_TIME");
// Change Hardware NEGATIVE (-) Limit charateristics.
//---ACT---
axis.HardwareNegLimitActionSet(RSIAction.RSIActionE_STOP); // Set the negative limit action to E_STOP.
axis.HardwareNegLimitTriggerStateSet(ACTIVE_LOW); // Set the negative limit trigger state to ACTIVE_LOW.
axis.HardwareNegLimitDurationSet(HW_NEG_DURATION_TIME); // Set the negative limit duration to 0.01 seconds.
//---ASSERT---
Assert.That(axis.HardwareNegLimitActionGet(), Is.EqualTo(RSIAction.RSIActionE_STOP), "Hardware Positive Limit Action should be set to RSIAction.RSIActionE_STOP");
Assert.That(axis.HardwareNegLimitTriggerStateGet(), Is.EqualTo(ACTIVE_LOW), "Hardware Positive Limit TriggerState should be set to ACTIVE_LOW");
Assert.That(axis.HardwareNegLimitDurationGet(), Is.EqualTo(HW_POS_DURATION_TIME), "Hardware Positive Limit Duration set to HW_POS_DURATION_TIME");
//@[HardwareLimits]
//---RESET---
axis.HardwarePosLimitTriggerStateSet(defaultTriggerState); // Set the positive limit trigger state to ACTIVE_HIGH.
axis.HardwareNegLimitTriggerStateSet(defaultTriggerState); // Set the positive limit trigger state to ACTIVE_HIGH.
}
public void PhantomAxis()
{
//@[PhantomAxis]
controller.AxisCountSet(controller.AxisCountGet() + 1); // Configure one additional axis to be used for the phantom axis
int axisNumber = controller.AxisCountGet() - 1; // Set the axis number to the last axis on the network (subtract one because the axes are zero indexed)
axis = controller.AxisGet(axisNumber); // Initialize Axis class
SampleAppsCS.HelperFunctions.CheckErrors(axis); // [Helper Function] Check that the axis has been initialized correctly
// These limits are not meaningful for a Phantom Axis (e.g., a phantom axis has no actual position so a position error trigger is not necessary)
// Therefore, you must set all of their actions to "NONE".
axis.ErrorLimitActionSet(RSIAction.RSIActionNONE); // Set Error Limit Action.
axis.HardwareNegLimitActionSet(RSIAction.RSIActionNONE); // Set Hardware Negative Limit Action.
axis.HardwarePosLimitActionSet(RSIAction.RSIActionNONE); // Set Hardware Positive Limit Action.
axis.HomeActionSet(RSIAction.RSIActionNONE); // Set Home Action.
axis.SoftwareNegLimitActionSet(RSIAction.RSIActionNONE); // Set Software Negative Limit Action.
axis.SoftwarePosLimitActionSet(RSIAction.RSIActionNONE); // Set Software Positive Limit Action.
const double positionToleranceMax = Double.MaxValue / 10.0; // reduce from max slightly, so XML to string serialization and deserialization works without throwing System.OverflowException
axis.PositionToleranceCoarseSet(positionToleranceMax); // Set Settling Coarse Position Tolerance to max value
axis.PositionToleranceFineSet(positionToleranceMax); // Set Settling Fine Position Tolerance to max value (so Phantom axis will get immediate MotionDone when target is reached)
axis.MotorTypeSet(RSIMotorType.RSIMotorTypePHANTOM); // Set the MotorType to phantom
//@[PhantomAxis]
}
}
}