I'm writing here a memorandum of lessons I learned in my fifteen year career as an industrial programmer. Emphasis on code, communication protocols, and electrical tips
Don't wanna be here? Send us removal request.
Text
STRUCTS or UNIONS (Sysmac Studio)
Structures are useful when you need to convert one or more variables of some data types to another data type. You can also use them for groups of data akin to object oriented programming.
Unions are useful when you need to use some bits of a variable as a single data type on the fly. They let you map the same bits of data as either BOOL or INT or whatever, and use them at the same time for different purposes.
Think of STRUCTS as monolithic variable declaration, where everything needs its boundaries, and UNIONS as organic variable declaration, where different members can overlap and share memory.
Aside from using STRUCTS as classes, I use them mostly for decomposing large data types into an array of bool to use as contacts in ladder.
Instead of mapping every single BOOL of this servodrive Digital inputs group, assign a global variable to the parent DWORD:
Go to Data Types and create a new Data Type with an array of bool for the total byte size of DWORD (32 bits):
Note: set Offset Type to User, and make sure you respect the starting and ending bytes and bits. If you are projecting a total byte size of 2, and you set some member to Offset Byte 3, it won't compile as the size of the struct won't match the size of the variable.
Go to Global Variables and change the Data Type of the assigned variable to your STRUCT:
Now you can use the DWORD variable as single contacts in ladder:
0 notes
Text
Power on a dead Omron CPM1A to retrieve the program
I managed to backup the program of an Omron CPM1A-20CDR with a busted power supply. The PLC has a power supply board (220VAC input) resting on the bottom, that feeds 24VDC for the I/O relay circuit (CN201) and 5VDC for the computing logic (CN204) to the upper motherboard.
In this case the fuse in the 220VAC line in the board exploded, so the motherboard was undamaged. If you have a spare controller you can disassemble the shell and swap the motherboards - if you don't you just need to connect the CN204 pins to a 5VDC power supply to get the CPU and the port working.
Note: this is a european model so the pinout and arrangement may change.
I uploaded everything (program, configuration, memory channels) from the motherboard and downloaded it all to a new controller. Worked!
0 notes
Text
Setting up Ethernet/IP connection between a Yaskawa Motoman robot (YRC1000) and a Omron NX PLC (Sysmac Studio)
Note: this is the same exact procedure for a Motoman DX100/DX200.
First of all you need to declare a global variable or multiple global variables that will hold all the information the robot is going to send and receive. In this case a STRUCT fits perfectly. Read this article on why and how to build a STRUCT:
Whether you use a single variable, a STRUCT or multiple variables, the total byte size needs to match the parameter you will be setting up in the robot.
Declare your variables as global and set the Network Publish parameter:
Example: Robot_IN is the output from the robot sent to the PLC, therefore it's an input to the PLC, so the Network Publish parameter is set to Input.
Note: inputs and outputs don't have to have the same size. You can use a 16byte input and a 8byte output.
Now go to main window, Tools, Ethernet/IP Connection Settings, right click on the PLC, Edit, Registration All, select your Ethernet/IP variables, and click Register:
Go to the second menu Connection and install your EDS file:
Add the target device from the Toolbox:
Back on the Connection menu add the device and select it from the display list. Choose the variables you previously registered for the Originator Variable field and write the size. Write the target name so they match their instance names, keeping in mind they are reversed (the input instance in Sysmac Studio is the output instance in YRC1000).
Click Transfer to Controller and reboot the PLC.
Power on the YRC1000 in Maintenance Mode to set up the Ethernet/IP connection. Please refer to manual 181389-1CD for an in depth guide.
In LAN INTERFACE SETTING, set the IP ADDRESS SETTING for the physical LAN port you are using to the same IP address you wrote earlier in Sysmac Studio, when adding a target device.
In Ethernet/IP (CPU BOARD) DETAIL, set Ethernet/IP to USED:
Go to ADAPTER DETAIL, set ADAPTER to ENABLE, and set the rest of parameters so they match your PLC configuration:
Leave CONFIGURATION SIZE to 1 word, and CONFIGURATION INSTANCE to something that is not used by another.
Keep hitting the ENTER key on the pendant to apply the changes until you go back to the main screen. If the I/O allocation was set to auto, your first input/output should start at #33 in the robot, but it depends on the hardware configuration.
Note: the easiest way to find out is to navigate through the universal input/output menu by clicking the NEXT PAGE key on the pendant.
Read this other article on how to use groups of inputs to generate more complex data in a Motoman controller:
Note: the parameters in both Sysmac Studio and YRC1000 shown here are actual working examples.
0 notes
Text
Setting up a Yaskawa servodrive (SGD7) and a Omron NX PLC (Sysmac Studio)
I purchased a Yaskawa SGD7W servodrive to control two Yaskawa SGM7 0.75kW servomotors. It took me three weeks to get them moving. Omron's fault, to be honest.
Add the drive to the EtherCAT list, and go to Edit Module Configuration:
Select the motor and go to Edit PDO Map Settings, select the already selected Input/Output value, and add/remove PDO entries (by Add PDO Entry/Delete PDO Entry buttons) so they look just like in the picture:
Output PDOs
Input PDOs
Note: these PDOs are the minimum necessary for position control. Your PDOs should change if you need some other kind of motion control.
Go to I/O Map and register the Digital inputs PDO we assigned earlier to a global variable:
You will need these inputs so you can skip the predefined homing process of Sysmac Studio, and do your own (no luck here).
Read this article on how to map a large variable to an array of contacts for easier programming:
Next, go to Motion Control, Axis Settings, Axis Basic Settings, display the Detailed Settings list, and unassign every input from the drive.
This is necessary for the controller to pass the inputs to your global variable.
Go to Homing Settings and ensure Homing Method is set to Zero position preset.
This is it. From now on you can use MC_MoveJog or whatever to get the motor to the NOT/HOME position, using MC_Stop when the signal fires, and set the Homed flag by using MC_Home.
Note: this has been working for the past +4 years with two servomotors that move in sync. As a matter of fact I ended up doing this for every servomotor that I use, no matter the brand (including Omron). With Omron motors, however, you can skip the PDO setting step.
0 notes
Text
HMI timer in a Omron NX PLC (Sysmac Studio)
Read my previous article on how to declare CJ-like variables in Sysmac Studio:
Now register a global variable to hold the timer value:
Data type should be large enough to hold as much precision as you need. UINT, in the example, can hold up to 16384 (miliseconds, seconds, minutes, whatever). Unsigned data types offer double the size than their signed counterparts.
Convert your global variable to TIME type, by using the NanoSecToTime function, to use it as an input in a timer:
NanoSecToTime needs a LINT variable, so you have to multiply by the correct power.
Example: Timer_Vacuum holds miliseconds. Multiply by 10^6 to get the NANOSEC value.
0 notes
Text
Setting tagless CJ-like memory (CIO, W, H, D) in a Omron NX PLC (Sysmac Studio)
If you are using an HMI with the older fixed address memory channel logic of the CP/CJ series of Omron PLCs, with the newer NX models, you have to enable the following setting in Sysmac Studio:
And register global variables:
Keep in mind that some channels will ask you to make them retainable, CIO/H/W take one byte, and D take two. Consult the IEC61131-3 for a list of variable sizes:
Example: REAL takes four bytes, so the first variable needs D210 and D211 (4/2). If you don't respect their sizes you will get gibberish results.
0 notes
Text
IF/ELSE (or semaphore) in ladder
Consider this logic:
Ladder doesn't have an IF/ELSE statement, but you can code something that looks similar. Just please focus on the Step1 value.
Step1 goes from 0 to 1 to 2 within the same rung, in the same execution cycle. This does not work because everything that is written after the parent condition (Step1 == 0) is executed if said condition was true, regardless of its value later on. You may think that setting Condition = true after Step1 = 1 would work, but it doesn't. Same principle.
In essence, you are writing this.
So you get both statements right, one after another.
This is a clean way to code it without making any changes to the logic:
StepFlag forbids the logic from continuing once the condition is met and set. Note how Step1 only goes now as far as 1.
StepFlag gets reset at the bottom rung of the section, so the execution is blocked for a single scan cycle. There's no need to keep track of it or manually reset it. I also often use this for the whole section of ladder - as a matter of fact you could use a single bool flag for your entire program.
0 notes
Text
Blinking timer in ladder
The following logic results in a timer that outputs a blink, regardless of the input (can be always true, like in the example). This is particularly useful for a strobe emergency light or a start button that blinks when auto mode is interrupted.
You can control both on/off duration times. Use TON_02's negated output in your program if the default state should be on (on > off).
0 notes