Reputation: 41
I'm trying to create a controlling module for a dome of a telescope. I will be using Beckhoff PLCs. I am not sure how to go about the whole process. I have C++ knowledge, but I am not sure about programming the PLC using TwinCAT.
Is programming in TwinCAT for a PLC the same as writing any other controlling program? Also, should I rather go for a state machine module? However due to my scanty programming knowledge I'm not sure if I'll be able to cope up with programming a state machine.
Upvotes: 1
Views: 5750
Reputation: 21
TwinCAT 3, among other languages, can be programmed in C++ (also TwinSAFE could be programmed in C++). It's not a standard C++, but a restricted version. Also, C++ programming in TwinCAT 3 is a bit tricky, and you need to do some extra steps to integrate the C++ code in the TwinCAT task if compared with the IEC 61131 languages (ST, CFC, SFC, IL, LADDER, etc.).
As an example, ST is a straightforward language, quite similar to PASCAL, C++ or C#. Graphical languages for PLC programming (such as CFC/SFC) are extremely recommended and very very powerful. Those languages helps you to code in a very similar manner as the machine works electrically and if you have some notions of electricity you will find them quite simple and nicer.
The main difference between PLC programming and regular programming are the way PLCs works, as it's perfectly described on the link posted by Jacques de Hooge. Each PLC cycle or sweep has three steps:
A watchdog is monitoring the sweep to ensure it's executed on the sweep time (10-20 ms usually) and that the next sweep is started on its corresponding time slot. If the sweep is not finished in the sweep time, it's reset to the beginning and may cause the CPU to be stopped.
So the PLC works as a continuous loop with no end and a regular PC application has a begin and an end of the application. Also, the memory management and FB/object orientation in a PLC programming is significantly different from PC programming, and C++ doesn't really fit well with the PLC model.
TwinCAT is based on CodeSyS, so it works quite similar as Somachine from Schneider or other PLCs from Omron, ABB, Allen Bradley, etc.
I think that rather than program a state machine in C++/ST/whatever a better choice would be use a SFC controller backed up with some CFC/ST code. Have in mind that just by using SFC you have the state machine developed for you by Beckhoff and you only need to program (in ST or whatever) what to do in each step and how to transition from one step to another.
Upvotes: 2
Reputation: 6990
Things to consider for this particular application:
You would be better off having an explict sweep: input => logic => output, as is typical for e.g. ladder logic or equivalent structured text. Structured text would be easier to edit and understand, in my view.
As for C++, it's quite possible to emulate a PLC sweep in C++:
In this central loop continuously do the following:
. read from sensors
. perform logical operations and computations
. write to actuators (motors in this case)
The advantage of a "true" PLC is that you'll be able to debug in realtime and watch and change all variables during active operation.
It's also quite possible to emulate this in C++. But for a comparatively simple project I'd stick with an existing PLC.
So structured text or ladder logic seems to me most appropriate.
Upvotes: 3