简体   繁体   English

使用C ++在Twincat 3上进行PLC编程

[英]PLC programming on Twincat 3 using C++

I'm trying to create a controlling module for a dome of a telescope. 我正在尝试为望远镜的圆顶创建一个控制模块。 I will be using Beckhoff PLCs. 我将使用Beckhoff PLC。 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. 我有C ++知识,但我不确定使用TwinCAT编程PLC。

Is programming in TwinCAT for a PLC the same as writing any other controlling program? 在TwinCAT中为PLC编程与编写任何其他控制程序相同吗? 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. 但是由于我的编程知识不足,我不确定我是否能够应对编程状态机。

Things to consider for this particular application: 这个特定应用需要考虑的事项:

  • Operating a telescope dome is not something that typically requires many steps 操作望远镜圆顶不是通常需要许多步骤的东西
  • Even when thinking in steps like when using a state machine, it would be necessary to continuously check if the conditions for enabling a certain step are still fulfilled (something could get stuck, a motor could get overheated, wind may change the position of a part of your dome or telescope) 即使在考虑使用状态机等步骤时,也需要不断检查是否仍然满足启用某个步骤的条件(可能会卡住,电机可能会过热,风可能会改变部件的位置)您的圆顶或望远镜)

You would be better off having an explict sweep: input => logic => output, as is typical for eg ladder logic or equivalent structured text. 你最好有一个明显的扫描:input => logic => output,这是典型的例如梯形逻辑或等效的结构化文本。 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++: 对于C ++,很有可能在C ++中模拟PLC扫描:

  • Have one central loop, and stick to a number of rules as specified in under 'PLC programming rules' of this document. 有一个中央循环,并遵守本文档 “PLC编程规则”中规定的许多规则
  • 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. “真正的”PLC的优点是您可以实时调试并在活动操作期间观察和更改所有变量。

It's also quite possible to emulate this in C++. 也很有可能在C ++中模拟它。 But for a comparatively simple project I'd stick with an existing PLC. 但是对于一个相对简单的项目,我会坚持使用现有的PLC。

So structured text or ladder logic seems to me most appropriate. 在我看来,结构化的文本或梯形逻辑是最合适的。

TwinCAT 3, among other languages, can be programmed in C++ (also TwinSAFE could be programmed in C++). TwinCAT 3和其他语言一样,可以用C ++编程(TwinSAFE也可以用C ++编程)。 It's not a standard C++, but a restricted version. 它不是标准的C ++,而是受限制的版本。 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.). 此外,TwinCAT 3中的C ++编程有点棘手,如果与IEC 61131语言(ST,CFC,SFC,IL,LADDER等)相比,您需要执行一些额外的步骤来将C ++代码集成到TwinCAT任务中。 。

As an example, ST is a straightforward language, quite similar to PASCAL, C++ or C#. 例如,ST是一种直截了当的语言,与PASCAL,C ++或C#非常相似。 Graphical languages for PLC programming (such as CFC/SFC) are extremely recommended and very very powerful. 非常推荐用于PLC编程的图形语言(例如CFC / SFC),并且功能非常强大。 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. PLC编程和常规编程之间的主要区别在于PLC的工作方式,因为它在Jacques de Hooge发布的链接中得到了很好的描述。 Each PLC cycle or sweep has three steps: 每个PLC循环或扫描都有三个步骤:

  1. Read all the process input signal. 读取所有过程输入信号。 In Beckhoff, the variables obtained through industrial network communications are read transparently as if they were connected directly to the PLC. 在Beckhoff中,通过工业网络通信获得的变量被透明地读取,就像它们直接连接到PLC一样。 Those signals stays unchanged for the whole cycle. 这些信号在整个周期内保持不变。
  2. Execute user code. 执行用户代码。 In TwinCAT 3 this user code can be programmed in any of the IEC 61131 languages, C++ and MATLAB/Simulink. 在TwinCAT 3中,该用户代码可以用任何IEC 61131语言编写,C ++和MATLAB / Simulink。 Both C++ and Simulink requires extra licenses to run. C ++和Simulink都需要额外的许可才能运行。
  3. Activate the output signals. 激活输出信号。 Those signals will be kept constant for the whole next sweep without minding the actual value of the variable on that sweep. 对于整个下一次扫描,这些信号将保持不变,而不需要考虑该扫描的变量的实际值。

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. 看门狗正在监视扫描以确保它在扫描时间(通常为10-20 ms)执行,并且下一次扫描在相应的时隙上启动。 If the sweep is not finished in the sweep time, it's reset to the beginning and may cause the CPU to be stopped. 如果扫描时间没有完成扫描,则复位到开头并可能导致CPU停止。

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. 因此,PLC作为一个没有结束的连续循环工作,并且常规PC应用程序具有应用程序的开始和结束。 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. 此外,PLC编程中的内存管理和FB /面向方向与PC编程明显不同,C ++并不能很好地适应PLC模型。

TwinCAT is based on CodeSyS, so it works quite similar as Somachine from Schneider or other PLCs from Omron, ABB, Allen Bradley, etc. TwinCAT基于CodeSyS,因此它与Schneider的Somachine或来自Omron,ABB,Allen Bradley等的其他PLC非常相似。

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. 我认为,不是在C ++ / ST中编程状态机,而是更好的选择是使用备份有一些CFC / ST代码的SFC控制器。 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. 请记住,只需使用SFC,您就拥有Beckhoff为您开发的状态机,您只需要编程(在ST或其他任何方面)在每个步骤中做什么以及如何从一个步骤转换到另一个步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM