using RSI.RapidCode.dotNET;
using System;
#if DOXYGEN
#endif
public class MathBlockDifferenceOfPositionUserLimit : SampleApp
{
public override int Run()
{
const int MATHBLOCK_COUNT = 1;
const int AXIS_COUNT = 2;
const int USER_LIMIT_COUNT = 1;
const int FIRST_AXIS_INDEX = 0;
const int SECOND_AXIS_INDEX = 1;
const double USER_UNITS = 1048576;
const int MATHBLOCK_INDEX = 0;
const int USER_LIMIT_INDEX = 0;
const double MAX_POSITION_DIFFERENCE = 0.5 * USER_UNITS;
const int USER_LIMIT_DURATION = 0;
const double RELATIVE_POSITION = 2 * MAX_POSITION_DIFFERENCE;
const double VELOCITY = 1;
const double ACCELERATION = 10;
const double DECELERATION = 10;
const double JERK_PCT = 0;
USE_HARDWARE = false;
try
{
if (USE_HARDWARE)
{
}
else
{
}
mathBlockConfig.InputAddress0 = axis0.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
mathBlockConfig.InputDataType0 =
RSIDataType.RSIDataTypeDOUBLE;
mathBlockConfig.InputAddress1 = axis1.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
mathBlockConfig.InputDataType1 =
RSIDataType.RSIDataTypeDOUBLE;
mathBlockConfig.ProcessDataType =
RSIDataType.RSIDataTypeDOUBLE;
Console.WriteLine("MathBlock configured to subtract the position of the second axis from the position of the first axis.");
Console.WriteLine("UserLimit configured to trigger when the absolute position difference is greater than " + MAX_POSITION_DIFFERENCE + " and abort motion.");
Console.WriteLine("Moving the axes to trigger the UserLimit...");
axis0.
MoveRelative(RELATIVE_POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PCT);
{
Console.WriteLine("Both axes are in the error state after the UserLimit triggered (This is the intended behavior).");
return 0;
}
else
{
Console.WriteLine("Error: The axes should be in an error state after the UserLimit triggers, but they are not.");
Console.WriteLine(
"First Axis State: " + axis0.
StateGet());
Console.WriteLine(
"Second Axis State: " + axis1.
StateGet());
return -1;
}
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
return -1;
}
finally
{
}
}
}
public class MathBlockCalculateAccelerationFromVelocity : SampleApp
{
public override int Run()
{
const int MATHBLOCK_COUNT = 2;
const int AXIS_COUNT = 1;
const int AXIS_INDEX = 0;
const double USER_UNITS = 1048576;
const int SUBTRACTION_MATHBLOCK_INDEX = 0;
const int PREVIOUS_VELOCITY_MATHBLOCK_INDEX = 1;
const double ONE = 1.0;
const int USERBUFFER_INDEX = 0;
const double VELOCITY = 1.0;
const double ACCELERATION = 0.123;
USE_HARDWARE = false;
try
{
if (USE_HARDWARE)
{
}
else
{
}
subtractionConfig.InputAddress0 = axis.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
subtractionConfig.InputDataType0 =
RSIDataType.RSIDataTypeDOUBLE;
subtractionConfig.InputDataType1 =
RSIDataType.RSIDataTypeDOUBLE;
subtractionConfig.ProcessDataType =
RSIDataType.RSIDataTypeDOUBLE;
previousVelocityConfig.InputAddress0 = axis.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
previousVelocityConfig.InputDataType0 =
RSIDataType.RSIDataTypeDOUBLE;
previousVelocityConfig.InputDataType1 =
RSIDataType.RSIDataTypeDOUBLE;
previousVelocityConfig.ProcessDataType =
RSIDataType.RSIDataTypeDOUBLE;
Console.WriteLine($"Calculated acceleration from MathBlock: {calculatedAcceleration}");
if (Math.Abs(calculatedAcceleration - ACCELERATION) <= 0.000001)
{
Console.WriteLine("The MathBlock is calculating the Axis' acceleration by subtracting previous velocity from current velocity.");
return 0;
}
else
{
Console.WriteLine("Error: The MathBlock is not calculating the Axis' acceleration as expected.");
return -1;
}
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
return -1;
}
finally
{
}
}
}
static void SetupControllerForHardware(MotionController controller)
Sets up the controller for hardware use by resetting it and starting the network.
static MotionController CreateController()
Creates the MotionController object, using creation parameters.
static void SetupControllerForPhantoms(MotionController controller, int axisCount, int[] axisNums)
Sets up the controller for phantom axes, including configuring specified axes as phantom.
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
HelperFunctionsCS class provides static methods for common tasks in RMP applications.
uint64_t AddressGet(RSIAxisAddressType addressType)
Get the an address for some location on the Axis.
double UserUnitsGet()
Get the number of counts per User Unit.
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
void MoveVelocity(double velocity)
void PositionSet(double position)
Set the Command and Actual positions.
void MoveRelative(double relativePosition, double vel, double accel, double decel, double jerkPct)
Command a relative point-to-point S-Curve motion.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void UserLimitDisable(int32_t number)
Disable the processing of a User Limit.
void MathBlockCountSet(int32_t mathBlockCount)
Set the number of processed MathBlocks in the MotionController.
void UserLimitConditionSet(int32_t number, int32_t conditionNumber, RSIUserLimitLogic logic, uint64_t addressOfUInt32, uint32_t userLimitMask, uint32_t limitValueUInt32)
Set the conditions for a User Limit with a 32-bit integer trigger value.
void MotionCountSet(int32_t motionCount)
Set the number of processed Motion Supervisors in the controller.
void MemoryDoubleSet(uint64_t address, double dataDouble)
Write a 64-bit double value to controller memory.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
void UserLimitConfigSet(int32_t number, RSIUserLimitTriggerType triggerType, RSIAction action, int32_t actionAxis, double duration, bool singleShot)
Configure a User Limit.
void Delete(void)
Delete the MotionController and all its objects.
MultiAxis * MultiAxisGet(int32_t motionSupervisorNumber)
MultiAxisGet returns a pointer to a MultiAxis object and initializes its internals.
void UserLimitCountSet(int32_t userLimitCount)
Set the number of processed UserLimits in the MotionController.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
MathBlockConfig MathBlockConfigGet(int32_t mathBlockNumber)
Get a MathBlock configuration.
FirmwareValue MathBlockProcessValueGet(int32_t mathBlockNumber)
Get a MathBlock process value.
void MathBlockConfigSet(int32_t mathBlockNumber, MathBlockConfig &config)
Set a MathBlock configuration.
void AxisRemoveAll()
Remove all axes from a MultiAxis group.s.
void AxisAdd(Axis *axis)
Add an Axis to a MultiAxis group.
Represents multiple axes of motion control, allows you to map two or more Axis objects together for e...
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void AmpEnableSet(bool enable)
Enable all amplifiers.
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
RSIState StateGet()
Get the Axis or MultiAxis state.
RSIMathBlockOperation
MathBlock operations.
RSIControllerAddressType
Used to get firmware address used in User Limits, Recorders, etc.
RSIDataType
Data types for User Limits and other triggers.
RSIUserLimitLogic
Logic options for User Limits.
RSIAction
Action to perform on an Axis.
RSIAxisAddressType
Used to get firmware address used in User Limits, Recorders, etc.
RSIUserLimitTriggerType
Trigger types for UserLimits.
MathBlock configuration structure.
double Double
Double precision (64-bit) floating-point.