Sample applications demonstrating use of Math Blocks in RapidCode.
Console.WriteLine("📜 MathBlock: Calculate Acceleration from Velocity");
const int MB_COUNT = 2;
const int MB1 = 0;
const int MB2 = 1;
const double VELOCITY = 1.0;
const double ACCELERATION = 0.0123;
try
{
mbConfig1.Operation = SUBTRACT;
mbConfig1.InputAddress0 = currentVelocityAddr;
mbConfig1.InputAddress1 = previousVelocityAddr;
mbConfig1.InputDataType0 = DOUBLE;
mbConfig1.InputDataType1 = DOUBLE;
mbConfig1.ProcessDataType = DOUBLE;
mbConfig2.Operation = MULTIPLY;
mbConfig2.InputAddress0 = currentVelocityAddr;
mbConfig2.InputAddress1 = userBuffer0Addr;
mbConfig2.InputDataType0 = DOUBLE;
mbConfig2.InputDataType1 = DOUBLE;
mbConfig2.ProcessDataType = DOUBLE;
double calculatedAcceleration = latestVelocityDelta * Math.Pow(sampleRate, 2) / userUnits;
double calculatedAccelerationRounded = Math.Round(calculatedAcceleration, 8);
Console.WriteLine($"Calculated acceleration: {calculatedAccelerationRounded}");
Console.WriteLine($"Expected acceleration: {ACCELERATION}");
if (ACCELERATION != calculatedAccelerationRounded)
throw new Exception("❌ MathBlock result is outside accepted tolerance.");
}
finally
{
}
Constants used in the C# sample apps.
const int AXIS_0_INDEX
Default: 0.
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Helpers 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 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.
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 MathBlockCountSet(int32_t mathBlockCount)
Set the number of processed MathBlocks in the MotionController.
static MotionController * Get()
Get an already running RMP EtherCAT 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 Delete(void)
Delete the MotionController and all its objects.
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 ClearFaults()
Clear all faults for an Axis or MultiAxis.
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
RSIMathBlockOperation
MathBlock operations.
RSIControllerAddressType
Used to get firmware address used in User Limits, Recorders, etc.
RSIDataType
Data types for User Limits and other triggers.
RSIAction
Action to perform on an Axis.
RSIAxisAddressType
Used to get firmware address used in User Limits, Recorders, etc.
double Double
Double precision (64-bit) floating-point.
Console.WriteLine("📜 MathBlock: Difference of Position UserLimit");
const int INDEX_ZERO = 0;
try
{
mbConfig.Operation = SUBTRACT;
mbConfig.InputAddress0 = axis0PositionAddr;
mbConfig.InputAddress1 = axis1PositionAddr;
mbConfig.InputDataType0 = DOUBLE;
mbConfig.InputDataType1 = DOUBLE;
mbConfig.ProcessDataType = DOUBLE;
number: INDEX_ZERO,
conditionNumber: 0,
addressOfDouble: mbProcessValueAddr,
limitValueDouble: 5 *
Constants.AXIS_0_USER_UNITS);
number: INDEX_ZERO,
duration: 0);
relativePosition: 10,
vel: 1,
accel: 1,
decel: 1,
jerkPct: 0);
Console.WriteLine($"Axis 0 expected state: {RSIState.RSIStateERROR}");
Console.WriteLine($"Axis 0 state: {axis0State}");
if (axis0State !=
RSIState.RSIStateERROR)
throw new Exception("❌ UserLimit did not trigger correctly - both axes should be in error state.");
}
finally
{
}
const int AXIS_1_INDEX
Default: 1.
void MoveRelative(double relativePosition, double vel, double accel, double decel, double jerkPct)
Command a relative point-to-point S-Curve motion.
void UserLimitDisable(int32_t number)
Disable the processing of a User Limit.
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 UserLimitConfigSet(int32_t number, RSIUserLimitTriggerType triggerType, RSIAction action, int32_t actionAxis, double duration, bool singleShot)
Configure a User Limit.
void UserLimitCountSet(int32_t userLimitCount)
Set the number of processed UserLimits in the MotionController.
RSIState StateGet()
Get the Axis or MultiAxis state.
RSIUserLimitLogic
Logic options for User Limits.
RSIUserLimitTriggerType
Trigger types for UserLimits.
Console.WriteLine("📜 MathBlock: PDO Copy");
const int MB_INDEX = 0;
const int BIAS = 8000;
try
{
{
Console.WriteLine("Network is not started. Please start the network before running this sample app.");
return;
}
{
Console.WriteLine("One or both axes are phantom (not real). Please use real axes for this sample app.");
return;
}
mbConfig.InputAddress0 = torqueActualAddress;
mbConfig.InputAddress1 = userBufferAddr0;
mbConfig.InputDataType0 = INT32;
mbConfig.InputDataType1 = INT32;
mbConfig.Operation = ADD;
mbConfig.ProcessDataType = INT32;
mbConfig.OutputAddress = targetTorqueAddress;
mbConfig.OutputDataType = INT32;
Console.WriteLine($"MathBlock configured to copy axis {Constants.AXIS_0_INDEX} torque actual to axis {Constants.AXIS_1_INDEX} target torque with bias {BIAS}");
Console.WriteLine($"Operation: {mbConfig.Operation}");
Console.WriteLine("✅ MathBlock PDO copy with bias configured successfully");
}
finally
{
}
uint32_t NetworkIndexGet(RSINetworkIndexType indexType)
Get the PDO array index for an axis signal mapping.
NetworkNode * NetworkNode
Gets the associated NetworkNode object.
RSINetworkState NetworkStateGet()
void MemorySet(uint64_t address, int32_t data)
Write a value to controller memory.
void NetworkOutputOverrideSet(int32_t index, bool outputOverride)
Set NetworkOutputValue to override RMP cyclic value.
uint64_t NetworkOutputAddressGet(int32_t index)
Returns an Address of a Network Output.
uint64_t NetworkInputAddressGet(int32_t index)
bool Exists()
Returns true if this NetworkNode exists on a physical network.
RSINetworkState
State of network.
RSINetworkOutputAddressType
Network output address types.
RSINetworkIndexType
Network PDO index types for configuring axis input/output mappings.