APIs, concepts, guides, and more
mathblock-pdo-copy.cs
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 MathBlock: PDO Copy");
// set sample config params
const int MB_INDEX = 0;
const int BIAS = 8000;
const RSIDataType INT32 = RSIDataType.RSIDataTypeINT32;
const RSIMathBlockOperation ADD = RSIMathBlockOperation.RSIMathBlockOperationADD;
// get RMP controller
try
{
Helpers.CheckErrors(controller);
// check is network is started
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
{
Console.WriteLine("Network is not started. Please start the network before running this sample app.");
return;
}
// set mathblock count before any RapidCodeObject get/create other than the controller
controller.MathBlockCountSet(1);
// get & configure axis 0
Axis axis0 = controller.AxisGet(Constants.AXIS_0_INDEX);
axis0.ErrorLimitActionSet(RSIAction.RSIActionNONE);
axis0.Abort();
axis0.ClearFaults();
controller.SampleWait(10);
// get & configure axis 1
Axis axis1 = controller.AxisGet(Constants.AXIS_1_INDEX);
axis1.ErrorLimitActionSet(RSIAction.RSIActionNONE);
axis1.Abort();
axis1.ClearFaults();
controller.SampleWait(10);
// check axis are real and not phantom
if (!axis0.NetworkNode.Exists() || !axis1.NetworkNode.Exists())
{
Console.WriteLine("One or both axes are phantom (not real). Please use real axes for this sample app.");
return;
}
// write BIAS value to user buffer index 0
// if you want a dynamic bias, you can write to this address at any time or use the process value of another MathBlock instead
ulong userBufferAddr0 = controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER, 0);
controller.MemorySet(userBufferAddr0, BIAS);
// configure the MathBlock to copy a PDO value from axis 0 to a PDO override value on axis 1 with a BIAS offset
// here we are using the actual torque of axis 0 and the target torque of axis 1, but these can be replaced with whatever PDOs you want
// by changing the index values to the desired PDOs
uint torqueActualIndex = axis0.NetworkIndexGet(RSINetworkIndexType.NetworkIndexTypeTORQUE_ACTUAL_INDEX);
ulong torqueActualAddress = controller.NetworkInputAddressGet((int)torqueActualIndex);
uint targetTorqueIndex = axis1.NetworkIndexGet(RSINetworkIndexType.NetworkIndexTypeTARGET_TORQUE_INDEX);
ulong targetTorqueAddress = controller.NetworkOutputAddressGet((int)targetTorqueIndex, RSINetworkOutputAddressType.RSINetworkOutputAddressTypeOVERRIDE_VALUE);
// enable the network override to copy the MathBlock output to the PDO
// only needs to be set once, probably in initialization
controller.NetworkOutputOverrideSet((int)targetTorqueIndex, true);
// MathBlock config & set (mb.value = axis0.torqueActual + BIAS)
var mbConfig = controller.MathBlockConfigGet(MB_INDEX);
mbConfig.InputAddress0 = torqueActualAddress; // input0: axis 0 actual torque
mbConfig.InputAddress1 = userBufferAddr0; // input1: BIAS from user buffer
mbConfig.InputDataType0 = INT32;
mbConfig.InputDataType1 = INT32;
mbConfig.Operation = ADD; // switch to MULTIPLY for proportional bias
mbConfig.ProcessDataType = INT32;
mbConfig.OutputAddress = targetTorqueAddress; // output: axis 1 target torque override
mbConfig.OutputDataType = INT32;
// set MathBlock and wait 1 sample for config to take effect
controller.MathBlockConfigSet(MB_INDEX, mbConfig);
controller.SampleWait(1);
// print results
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");
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
Constants used in the C# sample apps.
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:13
const int AXIS_1_INDEX
Default: 1.
Definition _constants.cs:14
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Definition _helpers.cs:15
Helpers class provides static methods for common tasks in RMP applications.
Definition _helpers.cs:5
uint32_t NetworkIndexGet(RSINetworkIndexType indexType)
Get the PDO array index for an axis signal mapping.
NetworkNode * NetworkNode
Gets the associated NetworkNode object.
Definition rsi.h:5900
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5870
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
RSINetworkState NetworkStateGet()
void MathBlockCountSet(int32_t mathBlockCount)
Set the number of processed MathBlocks in the MotionController.
void MemorySet(uint64_t address, int32_t data)
Write a value to controller memory.
static MotionController * Get()
Get an already running RMP EtherCAT controller.
void NetworkOutputOverrideSet(int32_t index, bool outputOverride)
Set NetworkOutputValue to override RMP cyclic value.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
uint64_t NetworkOutputAddressGet(int32_t index)
Returns an Address of a Network Output.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
uint64_t NetworkInputAddressGet(int32_t index)
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...
Definition rsi.h:800
MathBlockConfig MathBlockConfigGet(int32_t mathBlockNumber)
Get a MathBlock configuration.
void MathBlockConfigSet(int32_t mathBlockNumber, MathBlockConfig &config)
Set a MathBlock configuration.
bool Exists()
Returns true if this NetworkNode exists on a physical network.
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void Abort()
Abort an axis.
RSIMathBlockOperation
MathBlock operations.
Definition rsienums.h:1431
RSINetworkState
State of network.
Definition rsienums.h:568
RSIControllerAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:405
RSIDataType
Data types for User Limits and other triggers.
Definition rsienums.h:659
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1115
RSINetworkOutputAddressType
Network output address types.
Definition rsienums.h:1412
RSINetworkIndexType
Network PDO index types for configuring axis input/output mappings.
Definition rsienums.h:1390