-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMotionHoldReleasedByPosition.cs
106 lines (87 loc) · 8.35 KB
/
MotionHoldReleasedByPosition.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*!
* @example MotionHoldReleasedByPosition.cs
* @page motion-hold-released-by-position-cs MotionHoldReleasedByPosition.cs
* @brief Motion Hold Move Released By Position sample application.
* @details This sample code is done in AKD Drive with one Actual Axis and one Phantom Axis. It can be applied to two Phatom Axis or two Actual Axis with the slight changes of code which is guided in comment.
* @pre This sample code presumes that the user has set the tuning paramters(PID, PIV, etc.) prior to running this program so that the motor can rotate in a stable manner.
* @warning This is a sample program to assist in the integration of your motion controller with your application. It may not contain all of the logic and safety features that your application requires.
* @copyright
Copyright © 1998-2019 by Robotic Systems Integration, Inc. All rights reserved.
This software contains proprietary and confidential information of Robotic
Systems Integration, Inc. (RSI) and its suppliers. Except as may be set forth
in the license agreement under which this software is supplied, disclosure,
reproduction, or use with controls other than those provided by RSI or suppliers
for RSI is strictly prohibited without the prior express written consent of
Robotic Systems Integration.
*
* @include MotionHoldReleasedByPosition.cs
*/
using RSI.RapidCode.dotNET;
using RSI.RapidCode.dotNET.Enums;
using System;
namespace SampleAppsCS
{
class MotionHoldReleasedByPosition
{
static void Main(string[] args)
{
// Constants
const int HOLDING_AXIS_INDEX = 1; // Specify which axis/motor to control.
const int MOVING_AXIS_INDEX = 0; // Specify which axis/motor to control.
const double TRIGGER_POS = 5; // Specify the position that will be evaluted on triggering/releasing motion
const int USER_UNITS = 1048576; // Specify USER UNITS
// Initialize RapidCode Objects
MotionController controller = MotionController.CreateFromSoftware(/*@"C:\RSI\X.X.X\"*/); // Insert the path location of the RMP.rta (usually the RapidSetup folder) (This sample app used RMP 8.0.1).
SampleAppsCS.HelperFunctions.CheckErrors(controller); // [Helper Function] Check that the controller has been initialize correctly.
SampleAppsCS.HelperFunctions.StartTheNetwork(controller); // [Helper Function] Initialize the network.
controller.AxisCountSet(2); // Specify two Axis in controller
// Initiazlize Axes: holdingAxis and movingAxis
Axis holdingAxis = controller.AxisGet(HOLDING_AXIS_INDEX); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
SampleAppsCS.HelperFunctions.CheckErrors(holdingAxis); // [Helper Function] Check that the axis has been initialize correctly.
Axis movingAxis = controller.AxisGet(MOVING_AXIS_INDEX); // Initialize HoldAxis Class. (Use RapidSetup Tool to see what is your axis number)
SampleAppsCS.HelperFunctions.CheckErrors(movingAxis); // [Helper Function] Check that the axis has been initialize correctly.
try
{
controller.AxisCountSet(2); // Set the number of axis being used. A phantom axis will be created if for any axis not on the network. You may need to refresh rapid setup to see the phantom axis.
// GET HOLD AXIS READY
holdingAxis.UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
holdingAxis.PositionSet(0); // Make sure motor starts at position 0 everytime.
holdingAxis.ErrorLimitTriggerValueSet(1000); // Specify the position error limit trigger. (Learn more about this on our support page)
holdingAxis.Abort(); // If there is any motion happening, abort it.
holdingAxis.ClearFaults(); // Clear faults.>
holdingAxis.AmpEnableSet(true); // Enable the motor.
// GET MOVE AXIS READY
movingAxis.ErrorLimitActionSet(RSIAction.RSIActionNONE); // If NOT using a Phantom Axis, switch to RSIActionABORT
movingAxis.UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
movingAxis.PositionSet(0); // Make sure motor starts at position 0 everytime.
movingAxis.ErrorLimitTriggerValueSet(1000); // Specify the position error limit trigger. (Learn more about this on our support page)
movingAxis.Abort(); // If there is any motion happening, abort it.
movingAxis.ClearFaults(); // Clear faults.>
movingAxis.AmpEnableSet(true); // Enable the motor.
// SET UP MOTION HOLD // Condition/Configuration to the Axis(movingAxis) that will hold Motion and its Position that will trigger/release motion
holdingAxis.MotionHoldTypeSet(RSIMotionHoldType.RSIMotionHoldTypeAXIS_COMMAND_POSITION); // Use RSIMotionHoldTypeAXIS_ACTUAL_POSITION if it is not Phantom Axis.
holdingAxis.MotionHoldAxisNumberSet(movingAxis.NumberGet()); // Specify motion hold to the Axis(movingAxis) whose position will hold the motion of holdingAxis.
holdingAxis.MotionHoldAxisPositionSet(USER_UNITS * TRIGGER_POS); // Specify motion hold position which is the movingAxis's position(need to multiply with USER_UNITS to get correct position value) to trigger/release the motion of holdingAxis.
holdingAxis.MotionHoldAxisLogicSet(RSIUserLimitLogic.RSIUserLimitLogicGE); // Specify the logic condition that will be evaluated to trigger/release motion based on the SET POSITION(USER_UNITS * TRIGGER_POS).In this case, GT(Greater than or Equal to) motion hold position limit to release
// SET MOTION HOLD ON
holdingAxis.MotionAttributeMaskOnSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD); // Set the HOLD motion attribute mask ON. (This initializes the HOLD on a particular motion)
holdingAxis.MoveRelative(10); // Command simple relative motion(This motion will be hold by condition above until movingAxis's Position passes motion hold position limit)
// Release MOTION HOLD
movingAxis.MoveRelative(10); // Move movingAxis.MovingAxis's position reaches its MotionHold Position limit(in this case, limit is 5). It will trigger/release motion on holdingAxis (holidingAxis will move relatively 10).
movingAxis.MotionDoneWait();
holdingAxis.MotionDoneWait();
// Abort and Clear Faults
holdingAxis.Abort();
holdingAxis.ClearFaults();
movingAxis.Abort();
movingAxis.ClearFaults();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("\nPress Any Key To Exit"); // Allow time to read Console.
Console.ReadKey();
}
}
}