Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: rufan on July 20, 2013, 02:06:21 PM
-
During the toolchange the Z-axis needs to move to Z130 position but I got a ismoving() error message. See Sub MoveZ
This only happens when the routine: '-----If spindle RPM =0 and not Aligned ----- ' and '----- If spindle RPM > 10 and not Aligned ----' are executed
If routine '----- If spindle RPM =0 and Aligned ----' is used every thing works perfect.
Already tried this but does not help
While ismoving While ismoving()
Wend Wend
While ismoving While ismoving
sleep 10 Sleep 10
Wend Wend
I have no idea what is causing the problem, any suggestion.
This is a part of the code:
Sub AlignSpindle
'-------------------- If spindle RPM =0 and Aligned -------------------------
If GetOemDro(39) <10 Then
If isactive(INDEX) And isactive(OEMTRIG1) Then
ActivateSignal(OUTPUT9) 'Activate Locking Pin
Exit Sub
End If
End If
'-------------------- If spindle RPM =0 and not Aligned ---------------------
If GetOemDro(39) <10 Then
Code"M4S10"
ActivateSignal(OUTPUT9) 'Activate Locking Pin
While Not isactive(INDEX) And Not isactive(OEMTRIG1)
sleep 10
Wend
code"M5"
End If
'-------------------- If spindle RPM > 10 and not Aligned -------------------
'--------------------------- Dynamic spindle braking ------------------------
If GetOemDro(39) > 10 Then 'Get True spindle
code"M4S1000" 'Start spindle CCW to brake
While getOEMdro(39) > 100 'Check if spindle speed above 100rpm
sleep 1
If getOEMdro(39) > 100 Then
activateSignal(OUTPUT6) 'Activate Spindle ENABLE
sleep 50
deactivateSignal(OUTPUT6) 'deActivate Spindle ENABLE
End If
Wend
ActivateSignal(OUTPUT9) 'Activate Locking Pin
code"M4S10"
While Not isactive(INDEX) And Not isactive(OEMTRIG1)
sleep 10
Wend
code"M5"
End If
'---------------------- Double Check Spindle Index Alignment -----------------------
If Not isactive(INDEX) And Not isactive(OEMTRIG1) Then MsgBox("Tool Alignment Fail")
End Sub
'----------------------------------------------------------------------------
'----------------------------------------------------------------------------
Sub MoveZ
code "G1 G53 Z130 F3000" 'Move Z-Axis to tool change position
While ismoving()
Wend
End Sub
-
I would hazard a guess that the "call" for M4 may be the problem. It's a no no to call a macro from a macro.
Ian
-
I was also thinking about that but just didn't try that.
Now I change the code, for code"M4" I put:
'----M4-------- 'Start spindle CCW to brake
DoSpinCCW() 'Enable CCW Relay
ActivateSignal(OUTPUT6) 'Spindle enable
This didn't solve the problem with getting the error message line 134 error (while ismoving)
I keep playing around with vb, and found out vb is jumping so fast from 1 sub to another and I think this is causing the issue.
I put sleep 200 before (End Sub), and until now the problem seems to be solved.
-
without seeing all of your code I can't comment.
-
Attachment the M6Start version with the ismoving error on Ln-124
-
first thing that jumps out is you're explicitly declaring sleep. (Have you been reading the wiki by any chance?) there's no need to do this - sleep is already "internally" declared for you. Before I look any further you could take that first line out and see if it helps. Let me know.
-
I have read the wiki and there I found this line (Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long))
http://www.machsupport.com/Mach3Wiki/index.php?title=Mach_specific_Subroutines/Functions_grouped_by_purpose (http://www.machsupport.com/Mach3Wiki/index.php?title=Mach_specific_Subroutines/Functions_grouped_by_purpose)
I will remove this line tonight and perform a test, I will post the results.
Many thanks to look at my code.
-
Yes I know - that was why I asked - ignore it - it's presumably an old instruction and is now out of date.
-
Removed the Declare sleep line, but still fails.
From what I can visual see is: Spindle is turning to move to index position, but at the same time Z-Axis is going to move.
When this happens I get the ismoving error.
So vb is jumping out of a sub to the next before finishing the task.
-
You have some logic in there that would make me uneasy if it were mine. I'm always slightly dubious of the practice of putting in random sleeps when there are issues that should be sorted first.
Example: I'm not sure what your reasons are but you appear to be starting and stopping the spindle twice each time. DoSpinCCW AND activateSignal(OUTPUT6) and then deActivateSignal(OUTPUT6) AND DoSpinStop(). Why are you doing that?
And: Did you intend to potentially engage the lock pin when the spindle is doing anywhere between 0 and 100 rpm?
-
OUTPUT6 activate the start/stop of the DC Thyristor Speed Controller.
Because this controller has no option to change motor direction.
I have put 2 relays that change the potential of the motor armature.
YES the locking pin shoot out when RPM is lower than 100.
Locking pin is spring loaded so no problem.
Actually the reason why <100, because vb is so slow in reading the RPM.
When vb see 100RPM the real actual RPM is already lower, so to save time I put <100, rather than wait for 0RPM
I have change the macro a little bit, and now it's working perfect without failing and without the sleep.
I will upload the new macro tomorrow I forgot to take it with me.
-
Still troubleshooting the Toolchange macro, not bullet proof yet.
I have change the macro a little bit. Toolchange run much better but still fail 1 out of 10 times.
Error line: 124 (while ismoving)
Also it is taking a long time to align the spindle don't know why or is vb that slow.
Watch movie:http://youtu.be/g4gQXqF95yI (http://youtu.be/g4gQXqF95yI)
Any better vb will be nice.
-
Well you still have questionable logic in there. Also - why have you re-instated the API sleep - didn't you believe my earlier answer? Also - the while isMoving that fails should have a short sleep in it. I'm not saying this is WHY it fails or that it will fix your problem but it's not good practice.
Re: the speed of VB (CB) - trust me it's way faster than your mechanics - this is NOT the reason for slowness.
BTW - can you explain exactly what INDEX and OEMTRIG1 do? - I'm not sure why you appear to need TWO signals for alignment?
-
Damm uploaded the wrong file. This one is the one I use at the moment.
I have a double opto switch with a gap of 5mm. One output is INDEX and the other is OEMTRIG1.
Because the spindle needs to be very perfect aligned, I have used this dual opto switch.
So when both opto switch are triggered, the spindle is perfect aligned. The gap in the trigger ring is about 5,5mm.
I also tried below but did not help.
While ismoving
sleep 10
wend
About the speed.
When the spindle is stopped by the dynamic brake, it take some seconds before the spindle turn CCW to align spindle.
It looks like the command GetOEMDro(39) takes a while. When observe the spindle speed DRO, I notice that the DRO has a refresh delay compared to the real spindle speed.
-
Dear Stiling,
Witch logic do you think is still questionable?
I want to make this tool-change bullet proof.
Thanks