Control device and system program for maintaining global variable and reference data consistency during parallel processing of multiple tasks
09778630 · 2017-10-03
Assignee
Inventors
Cpc classification
G06F9/52
PHYSICS
International classification
G06F9/455
PHYSICS
G06F9/52
PHYSICS
G05B19/05
PHYSICS
G06F11/32
PHYSICS
Abstract
A control device includes a task execution unit; a storage unit which stores a variable in a program, which is capable of being referenced and updated; and a collection unit which collects a variable when a task is executed. The storage unit stores reference data corresponding to the variable. A plurality of tasks include: an update task which is capable of updating and referencing the variable; and a reference task which is capable of referencing the reference data. The collection unit collects the reference data when the plurality of tasks are executed.
Claims
1. A control device for controlling a control object apparatus, the control device comprising: a memory configured to store a plurality of global variables and respective reference data corresponding to the global variables; a processor configured to execute a plurality of tasks and to manage the reference data, each task including a program; a receiver; and a transmitter, wherein the plurality of the tasks is executed in parallel, with each task of the plurality of tasks being executed in different cycles, the plurality of tasks being executed in parallel includes at least one update task for updating the global variables, and at least one read-only reference task for referencing the reference data corresponding to the global variables, the processor is further configured to update a first value of the reference data to correspond to a first value of a global variable prior to executing a reference task and to maintain the first value of the reference data until the reference task is completed, and to update, during execution of the reference task, the first value of the global variable to have a second value, such that the updating of the first value of the global variable and execution of the reference task are performed concurrently, the processor is further configured to set a collection target, and to collect a value of the collection target when the plurality of tasks is executed, the receiver is configured to receive, from a tool device, the collection target and a collection cycle in which the value of the collection target is collected, the processor is further configured to collect the value of the collection target in the collection cycle when the plurality of tasks is executed, and the transmitter is configured to transmit collection results to the tool device.
2. The control device according to claim 1, wherein the processor is further configured to collect the global variables to be updated when the plurality of tasks is executed.
3. The control device according to claim 2, wherein the plurality of tasks includes a single update task and multiple reference tasks, the memory stores the reference data corresponding to the global variables for the reference tasks, and the processor is further configured to collect the reference data when the plurality of tasks is executed.
4. The control device according to claim 1, wherein the plurality of tasks includes a single update task and multiple reference tasks, the memory stores the reference data corresponding to the global variables for the reference tasks, and the processor is further configured to collect the reference data when the plurality of tasks is executed.
5. The control device according to claim 1, wherein the memory stores the collection results.
6. A non-transitory computer readable medium that store a system program, the system program, when executed by a processor, causes a computer to execute: executing a plurality of tasks, each task including a program; storing a plurality of global variables and respective reference data corresponding to the global variables; managing the reference data stored, wherein the plurality of the tasks includes at least one update task for updating the global variables, and at least one read-only reference task for referencing the reference data corresponding to the global variables, the plurality of the tasks being executed in parallel, with each task of the plurality of tasks being executed in different cycles; updating a first value of the reference data to correspond to a first value of a global variable prior to executing a reference task and to maintain the first value of the reference data until the reference task is completed; updating, during execution of the reference task, the first value of the global variable to have a second value, such that the updating of the first value of the global variable and execution of the reference task are performed concurrently; setting a collection target; collecting a value of the collection target when the plurality of tasks is executed; receiving, from a tool device, the collection target and a collection cycle in which the value of the collection target is collected, wherein the value of the collection target is collected in the collection cycle when the plurality of tasks is executed; and transmitting collection results to the tool device.
Description
BRIEF DESCRIPTION OF THE DRAWINGS
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
MODE FOR CARRYING OUT THE INVENTION
(11) Referring to the drawings, the following description will be given of an embodiment of the present invention.
(12) First, referring to
(13) As shown in
(14) The PAC 100 is configured to control the control object apparatus 60 based upon an input from the sensor 50 by executing a task. In this case, the task includes the execution of a user program for controlling the control object apparatus 60.
(15) The CPU unit 1 in which a system program 121 (see
(16) In this case, the system program 121 includes a program for executing an acquiring process of a signal inputted to the input unit 2 in the CPU unit 1, a program for executing a sending process of operation results by the CPU unit 1 to the output unit 3, etc. Moreover, the system program 121 includes a global variable (wide area variable) that is defined in the entire program. The global variable is a variable capable of being accessed from a plurality of tasks (programs).
(17) As shown in
(18) The CPU 11 has a function for executing the system program 121. The CPU 11 is configured so as to execute a plurality of tasks in parallel with one another in a time sharing manner. That is, the CPU 11 executes multitask operations.
(19) The ROM 12 is a nonvolatile memory such as a flash memory. In the ROM 12, the system program 121 is stored, and information L1 (see
(20) In the example of
(21) Moreover, in the ROM 12, setting information L2 (see
(22) In the example of
(23) The RAM 13 is a volatile memory such as a DRAM. The RAM 13 has a function for temporarily storing the system program 121 or the like to be executed by the CPU 11. More specifically, the RAM 13 has a function for storing the global variable GV1 (see
(24) The communication IF 14 is connected to the internal bus 5, and installed so as to allow the CPU unit 1 to communicate with the respective units through the internal bus 5. The communication IF 15 is connected to a tool device 70, and the CPU unit 1 is provided so as to communicate with the tool device 70.
(25) Moreover, as shown in
(26) The task execution unit 21 is configured so as to execute a plurality of tasks in parallel with one another, with each of the plurality of tasks being executed in a cycle based on each task. More specifically, the task execution unit 21 executes the tasks A, B and C in parallel with one another in a time sharing manner. Moreover, the task execution unit 21 executes the task A in a cycle of 1 ms, executes the task B in a cycle of 2 ms, and also executes the task C in a cycle of 4 ms.
(27) The reference data management unit 22 has a function for managing reference data stored in the RAM 13, when the system program 121 is executed. More specifically, the reference data management unit 22 is configured so as to alter the value of the reference data to the value of the global variable prior to the execution of the reference task (prior to the start of the execution of the program of the reference task). That is, the reference data management unit 22 is configured to alter the value of the reference data RD1 to the value of the global variable GV1 prior to the execution of the task B serving as the reference task, and to alter the reference data RD2 to the value of the global variable GV1 prior to the execution of the task C serving as the reference task.
(28) The collection unit 23 has a function for collecting the value of the global variable when the task is being executed by the task execution unit 21. Moreover, the collection unit 23 has a function for collecting the value of the reference data when the task is being executed by the task execution unit 21. More specifically, the collection unit 23 has a function for collecting the values of the global variable GV1 and the reference data RD1 and RD2. Thus, the CPU unit 1 is capable of collecting a change with time of each of variables (global variable GV1 and reference data RD1 and RD2, etc.) when the system program 121 is being executed. That is, in the CPU unit 1, it is possible to carry out a data tracing process of a variable when the system program 121 is being executed.
(29) The setting unit 24 has a function for setting a collection target by the collection unit 23. That is, the setting unit 24 has a function for setting a valuable to be data traced. More specifically, based upon data trace information T (see
(30) Moreover, the CPU unit 1 is configured so as to carry out an exclusive controlling process among the tasks relative to the global variable. For example, as shown in
(31) More specifically, the external variable (global variable) GV1 is registered in the program P1 of the task A. Since the task A is the update task, the external variable P1.GV1 of the program P1 directly accesses the main body of the global variable GV1 of the RAM 13.
(32) Moreover, the external variable GV1 is registered in the program P4 of the task B. Since the task B is the reference task, the external variable P4.GV1 of the program P4 accesses the reference data RD1 for the task B of the RAM 13. When the task B is executed by the task execution unit 21 (see
(33) Moreover, the external variable GV1 is registered in the program P5 of the task C. Since the task C is the reference task, the external variable P5.GV1 of the program P5 accesses the reference data RD2 for the task C of the RAM 13. When the task C is executed by the task execution unit 21, the value of the reference data RD2 for the task C is altered (updated) to the value of the global variable GV1 by the reference data management unit 22.
(34) A tool device 70 is, for example, a personal computer, and has a function for producing and editing a user program to be executed by the PAC 100. Moreover, the tool device 70 has a function for downloading a user program from the PAC 100 and a function for uploading the user program to the PAC 100.
(35) Moreover, the tool device 70 has a function for altering the setting information L2 (see
(36) Furthermore, the tool device 70 has a function for giving an instruction for an execution of data tracing to the CPU unit 1. More specifically, the tool device 70 is configured so as to transmit data tracing information T (see
(37) Moreover, as shown in
(38) Next, referring to
(39) The following description will be given by exemplifying a case in which prior to the start of the data tracing process, the global variable GV1 is set to “0”, with the reference data RD1 and RD2 being set to “0”.
(40) First, data trace information T (see
(41) In the CPU unit 1, in the case that the data trace information T is received from the tool device 70 through the communication IF 15 (see
(42) Moreover, the execution cycles of the tasks A, B and C are started simultaneously with the control cycle by the CPU 11. Additionally, the task A is executed in a cycle of 1 ms, the task B is executed in a cycle of 2 ms, and the task C is executed in a cycle of 4 ms.
(43) More specifically, first, the process of the task A having the highest degree of preference is started by the task execution unit 21 (see
(44) Moreover, the program P1 of the task A serving as the update task is executed, and in the program P1, “1” is written in the external variable (global variable) GV1. Thus, the value of the global variable GV1 to be stored in the RAM 13 is updated from “0” to “1”. At this time, since the task A is the update task, it directly accesses the main body of the global variable GV1 of the RAM 13. Thereafter, the program P2 of the task A is executed so that the process of the task A is completed.
(45) Prior to the execution of the task B having a higher degree of preference than the task C, the value of the reference data RD1 used for the task B is altered to the value of the global variable GV1 by the reference data management unit 22. At this time, since the value of the global variable GV1 is “1”, the value of the reference data RD1 is updated from “0” to “1”.
(46) Thereafter, the programs P3 and P4 of the task B serving as the reference task are executed by the task execution unit 21. Additionally, a reading process of the external variable GV1 is carried out in the program P4. At this time, since the task B is the reference task, it accesses the reference data RD1 of the RAM 13. Thus, “1” of the reference data RD1 is read out.
(47) Next, after a lapse of 1 ms from the simultaneous starts of the execution cycles of the tasks A, B and C, the program P4 of the task B is suspended. Then, by the collection unit 23 (see
(48) Moreover, since the execution cycle of the task A has been elapsed, the execution of the task A is carried out by the task execution unit 21. At this time, the tasks B and C are kept in the stand-by states. For this reason, the program P1 of the task A serving as the update task is executed so that in the program P1, “2” is written in the external variable (global variable) GV1. Thus, the value of the global variable GV1 to be stored in the RAM 13 is updated from “1” to “2”. Thereafter, the program P2 of the task A is executed, and the process of the suspended task B is resumed upon completion of the process of the task A. In this case, since the task B has been suspended, the value of the reference data RD1 is not updated. Then, the rest of the program P4 of the task B is executed by the task execution unit 21 so that the process of the task B is completed.
(49) Moreover, prior to the execution of the task C, the value of the reference data RD2 to be used in the task C is altered to the value of the global variable GV1 by the reference data management unit 22. At this time, since the value of the global variable GV1 is “2”, the value of the reference data RD2 is updated from the value “0” to “2”.
(50) Thereafter, the program P5 of the task C serving as the reference task is executed by the task execution unit 21. Additionally, in the program P5, the external variable GV1 is read out. At this time, since the task C is the reference task, it accesses the reference data RD2 of the RAM 13. Thus, “2” of the reference data RD2 is read out.
(51) Next, after a lapse of 2 ms from the simultaneous starts of the execution cycles of the tasks A, B and C, the program P5 of the task C is suspended. Moreover, the values of the external variable P1. GV1 of the program P1, the external variable P4.GV1 of the program P4 and the external variable P5.GV1 of the program P5 are collected by the collection unit 23. At this time, since the global variable GV1 is “2”, the reference data RD1 is “1” and the reference data RD2 is “2”, the external variable P1. GV1 is “2”, the external variable P4.GV1 is “1” and the external variable P5.GV1 is “2”. Moreover, since the collection results by the collection unit 23 are stored in the RAM 13 in association with the elapsed time (2 ms) from the start of the data tracing by the CPU 11, the trace results L3 are accumulated in the RAM 13.
(52) Moreover, since the execution cycle of the task A has been elapsed, the task A is carried out by the task execution unit 21. At this time, since the execution cycle of the task B has also been elapsed, the tasks B and C are kept in the stand-by states. For this reason, the program P1 of the task A serving as the update task is executed so that in the program P1, “3” is written in the external variable (global variable) GV1. Thus, the value of the global variable GV1 to be stored in the RAM 13 is updated from “2” to “3”. Thereafter, the program P2 of the task A is executed, and the process of the task A is completed.
(53) Prior to the execution of the task B having a higher degree of preference than the task C, the value of the reference data RD1 used for the task B is altered to the value of the global variable GV1 by the reference data management unit 22. At this time, since the value of the global variable GV1 is “3”, the value of the reference data RD1 is updated from “1” to “3”.
(54) Thereafter, the programs P3 and P4 of the task B serving as the reference task are executed by the task execution unit 21. Additionally, a reading process of the external variable GV1 is carried out in the program P4. At this time, since the task B is the reference task, the task B accesses the reference data RD1 of the RAM 13. Thus, “3” of the reference data RD1 is read out.
(55) Next, after a lapse of 3 ms from the simultaneous starts of the execution cycles of the tasks A, B and C, the program P4 of the task B is suspended. Then, by the collection unit 23, the values of the external variable P1. GV1 of the program P1, the external variable P4. GV1 of the program P4 and the external variable P5. GV1 of the program P5 are collected. At this time, since the global variable GV1 is “3”, the reference data RD1 is “3” and the reference data RD2 is “2”, the external variable P1. GV1 becomes “3”, the external variable P4. GV1 becomes “3” and the external variable P5. GV1 becomes “2”. Then, since the collection results by the collection unit 23 are stored in the RAM 13 in association with the elapsed time (3 ms) from the start of the data tracing by the CPU 11, the trace results L3 are accumulated in the RAM 13.
(56) Moreover, since the execution cycle of the task A has been elapsed, the task A is carried out by the task execution unit 21. At this time, the tasks B and C are kept in the stand-by states. For this reason, the program P1 of the task A serving as the update task is executed so that in the program P1, “4” is written in the external variable (global variable) GV1. Thus, the value of the global variable GV1 to be stored in the RAM 13 is updated from “3” to “4”. Thereafter, the program P2 of the task A is executed, and the process of the suspended task B is resumed upon completion of the process of the task A. In this case, since the task B has been suspended, the value of the reference data RD1 is not updated. At this time, the task C is kept in the stand-by state. Then, the rest of the program P4 of the task B is executed by the task execution unit 21. Thereafter, the process of the suspended task C is resumed upon completion of the process of the task B. Additionally, since the task C has been suspended, the value of the reference data RD2 is not updated.
(57) Moreover, the rest of the program P5 of the task C serving as the reference task is executed by the task execution unit 21. Additionally, the external variable GV1 is read out in the program P5. At this time, since the task C is the reference task, it accesses the reference data RD2 of the RAM 13. Thus, “2” of the reference data RD2 is read out.
(58) After a lapse of 4 ms from the simultaneous starts of the execution cycles of the tasks A, B and C since the completion of the process of the task C, the values of the external variable P1. GV1 of the program P1, the external variable P4. GV1 of the program P4 and the external variable P5. GV1 of the program P5 are collected by the collection unit 23. At this time, since the global variable GV1 is “4”, the reference data RD1 is “3” and the reference data RD2 is “2”, the external variable P1. GV1 becomes “4”, the external variable P4. GV1 becomes “3” and the external variable P5. GV1 becomes “2”. Then, since the collection results by the collection unit 23 are stored in the RAM 13 in association with the elapsed time (4 ms) from the start of the data tracing by the CPU 11, the trace results L3 are accumulated in the RAM 13.
(59) Moreover, since the execution cycle of the task A has been elapsed, the task A is carried out by the task execution unit 21. At this time, since the execution cycles of the tasks B and C have also been elapsed, the tasks B and C are kept in the stand-by states.
(60) Then, the same operations as the operations described above are carried out repeatedly.
(61) Thereafter, when the data tracing process by the CPU unit 1 is finished, the trace results L3 are transmitted to the tool device 70 from the communication IF 15 by the CPU 11. Thus, the tool device 70 is allowed to display a graph as shown in
(62) In the present embodiment, as described above, by allowing only the task A serving as the update task to update and reference the global variable GV1 as well as by allowing the task B serving as the reference task to reference the reference data RD1 corresponding to the global variable GV1, it is possible to carry out a consistent operation on the task B since the task B is allowed to reference the reference data RD1, even in the case that the value of the global variable GV1 is updated by the task A during a period from the start of the program P3 of the task B to the completion of the program P4. In other words, since the updating is carried out so as to correspond to the global variable GV1 prior to the start of the program P3 of the task B, and since, by allowing the task B to reference the reference data RD1 that is constant during the period from the start of the program P3 to the completion of the program P4, no updating unexpected by the task B is carried out on the reference data RD1 during the period from the start of the program P3 to the completion of the program P4, it is possible to carry out a consistent operation on the task B.
(63) In the same manner, by allowing only the task A serving as the update task to update and reference the global variable GV1 as well as by allowing the task C serving as the reference task to reference the reference data RD2 corresponding to the global variable GV1, it is possible to carry out a consistent operation on the task C since the task C is allowed to reference the reference data RD2, even in the case that the value of the global variable GV1 is updated by the task A during a period from the start of the program P5 of the task C to the completion thereof. In other words, since the updating is carried out so as to correspond to the global variable GV1 prior to the start of the program P5 of the task C, and since, by allowing the task C to reference the reference data RD2 that is constant during the period from the start of the program P5 to the completion of thereof, no updating unexpected by the task C is carried out on the reference data RD2 during the period from the start of the program P5 to the completion thereof, it is possible to carry out a consistent operation on the task C.
(64) Moreover, in the task A serving as the update task, since only the task A is allowed to update and reference the global variable GV1, it is possible to carry out a consistent operation on the task A. Therefore, even in the case that a plurality of tasks A, B and C access the global variable GV1, by allowing the tasks B and C serving as the reference tasks to respectively reference the reference data RD1 and RD2, it is possible to carry out a consistent operation. As a result, it is possible to appropriately carry out exclusive controls among the tasks A, B and C relative to the global variable GV1.
(65) Moreover, in the present embodiment, by collecting the value of the global variable GV1 by the collection unit 23 when the tasks A, B and C are being executed, a data tracing process can be carried out on the global variable GV1 (external variable P1. GV1) to be updated and referenced by the task A serving as the update task. Furthermore, by collecting the values of the reference data RD1 and RD2 by the collection unit 23 when the tasks A, B and C are being executed, a data tracing process can be carried out on the global variables GV1 (external variables P4. GV1 and P5. GV1) to be referenced by the tasks B and C serving as the reference tasks. With this configuration, even in the case that the tasks B and C serving as the reference tasks are allowed to respectively reference the reference data RD1 and RD2 so as to carry out a consistent operation in the case of allowing the tasks A, B and C to access the global variable GV1, it is possible to accurately carry out a data tracing process on each of the reference data RD1 and RD2 that are the referencing ends of the tasks B and C.
(66) Moreover, in the present embodiment, when the task B serving as the reference task is executed, the value of the reference data RD1 is altered to the value of the global variable GV1, while the task C serving as the reference task is executed, the value of the reference data RD2 is altered to the value of the global variable GV1. Therefore, it is possible to carry out a consistent operation on each of the tasks B and C serving as the update tasks while the reference data RD1 and RD2 are made associated with the global variable GV1.
(67) Moreover, in the present embodiment, by setting the collection target and the collection cycle of the data tracing process based upon the received data trace information T from the tool device 70 by the communication IF 15, the user is allowed to set the collection target and the collection cycle by using the tool device 70.
(68) Furthermore, in the present embodiment, by transmitting the trace results L3 from the communication IF 15 to the tool device 70, since the tool device 70 can obtain the trace results L3, the user is allowed to confirm the trace results L3 by using the tool device 70.
(69) Moreover, in the present embodiment, since the CPU 11 executes a plurality of tasks in parallel with one another in a time sharing manner, it is possible to effectively utilize the processing capability of the CPU 11.
(70) Additionally, the present embodiments disclosed above are exemplary only in all the aspects, and do not form the basis of a limited interpretation. Therefore, the technical scope of the present invention is not interpreted only by the above-mentioned embodiments, but defined based upon the description of the claims. Moreover, the technical scope of the present invention includes all modifications made within the meaning and scope equal to the claims.
(71) For example, the present embodiment has exemplified a configuration in which the PAC 100 is provided with the CPU unit 1, the input unit 2, the output unit 3 and the power supply unit 4; however, not limited to this configuration, the PAC may have another unit, such as a communication unit, and no input unit may be installed in the PAC.
(72) Moreover, the present embodiment has exemplified a configuration in which the PAC 100 is constituted by a plurality of units; however, not limited by this configuration, the PAC may be formed by one casing, with functions of the respective units being incorporated in the casing.
(73) Moreover, in the present embodiment, the external variable (global variable) GV1 may be registered in the program P2 of the task A. In this case, in the external variable P2. GV1 of the program P2, since the task A is the update task, the task A directly accesses the main body of the global variable GV1 of the RAM 13.
(74) Furthermore, in the present embodiment, the external variable GV1 may be registered in the program P3 of the task B. In this case, since the task B is the reference task, the external variable P3. GV1 of the program P3 accesses the reference data RD1 for the task B of the RAM 13.
(75) Furthermore, the present embodiment has exemplified a configuration in which the CPU 11 executes a plurality of tasks in parallel with one another in a time sharing manner; however, not limited by this configuration, the CPU may be a multi-core device that carries out a plurality of tasks simultaneously in parallel with one another. By using this configuration, it becomes possible to improve the processing capability of tasks.
(76) Moreover, the present embodiment has exemplified a configuration in which, the task execution unit 21, the reference data management unit 22, the collection unit 23 and the setting unit 24 are realized when the CPU 11 executes the system program 121; however, not limited to this configuration, the task execution unit 21, the reference data management unit 22, the collection unit 23 and the setting unit 24 may be respectively configured by hardware units.
(77) Moreover, the present embodiment has exemplified a configuration in which a sampling cycle contained in the data trace information T is set as a time interval; however, not limited to this configuration, the sampling cycle may be set by the cycle of the specified task.
(78) In the present embodiment, for simplicity of explanation, the trace results L3 from 1 ms to 8 ms are shown; however, actually, the data tracing process is executed for a longer period of time. For example, the data tracing process is executed for 10 seconds (10000 ms).
(79) Moreover, the present embodiment has exemplified a case in which the collection results and the elapsed periods of time are included in the trace results L3; however, not limited to this, time information relating to collected data, index information indicating the sequence of the collected data, or the like may be included therein.
(80) Furthermore, the present embodiment has exemplified a case in which the trace results L3 are stored in the RAM 13; however, not limited to this, the trace results L3 may be stored in the ROM 12.
(81) The present embodiment has exemplified a case in which a plurality of tasks include one update task (task A) and two reference tasks (tasks B and C); however, not limited to this, as long as one update task exists, a single reference task may be used, or three or more reference tasks may be used.
(82) Moreover, in the present embodiment, the values of the external variable GV1 and the like are exemplary only, and the present invention is not intended to be limited by those values.
(83) Furthermore, in the present embodiment, the task may include a task (event task) that is executed when a preliminary set execution condition is satisfied, in addition to tasks that are regularly executed (fixed-cycle tasks).
INDUSTRIAL APPLICABILITY
(84) The present invention is applicable to a control device for controlling a control object apparatus and a system program executed in the control device.
DESCRIPTION OF SYMBOLS
(85) 1 CPU unit (control device) 13 RAM (storage unit) 15 communication IF (communication unit) 21 task execution unit (task execution means) 22 reference data management unit 23 collection unit 24 setting unit 60 control object apparatus 70 tool device 121 system program