OK, PLC Software.
I'm using Rockwell Automation's Studio 5000 PLC development software (Version 33).
PLC's differ from your standard microcontroller in a number of important ways. First off, they are designed for large amounts of I/O which someone else has done the leg work of developing the interface for you. There are dozens of flavors of I/O modules and all of them are designed to plug into the PLC rack and have a data assembly automatically created for you as soon as you add them to the program. Next, PLC's are designed for networking and connectivity. All of the network processing is handled in the background and typically does not affect the execution of you runtime program. PLC code is interpreted (meaning no compiling) so you are able to "go online" with the PLC and watch it execute your code. Online edits to the code while the PLC is running are perfectly fine in most cases. Rockwell PLCs have 4 languages (Ladder logic, structured text, function block, and sequential function chart) which can be used interchangeably. Ladder logic is the easiest to read, especially at runtime.
PLCs are also excellent for real time program control and time dependent control (think of timers and scheduled code execution). This is perfect for machines since they have real world characteristics which require time delay in your code.
Here is the controller organizer for the PLC. From top to bottom... The Controller tags contains all globally scoped tags (PLC name for variables) in tabular format. Your actual code is organized into tasks. Tasks can occur on a schedule (periodic tasks), driven by an event (event tasks), or run continuously with whatever remaining processor power is left (continuous task). Each PLC can handle up to 32 tasks, although you typically only have a few. Inside each task are programs, you can have 1000 of these per task. Finally inside each program are routines (no limit on this). Programs may have their own locally scoped tags which can only be used by that program. Here I am using 3 periodic tasks (2ms, 10ms, and 50ms).
The motion group contains all the motion axes and coordinate systems for this PLC. I have 8 axes (T1, T2, T3, T4, X, Y, Z, and U) and 2 coordinate systems (cartesian and robot). The motion group can update every 2ms.
Finally at the bottom is the I/O tree where all the connected devices are stored. I have the PLC, an Ethernet interface module, and (2) 1756-M02AE analog motion modules.
Here is an example of some simple ladder code. Ladder logic was created to be easily read by electricians familiar with relay logic. In the rung below, the logic statement is: IF (
A and NOT
B OR
C) THEN
X = 1. There is also the parallel statement: IF ((
A and NOT
B OR
C) AND
D) THEN
Y = 1.
Here is an example with a timer which would be a touch tricky to do in an Arduino without stopping the processor. The statement is: IF
A THEN start
TIMER. IF
A AND
TIMER DONE THEN X = 1. The timer is preset to 1000ms and the accumulator will count up on screen until 1000 is reached. DN is a status bit indicating the timer is done
Here is an example of the real code running the robot. When the program counter tag (Wrk_ProgramStep) is equal to step 10, then execute the MAM (Motion Axis Move) instruction. This commands the axis T3 (Z axis motion) to move incrementally the distance contained in the tag (Wrk_BasicMotion_Pos1) which is currently -3 inches. The move should use the speed and accelerations contained in the tags shown below (current values are displayed with the tag), and the motion should follow a trapezoidal profile. The rest of the arguments in the instruction are advanced features not used at this time. The tag T3_BasicMotion_MAM1 is a unique tag containing the information pertinent to this motion instruction.
After the instruction is executed, the PLC sits on this rung of code until the status bit T3_BasicMotion_MAM1.PC (Process Complete) is set, then the program jumps to step 20. Motion programming is one of the most intensive tasks for a PLC. The PC bit is set when the PLC is done commanding motion and the command for the axis to reach its final destination has been sent.
I can't cover every detail of the program, but this is a quick and dirty introduction. Feel free to ask any questions.