“外放”电机控制程序条件逻辑的编写方法初探
A Preliminary Study on the Method of Compiling Condition Logic of Control Program for "Out-amplifier" Motor
电机控制程序,很常用,也很常见;自己写过很多,也见过很多别人写的。
Motor control procedures, very common, but also very common; I have written a lot, but also seen a lot of other people write.
有封装成块的,也有未封装的。
Some are packaged into blocks, and some are unpackaged.
大部分都是,一个块,接口有很多参数,像下面这样的,
Most of them are a block, and interfaces have a lot of parameters, like the following.

个人对这种风格的块,是不太感冒的,参数太多,脑子不够用的,目标一多就晕乎;认知负荷太高,大脑缺氧。
Individuals are not very cold to this style of block, too many parameters, insufficient brain, a lot of targets on the dizzy; cognitive load is too high, brain hypoxia.
模式功能,仿真功能,通讯控制功能,状态输出功能,错误功能,凡此种种,皆应是“可选项”,要让用户拥有“配置”的权利,简单地说,应当具有“扩展性”。
Mode function, simulation function, communication control function, status output function, error function, all these, should be "optional", to let the user have the right to "configuration", simply said, should have "scalability".

如上图中最后一个网络所示,电机控制最本质的逻辑由三部分组成(变相地看,甚至可以看作是一部分,一个前提条件):
As shown in the last network above, the most essential logic of motor control consists of three parts (in a disguised way, it can even be regarded as a part, a prerequisite):
1、启动条件;
1. Starting conditions;
2、故障条件;
2. Fault conditions;
3、停止条件;
3. Stop conditions;
一个电机控制程序,每一部分包含的条件数量不一,有的只有一个启动条件,有的有多个; 有的只有一个故障条件,有的有多个;有的只有一个停止条件,有的有多个; 也就是说,条件的数量会有发生改变的需求,而此时,一般地做法是重新编辑整个电机块,改变接口,增删对应触点;我是不喜欢这种做法的。
A motor control program, each part contains a different number of conditions, some have only one start condition, some have multiple; some have only one fault condition, some have multiple; some have only one stop condition, some have multiple; that is, the number of conditions will have to change, and at this time, the general approach is to re-edit the entire motor block, change the interface, add and delete the corresponding contacts; I do not like this approach.
过去在京城做官的人,一旦因为政见不合,被在权力中心的掌权者所厌恶,通常都会被贬官外放,或者升官外放,总之,就是让放大你我在空间上的距离,从此不相见,也不相扰。
In the past, when officials in the capital were hated by those in power at the center of power because of political differences, they were usually demoted or promoted. In short, they enlarged the distance between us in space and never met or disturbed each other again.
这些前提条件能否外放?答案是肯定的,可以外放。
Can these preconditions be externalized? The answer is yes, it can be released.

上图中的FB“HandleConditions",既是处理正向启动条件逻辑运算的功能块,它输出一个字“O_wCondGrpStatus"显示条件包各条件的当前状态,并集中输出一个位信号"bEnable",连接到FB"MotorControlLogic"的输入引脚"I_bForward"。
上面仅是举例正向启动信号的情况,其它信号类似。

正向启动条件包,包括多个正向启动的所有条件,打包成了数组结构,当条件数量需要改变时,完全可以在HMI/SCADA上设计简单的功能,即可实现不停机,不用连接电脑,通过简单的将新加点映射到条件包的方式实现修改。
电机控制逻辑块只依赖处理条件功能块的接口输出,也摆脱了大量复杂的条件逻辑算法,降低了复杂性,保持了简洁,对于不存在的输入触点功能引脚可以置TRUE处理。
条件包运算——>接口<——电机控制逻辑
以上就是对条件逻辑"外放"编程的一点初步尝试,想法不成熟,欢迎大家一起交流探讨。