
一个顺序控制过程可分为若干个阶段,也称为步或状态,每个状态都有不同的动作。当相邻两状态之间的转换条件得到满足时,就将实现转换,即由上一个状态转换到下一个状态执行。我们常用状态转移图(功能表图)描述这种顺序控制过程。用状态器S记录每个状态,X为转换条件。如当X1为ON时,则系统由S20状态转为S21状态。




状态转移图中的每一步包含三个内容:本步驱动的内容,转移条件及指令的转换目标。
步驱动Y0,当X1有效为ON时,则系统由S20状态转为S21状态,X1即为转换条件,转换的目标为S21步。
3.步进指令的使用说明
1)STL触点是与左侧母线相连的常开触点,某STL触点接通,则对应的状态为动步;
2)与STL触点相连的触点应用LD或LDI指令,只有执行完RET后才返回左侧母线
3)STL触点可直接驱动或通过别的触点驱动Y、M、S、T等元件的线圈;
4)由于PLC只执行活动步对应的电路块,所以使用STL指令时允许双线圈输出(顺控程序在不同的步可多次驱动同一线圈);
5)STL触点驱动的电路块中不能使用MC和MCR指令,但可以用CJ指令;
函数是一定作用的代码块的集合。我们比如可以把计算两个数和写成一个函数,所以函数是具有一定意义的功能代码块,平时我们工作种,习惯性把重复使用到的代码块编写成函数,这样方便阅读和理解,同时也精简了代码量。
函数其实是用作用域,一般函数默认是全局都可以使用,我们也可以限制函数只能在固定的Task或者只能在某个模块里面生效。这个涉及到函数的作用域我会在下一章节和大家一起讨论这个问题。
函数都要有个函数名,函数名和变量名相同规则相同,也就是说是字母和数组的排列组合,当然其中0个字符必须是字母,我们在命名函数的时候不能太长,也不能太短,我记得以前在学校的时候学校有了老教授,教我们单片机,他写程序命名就喜欢取汉语拼音的手写字母比如下面这个函数“JQRDD”名称就是“机-器-人-断-电”,你会发现看他写的程序,相当费劲,尤其是没有注释的函数简直是灾难,0搞笑的是这老头子,给他的车拍买了个“80C51”的号码。简直没谁了。我建议可以这样命名“Robot_Power_Off”,你也可以不用下划线直接取命名“RobotPowerOff”。好吐槽完那个老头子了。函数的主要有点就是,可以在需要该函数的地方执行该函数任意的次数,如果不能把代码函数话,那我们项目都写在Main函数里面,那将是一个巨大的流水账,正如一句话:用时一时爽,重写火葬场。大家好自为之。
函数的另一个有点就是方便开发测试和维护,比如对某一段函数添加一些功能或者修改之前遗漏的Bug,只要函数的输入输出没有变化逻辑没有错误,以前程序的其他部分调用该代码的部分都不会收到影响。当然你可以在修改后的函数名字后面加上一个“V2”,或者“New”,那问题来了,下次再修改了该怎么命名呢?“V3”或者“New_New”,我以前就见多有同事这么写,后来他也发现不对,直接再函数后面谢谢了“年月日”。我当时看到真的和小哪吒一样,“沙子里进了眼睛”。
当然如果你上面的原则都懒得遵守,为了以后的你依旧能看到从前的你写代码,你可以再一个函数的开头进行备注,写下如下几行:当我们再ABB RAPID 中写下人生0段机器人代码的时候,大部分人都是从Main函数开始,“Mian” 就是函数函数名,也就是该函数的函数头,后面跟着的就是函数体,我们的函数。
ABB RAPID 如果没有返回的函数,就写 “PROC” 和 “ENDPROC”直接,风格和VB的风格很像。
当让我们可以在函数的头里面添加参数,我们也可以让函数返回结果,“PROC”函数是没有返回结果的函数格式,有返回的函数格式是”FUNC”我会在这一章节的下面和大家分享。有了前面的两个小节的讨论其实可以足够应对我们工作中的大部分情况甚至是99%的情况,但是总有一些情况我们比较棘手,比如我们编写了一个函数,是发送数据给上位机的,以前是通过串口发送,现在客户想要通过网线发送,但是我程序框架都写好了,只要把发送数据的函数单独修改一下就好了,结果到下一个客户要求两个功能都要,还要可以自由切换,这次难道,可能你感觉可以写两套程序,使用需求,但是如果你掌握了下面的编程技巧,你就会发现你的人生从此改变,老板欣赏你,同事尊重你,食堂打饭的阿姨手也不抖了。
下面就是我们的一个比较有意思的编程语法糖,“Swith“关键字,可选参数。
我们依旧用之前的例子,两个数据的相加,现在我们需求改成同样的函数,可以实现相加,同时也能实现计算两个数据的减法,虽然减法是特殊的加法但是在编程的时候我们还是需要告诉机器人该如何进行操作。话不多说直接上代码:
6)在中断程序和子程序内,不能使用STL指令。
作为全球能源管理和自动化领域的数字化转型专家,施耐德电气始终都在关注着中小企业的成长和良性发展,并在2020年开启了“绿色智能制造创赢计划”0季。
A sequence control process can be divided into several stages, also called steps or states, and each state has different actions. When the transition conditions between two adjacent states are met, the transition will be realized, that is, the transition from the previous state to the next state will be executed. We often use the state transition diagram (menu diagram) to describe this sequential control process. Record each state with state meter S, and X is the transition condition. If X1 is ON, the system changes from S20 state to S21 state.
Each step in the state transition diagram contains three contents: the content driven by this step, the transition conditions and the transition target of instructions.
Step drive Y0. When X1 is effectively ON, the system changes from S20 state to S21 state. X1 is the conversion condition, and the conversion target is S21 step.
3. Instructions for step command
1) STL contact is a normally open contact connected to the left bus. If a STL contact is connected, the corresponding state is dynamic step;
2) The contact connected with STL contact shall apply LD or LDI command and return to the left bus only after executing RET
3) STL contact can directly drive or drive the coil of Y, M, S, T and other components through other contacts;
4) Since PLC only executes the circuit block corresponding to the active step, double coil output is allowed when STL command is used (sequence control program can drive the same coil multiple times in different steps);
5) MC and MCR commands cannot be used in circuit blocks driven by STL contacts, but CJ commands can be used;
A function is a collection of functional code blocks. For example, we can calculate two numbers and write them into a function, so a function is a functional code block with a certain meaning. In our daily work, we habitually write the reused code block into a function, which is convenient for reading and understanding, and also simplifies the code amount.
Functions actually use scopes. Generally, functions can be used globally by default. We can also limit functions to only work in a fixed task or a module. This involves the scope of functions, which I will discuss with you in the next chapter.
All functions must have a function name. The function name and variable name have the same rules, that is, the arrangement and combination of letters and arrays. Of course, the first character must be a letter. We can't name functions too long or too short. I remember that there was an old professor in school who taught us the microcontroller, He likes to name programs with handwritten letters in Chinese Pinyin. For example, the name of the function "JQRDD" below is "machine machine human power off". You will find it very difficult to look at his programs, especially the functions without comments are a disaster. The funny thing is that the old man bought a number of "80C51" for his car. There is hardly anyone else. I suggest you name "Robot_Power_Off" this way, or you can directly name "RobotPowerOff" without underlining. Roast about that old man. The main advantage of the function is that it can be executed any number of times at the place where it is needed. If the code function cannot be written, our project will be written in the Main function, which will be a huge daily account. As a saying goes, it will take a while to rewrite the crematorium. Everyone should do what they want.
Another advantage of the function is that it is convenient for development, testing and maintenance. For example, if you add some functions to a function or modify a bug that was missed before, as long as the input and output of the function do not change and the logic is correct, the part of the previous program that calls the code will not be affected. Of course, you can add a "V2" or "New" after the name of the modified function. The problem is, how to name the modified function next time? "V3" or "New_New". I have seen many colleagues write this before, but later they found it wrong. They directly thanked "Year Month Day" after the function. At that time, I saw that just like Nezha, "eyes were in the sand".
Of course, if you are too lazy to follow the above principles, in order that you can still see the code you wrote in the past, you can make a note at the beginning of another function and write the following lines: When we write the first robot code in ABB RAPID, most people start from the Main function. "Mian" is the function name, that is, the function header of the function, followed by the function body, Our function.
If ABB RAPID has no returned function, it will write "PROC" and "ENDPROC" directly, and the style is similar to that of VB.
When we can add parameters to the function header, we can also let the function return results. "PROC" function is a function format that does not return results, and the function format that returns is "FUNC". I will share it with you later in this chapter. The discussion in the previous two sections is actually enough to deal with most of the situations, even 99% of the situations, in our work. However, there are always some situations that are difficult for us. For example, we have written a function to send data to the upper computer. Previously, it was sent through the serial port. Now, the customer wants to send data through the network cable, but my program framework has been written. Just modify the function to send data separately, As a result, the next customer requires both functions and can switch freely. This time, you may feel that you can write two programs and use them. But if you master the following programming skills, you will find that your life has changed. Your boss appreciates you, your colleagues respect you, and the aunt who cooks in the canteen will not shake her hand.
The following is our interesting programming syntax sugar, "Swith" keyword, optional parameters.
We still use the previous example, the addition of two data. Now we need to change it to the same function, which can achieve addition and also can calculate the subtraction of two data. Although subtraction is a special addition, we still need to tell the robot how to operate when programming. Without much to say, code directly:
6) The STL instruction cannot be used in interrupt programs and subprograms.
As a digital transformation expert in the field of global energy management and automation, Schneider Electric has always been paying attention to the growth and sound development of small and medium-sized enterprises, and opened the first quarter of the "Green Intelligent Manufacturing Win Plan" in 2020.英维思(3008, 3625, 3508E.3721, 3700A 4351B)
本特利(3500/42M, 3500/ 22M, 3500/ 95.3500/05)
黑马(F3330, F3236, F6217, F7126, F8621A)
福克斯波罗(FBM203, FBM204, FBM217, FMB231)
AB: (1746 1747 1756 1770 1771 1785触摸屏2711系列CPU PLC)
普罗索芙特PROSOFT MVI46/56/69, AB旗下,跟AB模块
瑞恩RELIANCE模块,卡件
飞利浦EPRO MMS6210/ 621…. PR6423/003-031
美尔托Meltal MT1102-02-00, MS3101-00-00, MS3102-01-00
横河YOKOGAWA AAI, ADV, ADI, ANB, AMM, SB, PW(型号开头),卡件模块(CPU,电源,输出,PLC)
摩尔MOORE Q开头, 3开头模块,像电视显示器
你的满意是我们不懈的追求;
你的口碑相传是对我们好的回报;ABB 3HNA000512-001
ABB CI627
ABB DI620
ABB AI625
ABB DO620
ABB BRC300
ABB AO610
ABB BRC300
ABB AI835
ABB DSPC172H
ABB 3HAC17326-1/02
ABB DSAI130
ABB
ABB DSPC170
ABB CI626
ABB DI610
ABB DSAI146
ABB SC520 3BSE003816R1
ABB PFSK151
ABB PM511V16 3BSE011181R1
ABB 3HNA000512-001
ABB SPCJ4D34-AA
ABB IMASI23
ABB DI651
ABB IMASI23
ABB IMDSI14
ABB PPD113B01-10-150000
ABB CI541V1 3BSE014666R1
ABB CI627
ABB SC520 3BSE003816R1
ABB CS513 3BSE000435R1
ABB PM802F
ABB SC510 3BSE003832R1
ABB 5SHY5045L0020
ABB DI620
ABB CI522A 3BSE018283R1
ABB PM630
ABB CI534V02 3BSE010700R1
ABB PCD231B101
ABB SC520M 3BSE016237R1
ABB INNPM12
ABB PM803F
ABB DO630
ABB PM633
ABB CI855-1
ABB 5SHY3545L0009
ABB PPD113B03-26-100110
ABB PPD113-B03-23-111615
ABB IMBLK01
ABB SC610
ABB PM633
ABB RF615 RC610
ABB DO620
ABB AI625
ABB IMDS014
ABB BRC300
ABB PCD231B
ABB 5SGX1060H0003
ABB PM632
ABB P-HA-RPS-32200000
ABB PFCL201C 10KN
ABB PM645B
ABB PPC902CE101
ABB PP846A
ABB TC630
ABB 5SHY3545L0014
ABB AO610
ABB DSDP140B 57160001-ACX
ABB UAD149
ABB 216EA61b
ABB BRC300
ABB 5SHX2645L0004
ABB 07AC91D
ABB AI835
ABB 5SHX2645L0004
ABB SPHSS13
ABB PPD113B01-10-150000
ABB DSPC172H
ABB FI830F
ABB 5SHX1060H0003
ABB ASE2UDC920AE01
ABB 5SHX2645L0004
ABB 3BHB003688R0001
ABB DSPC172H
ABB 800PP846A
ABB 3HAC17326-1/02
ABB PM511V16
ABB PM864AK01-eA
ABB PFSK152
ABB SR511 3BSE000863R1
ABB IW93-2 HESG440356R1 HESG216678/B
ABB M2004HW
ABB 216DB61
ABB IMHSS03
ABB DSQC202
ABB PFEA113-65
ABB P-HA-RPS-32200000
ABB PU515A
ABB 5SHY5045L0020
ABB AI625
ABB IMFECI2
ABB 504994880
ABB 5SHY3545L0009
ABB DSAI130
ABB CI535V30 3BSE022162R1
ABB PP836A
ABB MB510 3BSE002540R1
ABB PFSK152
ABB CI535V30 3BSE022162R1
ABB HIEE300024R4 UAA326A04
ABB CI871K01
ABB DO620
ABB PPC907BE
ABB PM864A
ABB UAA326A02
ABB SB822
ABB PCD235A101
ABB 216EA62
ABB DSAI130D
ABB UNS0119A-P V101
ABB 5SHX1060H0003
ABB TAS.580.0560G00
ABB REX010
ABB 5SHX1060H0003