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