PLC Control Systems
// HAMK Control Systems Course · TwinCAT 3 / Beckhoff EtherCAT · Group 7
Process State Machine — Pick & Place with Cooling
Live Variables (GVL_IO)
| Variable | Type | Value | Description |
|---|
LED Indicators
🟢 Green
Idle
Idle
🔵 Blue
Cooling
Cooling
🟡 Yellow
Wait Robot
Wait Robot
🔴 Red
Fault
Fault
Temperature Sensor (LM35)
24.2 °C
Setpoint: 8.0°C
Monitoring…
State Transition Log
Refrigerator Control Visualization
System Parameters
| Variable | Value |
|---|
Temperature History (TwinCAT YT Chart)
E_ProcessState — Enumeration (DUT)
// Data Unit Type — State machine enumeration
{attribute 'qualified_only'}
{attribute 'strict'}
TYPE E_ProcessState :
(
stIdle, // Waiting for StartCycle
stRequestMoveToP2, // PLC sets RobotCmd := TRUE
stWaitRobotAtP2, // Wait for RobotAck = TRUE (at cooling tank)
stCooling, // Temperature supervision
stRequestMoveToP3, // PLC sets RobotCmd := FALSE
stWaitRobotAtP3, // Wait for RobotAck = FALSE (at output)
stDone, // Cycle complete
stFault // Timeout or error
);
END_TYPE
MAIN — State Machine in Structured Text (IEC 61131-3)
CASE eState OF
E_ProcessState.stIdle:
bRobotCmd := FALSE;
bCycleDone := FALSE;
IF bStartCycle THEN
eState := E_ProcessState.stRequestMoveToP2;
END_IF;
E_ProcessState.stRequestMoveToP2:
bRobotCmd := TRUE; // MG400 DI8 goes HIGH
eState := E_ProcessState.stWaitRobotAtP2;
E_ProcessState.stWaitRobotAtP2:
tonStepTimeout(IN := TRUE, PT := T#30S);
IF bRobotAck THEN // MG400 DO8 → EL1008 DI8
eState := E_ProcessState.stCooling;
ELSIF tonStepTimeout.Q THEN
eState := E_ProcessState.stFault;
END_IF;
E_ProcessState.stCooling:
// LM35 → EL3074 analog input → rTempValue (scaled to °C)
IF rTempValue <= rTempSetpoint THEN
eState := E_ProcessState.stRequestMoveToP3;
END_IF;
E_ProcessState.stRequestMoveToP3:
bRobotCmd := FALSE; // Signal: move P2 → P3
eState := E_ProcessState.stWaitRobotAtP3;
E_ProcessState.stWaitRobotAtP3:
tonStepTimeout(IN := TRUE, PT := T#30S);
IF NOT bRobotAck THEN
eState := E_ProcessState.stDone;
ELSIF tonStepTimeout.Q THEN
eState := E_ProcessState.stFault;
END_IF;
E_ProcessState.stDone:
bCycleDone := TRUE;
bFaultActive := FALSE;
IF NOT bStartCycle THEN
eState := E_ProcessState.stIdle;
END_IF;
E_ProcessState.stFault:
bRobotCmd := FALSE;
bFaultActive := TRUE;
IF bResetFault THEN
eState := E_ProcessState.stIdle;
END_IF;
END_CASE;
Beckhoff EtherCAT I/O Architecture
IPC (Industrial PC) ─── EtherCAT ───┐
TwinCAT Runtime 4024 │
IP: 192.168.1.10 ▼
EL1008 Digital Input 8-ch
EL2008 Digital Output 8-ch
EL3074 Analog Input 4-ch (0-10V / Real32)
EL4074 Analog Output 4-ch
── Wiring to Dobot MG400 ──
EL2008 DO4 ──────────────── MG400 DI8 (PLC → Robot CMD)
MG400 DO8 ──────────────── EL1008 DI8 (Robot → PLC ACK)
GND (PLC) ──────────────── GND (MG400)
── Temperature Sensor LM35 ──
Brown → +24V
Black → 0V (GND)
Blue → EL3074 Channel 1 (analog input)
Scale: 10 mV/°C → 22°C = 0.22V input
Robot–PLC Handshake Protocol
Single-bit bidirectional handshake:
1. PLC sets CMD = TRUE
→ Robot picks at Position 1
→ Robot moves to Position 2 (cooling tank)
2. Robot sets ACK = TRUE
→ PLC enters stCooling
→ Waits: rTempValue ≤ 8.0°C
3. PLC sets CMD = FALSE
→ Robot moves from P2 to P3 (output)
4. Robot sets ACK = FALSE
→ PLC enters stDone
Timeout: 30s per step → stFault
Reset: momentary switch bResetFault
Physical I/O Mapping
| Variable | Qualifier | Terminal | Channel | Description |
|---|---|---|---|---|
| bDoorOpen | AT %I* | EL1008 | CH1 | Toggle switch → door sensor |
| bResetFault | AT %I* | EL1008 | CH2 | Momentary button → fault reset |
| bRobotAck | AT %I* | EL1008 | CH8 | MG400 DO8 → robot acknowledge |
| bLight | AT %Q* | EL2008 | CH1 | LED → door open indicator |
| bAlarm | AT %Q* | EL2008 | CH2 | Red LED → blinking alarm |
| bRobotCmd | AT %Q* | EL2008 | CH4 | MG400 DI8 → robot command |
| rTempValue | AT %I* | EL3074 | CH1 | LM35 analog → Real32 °C |