Skip to content

About

PLC-controlled height-sorting conveyor cell in CODESYS Structured Text with Factory I/O simulation, Modbus TCP, HMI and a scenario-based test suite.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

PLC height-sorting conveyor cell

PLC-controlled conveyor cell that sorts boxes by height, with alarm handling, an operator HMI and a 3D simulation of the plant.

Built with: CODESYS 3.5 (IEC 61131-3 Structured Text) · Factory I/O · Modbus TCP · CODESYS Visualization (HMI) · Siemens S7-1500 SCL

A conveyor cell that sorts boxes by height. Boxes are released onto a belt one at a time and pass a two-beam height gate. Small boxes are pushed into chute A, large ones into chute B, and anything the controller isn't sure about runs on to a reject bin at the end of the belt.

The control program is IEC 61131-3 Structured Text running on a CODESYS soft PLC. It talks to a 3D model of the cell in Factory I/O over Modbus TCP and has a three-screen operator HMI. I also ported it to Siemens SCL for an S7-1500.

Demo video (1:36, Factory I/O on the left, live HMI on the right): media/demo_factoryio.mp4

What's in the repo

Folder / file Contents
src/ PLC program in portable ST (the version tested with matiec)
codesys/ The same code split into CODESYS objects, plus PRG_HMI for the screens
codesys_project/ The CODESYS 3.5 SP22 project and the logs from building and testing it
factoryio/ Factory I/O scene, scenario results and demo chapter list
tia_portal/ S7-1500 SCL port and tag table (not compiled yet)
docs/ Functional design, I/O list and alarm list (xlsx), setup guides, test report
tools/ Scripts that build the CODESYS project, the HMI and the Factory I/O scene, plus the test and demo scripts
sim/ C model of the plant used for the original automated tests
media/ Demo videos, HMI screenshots

How it was tested

I tested it in four stages, and each stage has its own log:

  1. Simulation. The ST code compiled with matiec and ran against a C model of the plant (sim/). 17 scenarios and 124 checks passed, and I injected four bugs on purpose to confirm the tests catch them. See docs/Test_Report.md.
  2. CODESYS runtime. The project builds with no errors or warnings (codesys_project/build.log). Forcing inputs online, 22 of 22 checks passed (online_test.log).
  3. Modbus link. I set each of the 29 Modbus channels one at a time and checked it arrived on the right PLC variable (modbus_map_check.log).
  4. Factory I/O. With the 3D plant connected, the cell sorted with no rejects at 18 boxes a minute and passed 17 fault scenarios: air loss, E-stop, controlled stop and manual mode (factoryio/scenario_results.txt).

Not done yet: compiling the Siemens port (I don't have TIA Portal) and WinCC screens. The matiec test bench also hasn't been re-run since I renamed one variable for CODESYS (st is a reserved word there, so it became pState). That rename is covered by the CODESYS and Factory I/O tests.

Program structure

PRG_Main (10 ms cyclic task)
  1. input conditioning        4. master state machine
  2. fault conditions          5. height gate -> queue 1 -> pusher A -> queue 2 -> pusher B
  3. alarm manager             6. outputs, stack light, HMI status
PRG_HMI  formats state, alarm list and interlocks for the screens (read-only)

Cell states: INIT, STOPPED, RUNNING, STOPPING, FAULT, E-STOP, MANUAL. docs/Functional_Design.md has the state diagram and the reasoning behind it.

Design decisions

  • Tracking by belt distance, not time. Each box's size is queued at the gate with a timestamp that only advances while the belt moves. If a box goes missing, its entry expires instead of shifting every later sort by one.
  • Safe stop. When a chute fills up, the belt only stops once no box sits between a sensor and its pusher. Otherwise the pusher would fire at a box that isn't moving. The simulation found this one, not me.
  • Metered infeed. The PLC releases boxes far enough apart that a pusher always finishes one stroke before the next box arrives.
  • Faults latch. A fault stays latched until its cause is gone and Reset is pressed. Releasing the E-stop never restarts the cell on its own.
  • First-out alarm. It records which fault came first in a cascade. With an air loss, for example, you see AIR_LOW rather than the extend timeout that follows it.

Limitations

The E-stop here is handled in the PLC program, which is fine for a simulation. A real machine needs a hard-wired or safety-rated stop circuit (ISO 13849). The timings are tuned to the Factory I/O belt speed of about 0.6 m/s.

Running it

  • CODESYS project, Modbus and HMI: docs/CODESYS_Quickstart.md
  • Factory I/O scene and the demo: docs/Factory_IO_Scene_Guide.md and docs/Setup_and_Porting.md
  • Siemens port: tia_portal/README.md
  • Original simulation tests:
git clone https://github.com/beremiz/matiec && cd matiec && autoreconf -i && ./configure && make
cd plc_sorting_cell/sim && MATIEC=/path/to/matiec ./build.sh && ./cell_sim

About

PLC-controlled height-sorting conveyor cell in CODESYS Structured Text with Factory I/O simulation, Modbus TCP, HMI and a scenario-based test suite.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages