Can you elaborate on the function you describe, INT(tool/3)? I assume that is nearest integar of tool number divided by 3, but I don't see how that would work - tool 1/3 = face1, tool 2/3 =face1, tool3/3= face1?LOL - trust me - I've been doing this software sh1t for a loooooong time.
The real purpose of the check command on rotation was for the looping of multiple rotation steps, to be sure it doesn't 'push the button' again before it is seated at the end of prior loop, as this messes with the toolchanger. but I agree it is pretty redundant when we are already checking for motion at the end of the while loop before proceeding.
2 1 0
0
3 11
4 1 3 10
5 9
2
6 7 8
8 4 0
0
1 11
5 1 3 7
9 3
2
2 6 10
face = tool mod 4 (where face = 0 to 3 and tool = 0 to 11)
face = (tool - 1) mod 4 (face will still be 0 to 3 but that's fine)
selectedTool = getSelectedTool()
currentFace = (getCurrentTool() - 1) mod 4
targetFace = (selectedTool - 1) mod 4
'rotate turret required number of "clicks"
For click = 1 To (targetFace - currentFace + 4) Mod 4 'rotate accounting for rollover
ActivateSignal(OutputX) 'activate momentary command to rotate
While Not IsActive(InputX) Then 'wait for turret to move
Sleep (10)
Wend
DeActivateSignal(OutputX) 'deactivate momentary command
While IsActive(InputX) Then 'wait for turret to stop
Sleep (10)
Wend
Next
'not forgetting to update to the new tool
SetCurrentTool selectedTool
selectedTool = getSelectedTool()
currentFace = (getCurrentTool() - 1) mod 4
targetFace = (selectedTool - 1) mod 4
'rotate turret required number of "clicks"
For click = 1 To (targetFace - currentFace + 4) Mod 4 'rotate accounting for rollover
ActivateSignal(Output2) 'activate momentary command to rotate
While Not IsActive(Input2) 'wait for turret to move
Sleep (10)
Wend
DeActivateSignal(Output2) 'deactivate momentary command
While IsActive(Input2) 'wait for turret to stop
Sleep (10)
Wend
Next
'not forgetting to update to the new tool
SetCurrentTool selectedTool
current face = (1-1) mod 4 = 0div4 = 0, ok good so far
target face = (3-1) mod 4 = 2div4= 0, remainder of 0.5 = 1? (partial remainder?), answer should be 2 though, correct?
selectedTool = getSelectedTool()
currentTool = getCurrentTool()
currentFace = (currentTool - 1) Mod 4
targetFace = (selectedTool - 1) Mod 4
clicks = (targetFace - currentFace + 4) Mod 4
MsgBox "Selected Tool=" & selectedTool & _
" Current Tool=" & currentTool & _
" Current Face=" & currentFace & _
" Target Face=" & targetFace & _
" Clicks=" & clicks
SetCurrentTool selectedTool
So, in summary, the mod function doesn't care if it is 'a mod b' or 'b mod a', it just takes the remainder after dividing into the larger number? (That is what I meant by acting like a divisor, depending if the first integar is larger than second, would be a fraction at the start.)
Nick
OK, I think I understand the Mod function (Modulus) in Mach3 VB script, figured I'd post it here in case someone else needs to reference;
For 'a Mod b',
If a<b, uses full 'a' value as product. i.e. '2 mod 3' = 2. (this is what was confusing me).
If a > or = b, divide 'a' by 'b' and the remainder is your product. i.e. for '9 mod 4', 4 goes into 9 twice evenly (8 ), with a remainder of 1 so 1 is the product.
Hope this helps, it was confusing me, but now it is all clear! :D
And Stirling, you are absolutely right, it all works out correctly!
Nick