6using RSI.RapidCode.dotNET;
14public class MathBlockDifferenceOfPositionUserLimit : SampleApp
16 public override int Run()
23 const int MATHBLOCK_COUNT = 1;
24 const int AXIS_COUNT = 2;
25 const int USER_LIMIT_COUNT = 1;
28 const int FIRST_AXIS_INDEX = 0;
29 const int SECOND_AXIS_INDEX = 1;
30 const double USER_UNITS = 1048576;
33 const int MATHBLOCK_INDEX = 0;
36 const int USER_LIMIT_INDEX = 0;
37 const double MAX_POSITION_DIFFERENCE = 0.5 * USER_UNITS;
39 const int USER_LIMIT_DURATION = 0;
42 const double RELATIVE_POSITION = 2 * MAX_POSITION_DIFFERENCE;
43 const double VELOCITY = 1;
44 const double ACCELERATION = 10;
45 const double DECELERATION = 10;
46 const double JERK_PCT = 0;
65 HelperFunctionsCS.CheckErrors(controller);
70 HelperFunctionsCS.SetupControllerForHardware(controller);
74 HelperFunctionsCS.SetupControllerForPhantoms(controller, AXIS_COUNT,
new int[] { FIRST_AXIS_INDEX, SECOND_AXIS_INDEX });
84 HelperFunctionsCS.CheckErrors(axis0);
90 HelperFunctionsCS.CheckErrors(axis1);
97 HelperFunctionsCS.CheckErrors(multiAxis);
110 mathBlockConfig.InputAddress0 = axis0.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
111 mathBlockConfig.InputDataType0 =
RSIDataType.RSIDataTypeDOUBLE;
112 mathBlockConfig.InputAddress1 = axis1.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
113 mathBlockConfig.InputDataType1 =
RSIDataType.RSIDataTypeDOUBLE;
114 mathBlockConfig.ProcessDataType =
RSIDataType.RSIDataTypeDOUBLE;
122 Console.WriteLine(
"MathBlock configured to subtract the position of the second axis from the position of the first axis.");
132 Console.WriteLine(
"UserLimit configured to trigger when the absolute position difference is greater than " + MAX_POSITION_DIFFERENCE +
" and abort motion.");
135 Console.WriteLine(
"Moving the axes to trigger the UserLimit...");
137 axis0.
MoveRelative(RELATIVE_POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PCT);
148 Console.WriteLine(
"Both axes are in the error state after the UserLimit triggered (This is the intended behavior).");
153 Console.WriteLine(
"Error: The axes should be in an error state after the UserLimit triggers, but they are not.");
154 Console.WriteLine(
"First Axis State: " + axis0.
StateGet());
155 Console.WriteLine(
"Second Axis State: " + axis1.
StateGet());
161 Console.WriteLine(
"Error: " + e.Message);
172public class MathBlockCalculateAccelerationFromVelocity : SampleApp
174 public override int Run()
181 const int MATHBLOCK_COUNT = 2;
182 const int AXIS_COUNT = 1;
185 const int AXIS_INDEX = 0;
186 const double USER_UNITS = 1048576;
189 const int SUBTRACTION_MATHBLOCK_INDEX = 0;
192 const int PREVIOUS_VELOCITY_MATHBLOCK_INDEX = 1;
193 const double ONE = 1.0;
194 const int USERBUFFER_INDEX = 0;
197 const double VELOCITY = 1.0;
198 const double ACCELERATION = 0.123;
201 USE_HARDWARE =
false;
216 HelperFunctionsCS.CheckErrors(controller);
221 HelperFunctionsCS.SetupControllerForHardware(controller);
225 HelperFunctionsCS.SetupControllerForPhantoms(controller, AXIS_COUNT,
new int[] { AXIS_INDEX });
236 HelperFunctionsCS.CheckErrors(axis);
250 subtractionConfig.InputAddress0 = axis.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
251 subtractionConfig.InputDataType0 =
RSIDataType.RSIDataTypeDOUBLE;
254 subtractionConfig.InputDataType1 =
RSIDataType.RSIDataTypeDOUBLE;
255 subtractionConfig.ProcessDataType =
RSIDataType.RSIDataTypeDOUBLE;
259 previousVelocityConfig.InputAddress0 = axis.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
260 previousVelocityConfig.InputDataType0 =
RSIDataType.RSIDataTypeDOUBLE;
262 previousVelocityConfig.InputDataType1 =
RSIDataType.RSIDataTypeDOUBLE;
263 previousVelocityConfig.ProcessDataType =
RSIDataType.RSIDataTypeDOUBLE;
268 controller.
MathBlockConfigSet(PREVIOUS_VELOCITY_MATHBLOCK_INDEX, previousVelocityConfig);
291 Console.WriteLine($
"Calculated acceleration from MathBlock: {calculatedAcceleration}");
294 if (Math.Abs(calculatedAcceleration - ACCELERATION) <= 0.000001)
296 Console.WriteLine(
"The MathBlock is calculating the Axis' acceleration by subtracting previous velocity from current velocity.");
301 Console.WriteLine(
"Error: The MathBlock is not calculating the Axis' acceleration as expected.");
307 Console.WriteLine(
"Error: " + e.Message);
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, Sequencers, 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, Sequencers, etc.
RSIUserLimitTriggerType
Trigger types for UserLimits.
MathBlock configuration structure.
double Double
Double precision (64-bit) floating-point.