10using RSI.RapidCode.dotNET;
18public class MathBlockDifferenceOfPositionUserLimit : SampleApp
20 public override int Run()
27 const int MATHBLOCK_COUNT = 1;
28 const int AXIS_COUNT = 2;
29 const int USER_LIMIT_COUNT = 1;
32 const int FIRST_AXIS_INDEX = 0;
33 const int SECOND_AXIS_INDEX = 1;
34 const double USER_UNITS = 1048576;
37 const int MATHBLOCK_INDEX = 0;
40 const int USER_LIMIT_INDEX = 0;
41 const double MAX_POSITION_DIFFERENCE = 0.5 * USER_UNITS;
43 const int USER_LIMIT_DURATION = 0;
46 const double RELATIVE_POSITION = 2 * MAX_POSITION_DIFFERENCE;
47 const double VELOCITY = 1;
48 const double ACCELERATION = 10;
49 const double DECELERATION = 10;
50 const double JERK_PCT = 0;
114 mathBlockConfig.InputAddress0 = axis0.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
115 mathBlockConfig.InputDataType0 =
RSIDataType.RSIDataTypeDOUBLE;
116 mathBlockConfig.InputAddress1 = axis1.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
117 mathBlockConfig.InputDataType1 =
RSIDataType.RSIDataTypeDOUBLE;
118 mathBlockConfig.ProcessDataType =
RSIDataType.RSIDataTypeDOUBLE;
126 Console.WriteLine(
"MathBlock configured to subtract the position of the second axis from the position of the first axis.");
136 Console.WriteLine(
"UserLimit configured to trigger when the absolute position difference is greater than " + MAX_POSITION_DIFFERENCE +
" and abort motion.");
139 Console.WriteLine(
"Moving the axes to trigger the UserLimit...");
141 axis0.
MoveRelative(RELATIVE_POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PCT);
152 Console.WriteLine(
"Both axes are in the error state after the UserLimit triggered (This is the intended behavior).");
157 Console.WriteLine(
"Error: The axes should be in an error state after the UserLimit triggers, but they are not.");
158 Console.WriteLine(
"First Axis State: " + axis0.
StateGet());
159 Console.WriteLine(
"Second Axis State: " + axis1.
StateGet());
165 Console.WriteLine(
"Error: " + e.Message);
176public class MathBlockCalculateAccelerationFromVelocity : SampleApp
178 public override int Run()
185 const int MATHBLOCK_COUNT = 2;
186 const int AXIS_COUNT = 1;
189 const int AXIS_INDEX = 0;
190 const double USER_UNITS = 1048576;
193 const int SUBTRACTION_MATHBLOCK_INDEX = 0;
196 const int PREVIOUS_VELOCITY_MATHBLOCK_INDEX = 1;
197 const double ONE = 1.0;
198 const int USERBUFFER_INDEX = 0;
201 const double VELOCITY = 1.0;
202 const double ACCELERATION = 0.123;
205 USE_HARDWARE =
false;
254 subtractionConfig.InputAddress0 = axis.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
255 subtractionConfig.InputDataType0 =
RSIDataType.RSIDataTypeDOUBLE;
258 subtractionConfig.InputDataType1 =
RSIDataType.RSIDataTypeDOUBLE;
259 subtractionConfig.ProcessDataType =
RSIDataType.RSIDataTypeDOUBLE;
263 previousVelocityConfig.InputAddress0 = axis.
AddressGet(INPUT_AXIS_ADDRESS_TYPE);
264 previousVelocityConfig.InputDataType0 =
RSIDataType.RSIDataTypeDOUBLE;
266 previousVelocityConfig.InputDataType1 =
RSIDataType.RSIDataTypeDOUBLE;
267 previousVelocityConfig.ProcessDataType =
RSIDataType.RSIDataTypeDOUBLE;
272 controller.
MathBlockConfigSet(PREVIOUS_VELOCITY_MATHBLOCK_INDEX, previousVelocityConfig);
295 Console.WriteLine($
"Calculated acceleration from MathBlock: {calculatedAcceleration}");
298 if (Math.Abs(calculatedAcceleration - ACCELERATION) <= 0.000001)
300 Console.WriteLine(
"The MathBlock is calculating the Axis' acceleration by subtracting previous velocity from current velocity.");
305 Console.WriteLine(
"Error: The MathBlock is not calculating the Axis' acceleration as expected.");
311 Console.WriteLine(
"Error: " + e.Message);
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.