DonNH Posted March 1, 2024 Report Posted March 1, 2024 Again, I'm missing something basic here . . . . So the Sysmac reference materials I've looked at give some details about the FOR function block, but I haven't seen anything telling me how I would actually call it up. The FOR and NEXT functions have to be attached to the left side of the ladder, so I can't insert an input to initiate the loop. Can anyone give me the basics of how I would place a loop like this in a ladder program, or direct me to more info? As is, it will run as soon as the PLC (or Simulation) is fired up. Quote
chelton Posted March 2, 2024 Report Posted March 2, 2024 (edited) You are correct that you can't create an input condition to the "FOR" loop using the "FOR" instruction, so it runs every time the task is scanned. However you can easily just use inline ST (structured text) and have input conditions before the inline ST block. Edited March 2, 2024 by chelton typo Quote
DonNH Posted March 4, 2024 Author Report Posted March 4, 2024 Seems like that severely limits the usefulness of the function. I want to use it to check to see if an ARCL function block actually succeeded (I'm getting occasional short network drops), and reissue the command if necessary.. I believe these function blocks can also be called through ST, but the documentation doesn't show the syntax. I've worked out the ladder code to run through a couple passes just by repeating the command, but that would get pretty clunky if I want it to try several times. Quote
chelton Posted March 4, 2024 Report Posted March 4, 2024 Do you really need to loop within the same scan cycle? If it's comm's responses your wanting to see if it succeed or not i don't think a "for" loop is the correct solution. Quote
DonNH Posted March 4, 2024 Author Report Posted March 4, 2024 So I guess maybe I'm looking at this wrong - will a For , Next ladder loop always happen within a single scan cycle? I actually want to wait about a second after the function block is issued, then check its Status variable and act accordingly. I just want the check and command reissue to happen within a loop rather than duplicating the code multiple times. Is there a different looping structure to use within ladder? Quote
Str8jCkt Posted March 4, 2024 Report Posted March 4, 2024 (edited) @DonNH Use the Omron help for any functions, they can be very informative. Select the function and F1 to go to the help. FOR loops do execute the entire loop within a single PLC scan so like @chelton said it is probably not the correct solution for what you are wanting to do. Without really seeing how you are doing you commands, if you are wanting to check a condition every second then maybe you can just use the Get1sClk instruction. Would look something like this. This assumes the Start_enabled bit is latched on the entire time after you execute your function. on a Failed state you would probably reset your function execute and then issue the command again if it has been turned off. Edited March 4, 2024 by Str8jCkt Quote
DonNH Posted March 4, 2024 Author Report Posted March 4, 2024 In ST, I think this is what it would basically look like. The ARCLGotoXXX would be the function block I'm currently using, in the correct ST syntax. Ladder syntax shown here. TP_3 line is just a 1 second wait before verifying command receipt. IF function checks to see if the function block's Status variable is showing 'Going to Goal'. If not, then there was a communication loss at that moment, so we'll count the failure then loop back & try reissuing the command, in this case up to 5 times total. Quote
chelton Posted March 4, 2024 Report Posted March 4, 2024 @DonNH You shouldn't use timers within a FOR loop. In your case your timer will never timeout. The loop will iterate the 5 times instantly then finish. You need to monitor the status of the FB after you have executed, then if you don't get the desired result after xxx time/counts then re-execute the FB. Quote
DonNH Posted March 4, 2024 Author Report Posted March 4, 2024 Ok, but I have no idea what that would look like. Quote
DonNH Posted March 4, 2024 Author Report Posted March 4, 2024 So I added ladder logic to the existing program which checks the status once, and if it's not correct, tries again before stopping. However, it's now giving me a weird problem: The Status variable of the function block typically returns as "Command Sent" when first triggered, very quickly changing to "Going to Goal", once the robot responds that it has received the command. However, once I added the code to act upon that info, it stays on "Command Sent" indefinitely. I can't see anything I've done to change the way it is called - will look harder. When I reload the original program, I'm back to normal. Looks like a variation on the Heisenberg Principal - you can observe the status or act on it, but not both. Quote
BE Posted March 4, 2024 Report Posted March 4, 2024 I haven't looked at this thoroughly, so apologies if I have misunderstood. But instead of using a For Loop, why not just have a integer variable that is your incrementing counter, and then add an additional condition to your IF statement where that integer must be <=5 (less than or equal to 5) for the statement to proceed. The integer would be set to 1 (or 0, depending on what you need) using a one shot of the start_enabled bit to initiate the process. This way you can incorporate the timer side of things quite easily. 1 Quote
DonNH Posted March 5, 2024 Author Report Posted March 5, 2024 (edited) So I obviously got hung up on the fact that there is a FOR loop within Sysmac, and didn't realize its limitations. After pondering on the comments here, it finally clicked that I should be able to create a fairly simple While loop. I think this should work: (Conceptual ladder program, using a TP as a stand-in for the ARCL Goto function block, and taking some liberties with data types in order to keep it visually clean). I still need to figure out why the Status variable isn't kicking back correctly, as noted in my last post - maybe this structure will work correctly for some reason. Edited March 5, 2024 by DonNH update ladder diagram Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.