The RMP Motion Controller APIs
Homing.cs
1
45using RSI.RapidCode.dotNET; // Import our RapidCode Library.
46using NUnit.Framework;
47using System;
48
50class Homing : SampleAppTestBase
51 {
52 public void MasterBasedHoming()
53 {
54 //@[MasterBasedHoming]
55 axis.HardwareNegLimitActionSet(RSIAction.RSIActionSTOP); // Neg Limit action set to STOP.
56 axis.HomeMethodSet(RSIHomeMethod.RSIHomeMethodImprovedFALLING_HOME_NEGATIVE_START_POSITIVE_MOMENTUM); // Set the method to be used for homing.
57 axis.HomeVelocitySet(Constants.VELOCITY); // Set the home velocity.
58 axis.HomeSlowVelocitySet(Constants.VELOCITY / 10); // Set the slow home velocity. (used for final move, if necessary)
59 axis.HomeAccelerationSet(Constants.ACCELERATION); // Set the acceleration used for homing.
60 axis.HomeDecelerationSet(Constants.DECELERATION); // Set the deceleration used for homing.
61 axis.HomeOffsetSet(0.5); // HomeOffsetSet sets the position offset from the home (zero) position.
62
63 axis.Home(); // Execute the homing routine.
64
65 if (axis.HomeStateGet() == true) // HomeStateGet returns true if the Axis is homed.
66 {
67 Console.WriteLine("Homing successful\n");
68 }
69
70 axis.ClearFaults(); // Clear faults created by homing.
71 axis.AmpEnableSet(false); // Disable the motor.
72 //@[MasterBasedHoming]
73 }
74
75 public void HomingWithAKDdrive()
76 {
77 //@[HomingWithAKDdrive]
78
79 // 1. READY DRIVE
80 axis.OperationModeSet(RSIOperationMode.RSIOperationModeHOMING_MODE); // Mode of Operation set to Homing Mode.
81 axis.NetworkNode.AKDASCIICommand("DRV.OPMODE 2"); // Sets the drive operation mode (0 - current | 1 = velocity | 2 = position).
82 axis.NetworkNode.AKDASCIICommand("HOME.AUTOMOVE 0"); // 0 = Disabled | 1 = Homing starts when drive is enabled.
83
84 // Make sure you know your motor's position, velocity, and acceleration units before you send any values.
85
86 // 2. SET YOUR LIMIT SWITCHES
87 axis.NetworkNode.AKDASCIICommand("DIN5.MODE 18"); // Sets the digital input modes. - DI5 is now our Positive Limit Switch.
88 axis.NetworkNode.AKDASCIICommand("DIN5.INV 1"); // Sets the indicated polarity of a digital input mode. - DI5 is now active when Low.
89 axis.NetworkNode.AKDASCIICommand("DIN6.MODE 19"); // Sets the digital input modes. - DI6 is now our Negative Limit Switch.
90 axis.NetworkNode.AKDASCIICommand("DIN6.INV 1"); // Sets the indicated polarity of a digital input mode. - DI6 is now active when Low.
91
92 // 3. CONFIGURE DRIVE HOMING PARAMETERS
93 axis.NetworkNode.AKDASCIICommand("HOME.MODE 1"); // Selects the homing method. MODE1 = Find limit input
94 axis.NetworkNode.AKDASCIICommand("HOME.V 20");
95 axis.NetworkNode.AKDASCIICommand("HOME.ACC 200");
96 axis.NetworkNode.AKDASCIICommand("HOME.DEC 200");
97 axis.NetworkNode.AKDASCIICommand("HOME.DIR 0"); // Sets homing direction (0 = negative | 1 = positive)
98 axis.NetworkNode.AKDASCIICommand("HOME.P 0");
99 axis.NetworkNode.AKDASCIICommand("HOME.DIST 0");
100 axis.NetworkNode.AKDASCIICommand("HOME.MAXDIST 0");
101 axis.NetworkNode.AKDASCIICommand("HOME.IPEAK");
102
103 // 4. READY AXIS
104 axis.ErrorLimitActionSet(RSIAction.RSIActionNONE); //Set the action to none so we don't get a position error while the drive is in control.
105 axis.Abort(); // Disable axis.
106 axis.ClearFaults(); // Clear any faults.
107 axis.AmpEnableSet(true); // Enable the axis.
108 System.Threading.Thread.Sleep(100); // Allow time for amp enable
109
110 // 5. START HOMING
111 axis.NetworkNode.AKDASCIICommand("HOME.MOVE"); // Starts a homing procedure; active in opmode 2 (position) only.
112 Console.WriteLine("HOME.MOVE");
113
114 // 6. CHECK IF HOMING IS DONE
115 UInt16 statusWordValue;
116 int isHomedvalue = 0;
117 int axisIndex = axis.NumberGet();
118
119 while (isHomedvalue != 1) // When isHomedValue = 1, homing has finished.
120 {
121 statusWordValue = axis.NetworkNode.StatusWordGet(axisIndex);
122 isHomedvalue = statusWordValue >> 12; // Get the 12th bit only. This bit tells us homing is done when it goes HIGH.
123 }
124
125 Console.WriteLine("Axis homed.");
126
127 // 7. CLEAN UP
128 axis.OriginPositionSet(0.0);//Set the origin to 0, otherwise repeated use will not result in Rapidcode reporting 0 at the found home position.
129 axis.Abort(); // Disable the axis.
130 axis.OperationModeSet(RSIOperationMode.RSIOperationModeINTERPOLATED_POSITION_MODE); // Mode of Operation Restore
131 axis.ErrorLimitActionSet(RSIAction.RSIActionABORT);// Restore the position error action to whatever you want it to be.
132
133 //@[HomingWithAKDdrive]
134
135 }
136
137 public void HomingWithDS402drive()
138 {
139 //@[HomingWithDS402drive]
140
141 // Constants
142 const int AXIS_NUMBER = 0; // Specify which axis/motor to control.
143
144 // Homing Offset.
145 const int offsetIndex = 0x607C;
146 const int offsetSubindex = 0x0;
147 const int offsetByteSize = 4;
148 const int offsetValue = 0;
149
150 // Home Method
151 const int methodIndex = 0x6098;
152 const int methodSubindex = 0x0;
153 const int methodByteSize = 1;
154 const int methodValue = 24;
155
156 // Speed To Switch
157 const int targetSpeedIndex = 0x6099;
158 const int targetSpeedSubindex = 0x1;
159 const int targetSpeedByteSize = 4;
160 const int targetSpeedValue = 2;
161
162 // Speed to Zero
163 const int originSpeedIndex = 0x6099;
164 const int originSpeedSubindex = 0x2;
165 const int orignSpeedByteSize = 4;
166 const int originSpeedValue = 10;
167
168 // Homing Acceleration
169 const int accelerationIndex = 0x609A;
170 const int accelerationSubindex = 0x0;
171 const int accelerationByteSize = 4;
172 const int accelerationValue = 100;
173
174 //Desired DS402 Enabled Output.
175 const int CONTROL_WORD_TO_PREP_HOMING = 15;
176 const int CONTROL_WORD_TO_START_HOMING = 31;
177 const int ACCEPTABLE_DELAY_IN_MS = 20;
178 const int STATUS_WORD_TARGET_REACHED_BIT = 0x400; // Status Bit 10 (0x400) indicates Target Reached (Homing is Complete).
179 const int STATUS_WORD_HOMING_ATTAINED_BIT = 0x1000; // Status Bit 12 (0x1000) indicates Homing Attained (Homing is Successful).
180 const int STATUS_WORD_HOMING_ERROR_BIT = 0x2000; // Status Bit 13 (0x2000) indicates Homing Error (Homing ran into a problem).
181
182 int axisControlWordIndex = (int)axis.NetworkIndexGet(RSINetworkIndexType.NetworkIndexTypeCONTROL_WORD_INDEX);
183
184 // CONFIGURE (Writing to SDOs)
185 axis.NetworkNode.ServiceChannelWrite(offsetIndex, offsetSubindex, offsetByteSize, offsetValue); // Home Offset
186 axis.NetworkNode.ServiceChannelWrite(methodIndex, methodSubindex, methodByteSize, methodValue); // Home Method (Home type)
187 axis.NetworkNode.ServiceChannelWrite(targetSpeedIndex, targetSpeedSubindex, targetSpeedByteSize, targetSpeedValue); // Home Speed during search for switch
188 axis.NetworkNode.ServiceChannelWrite(originSpeedIndex, originSpeedSubindex, orignSpeedByteSize, originSpeedValue); // Home Speed during search for zero
189 axis.NetworkNode.ServiceChannelWrite(accelerationIndex, accelerationSubindex, accelerationByteSize, accelerationValue); // Home acceleration
190
191 axis.rsiControl.NetworkOutputOverrideValueSet(axisControlWordIndex, CONTROL_WORD_TO_PREP_HOMING); // Control Word should be 15 before Switching to Homing Mode.
192 axis.rsiControl.NetworkOutputOverrideSet(axisControlWordIndex, true); // Override Control Word.
193 controller.SampleWait(ACCEPTABLE_DELAY_IN_MS);
194 // Delay to give transitions time -or- setup something more complex to ensure drive is in the appropriate state.
195
196 axis.OperationModeSet(RSIOperationMode.RSIOperationModeHOMING_MODE);
197 controller.SampleWait(ACCEPTABLE_DELAY_IN_MS);
198
199 // HOME
200 axis.rsiControl.NetworkOutputOverrideValueSet(axisControlWordIndex, CONTROL_WORD_TO_START_HOMING); // Start Homing.
201 controller.SampleWait(ACCEPTABLE_DELAY_IN_MS); // Delay to give transitions time -or- setup something more complex to ensure drive is in the appropriate state.
202
203 UInt16 statusWordValue; // Takes the axis index. This will return the status word value.
204 bool cancelHome = false;
205
206 statusWordValue = axis.NetworkNode.StatusWordGet(AXIS_NUMBER);
207 while ((!cancelHome) && ((statusWordValue & STATUS_WORD_TARGET_REACHED_BIT) == 0)) // When Status Word Indicates Target Reached (Success or Fail) or external evaluator (cancelHome)
208 {
209 //A timeout that sets cancelHome would be a good idea for this while loop.
210 statusWordValue = axis.NetworkNode.StatusWordGet(AXIS_NUMBER); //Update.
211 //A short sleep or wait is appropriate so you can't spamming this call.
212 }
213
214 // 4. EVALUATE HOMING SUCCESS
215 if ((statusWordValue & STATUS_WORD_HOMING_ATTAINED_BIT) == 1)
216 {
217 Console.WriteLine("Axis homed.");
218 }
219 else if ((statusWordValue & STATUS_WORD_HOMING_ERROR_BIT) == 1)
220 {
221 Console.WriteLine("Error Occured during homing.");
222 }
223
224 //5. CLEAN UP
225 axis.AmpEnableSet(false); // Disable the axis.
226 axis.ClearFaults();
227 axis.rsiControl.NetworkOutputOverrideSet(axisControlWordIndex, false);
228 // Restore the mode of operation to the control mode you want to run in. For most, this will be RSIOperationModeCYCLIC_SYNCHRONOUS_POSITION_MODE.
229 axis.OperationModeSet(RSIOperationMode.RSIOperationModeCYCLIC_SYNCHRONOUS_POSITION_MODE);
230
231
232 //@[HomingWithDS402drive]
233 }
234
235 public void CustomHome()
236 {
237 //@[CustomHome]
238
239 // user defined options
240 //const RSIMotorDedicatedIn CAPTURE_SOURCE = RSIMotorDedicatedIn.RSIMotorDedicatedInHOME;
241
242 const int HOME_LIMIT_NETWORK_INDEX = 99; //You may want to discover this rather than hard code it.
243 const int HOME_LIMIT_SIG_BIT = 0;
244 const int LongTime = 15000;
245
246 var homeLimitAddress = controller.NetworkInputAddressGet(HOME_LIMIT_NETWORK_INDEX);
247 axis.HomeLimitCustomConfigSet(homeLimitAddress, HOME_LIMIT_SIG_BIT);
248 axis.HomeActionSet(RSIAction.RSIActionSTOP);
249
250 // Ready Axis
251 axis.Abort();
252 axis.ClearFaults();
253 axis.AmpEnableSet(true);
254
255 // commanding a velocity move. This program assumes that the Custom Home will trigger at some point.
256 axis.MoveVelocity(Constants.VELOCITY, Constants.ACCELERATION);
257
258 //wait (sleep) until motion done interrupt occurs
259 Boolean done = false;
260 while (!done)
261 {
262 RSIEventType eventType = controller.InterruptWait(LongTime);
263 switch (eventType)
264 {
265 case RSIEventType.RSIEventTypeMOTION_DONE:
266 done = true;
267 break;
268 case RSIEventType.RSIEventTypeTIMEOUT:
269 done = true;
270 break;
271 default:
272 break;
273 }
274 }
275
276 if ((controller.NetworkInputValueGet(HOME_LIMIT_NETWORK_INDEX) & HOME_LIMIT_SIG_BIT) > 0) //On Home Limit
277 {
278 axis.HomeStateSet(true);
279 }
280 else
281 {
282 //Evaluate why we aren't on custom home.
283 }
284
285 // setup Home Action (the home action will not trigger)
286 axis.HomeActionSet(RSIAction.RSIActionNONE);
287
288 axis.ClearFaults();
289 axis.AmpEnableSet(false);
290 //@[CustomHome]
291 }
292 }
uint32_t NetworkIndexGet(RSINetworkIndexType indexType)
Get the Network Index associated with a DS402 Axis Feature.
void HardwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Negative Limit Event triggers.
void HomeSlowVelocitySet(double velocity)
Set the slow home velocity.
void OriginPositionSet(double position)
Set the origin position.
void OperationModeSet(RSIOperationMode mode)
Set the axis operation mode.
void HomeVelocitySet(double velocity)
Set the home velocity.
NetworkNode * NetworkNode
Gets the associated NetworkNode object.
Definition rsi.h:5694
void HomeActionSet(RSIAction action)
Set the action that will occur when the Home Event triggers.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
void MoveVelocity(double velocity)
void Home()
Execute the homing routine.
void HomeDecelerationSet(double decel)
Set the decleration to be used for homing when using the switch is not detected before the HomeTravel...
void HomeStateSet(bool homed)
Set the home state.
void HomeAccelerationSet(double accel)
Set the deceleration used for homing.
void HomeMethodSet(RSIHomeMethod method)
Set the method to be used for homing.
bool HomeStateGet()
Get the home state.
void HomeLimitCustomConfigSet(uint64_t address, int32_t bitIndex)
void HomeOffsetSet(double offset)
Set the home offset.
void NetworkOutputOverrideValueSet(int32_t index, uint64_t outputValue)
Sets a PDO output directly.
void NetworkOutputOverrideSet(int32_t index, bool outputOverride)
Set NetworkOutputValue to override RMP cyclic value.
uint64_t NetworkInputValueGet(int32_t index)
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
uint64_t NetworkInputAddressGet(int32_t index)
char * AKDASCIICommand(const char *const command)
Send a Kollmorgen AKD ASCII command (NodeType must equal KOLLMORGEN_AKD)
void ServiceChannelWrite(int32_t index, int32_t subIndex, int32_t byteCount, int32_t sdoValue)
Write a number in the SDO.
uint16_t StatusWordGet(int32_t axisIndex)
Get the DS402 status word.
RSIEventType InterruptWait(int32_t milliseconds)
Suspend the current thread until an interrupt arrives from the controller.
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void AmpEnableSet(bool enable)
Enable all amplifiers.
void Abort()
Abort an axis.
int32_t NumberGet()
Get the axis number.
MotionController * rsiControl
Gets the parent MotionController object.
Definition rsi.h:4135
RSIEventType
Event Types or Status Bits.
Definition rsienums.h:911
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1051
RSIOperationMode
DS402 modes of operation.
Definition rsienums.h:1267
RSINetworkIndexType
Network index types for Axis.
Definition rsienums.h:1301