G code generation method, generation device, processor and electronic device
Patent Information
- Application Number
- CN202211538909.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-02
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2042-12-02
Smart Images

Figure CN116125911B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of numerical control technology, and in particular to a method for generating a G code, a generating device, a computer-readable storage medium, a processor, and an electronic device. Background Art
[0002] Most current motion control systems control axes in either manual or automatic ways. In manual mode, a button is usually pressed to make the axis move continuously. If long-distance movement or multiple axes need to be moved, manual operation takes a lot of time and effort. In automatic mode, complex multi-axis movement is achieved by pre-analyzing and planning the axis's motion path, speed, and sequence of motion, and writing corresponding G codes.
[0003] However, in the case of simple movements of axes over long distances or simple movements of multiple axes, it will take more time and effort to rewrite the program for each movement. Summary of the invention
[0004] The main purpose of the present application is to provide a G-code generation method, generation device, computer-readable storage medium, processor and electronic device to solve the problem that in the motion control system of the prior art, it takes a lot of time and effort to write programs for multiple long-distance simple movements of the control axis or simple movements of multiple axes.
[0005] According to one aspect of an embodiment of the present invention, a method for generating a G code is provided, comprising: in response to a first predetermined operation, displaying an initial interface, the initial interface comprising selection identifiers of multiple moving axes and input identifiers of destination positions corresponding to each of the moving axes; in response to a second predetermined operation acting on the initial interface, determining an axis identification number and first target position information of a target moving axis, the target moving axis being the moving axis whose state of the selection identifier is a predetermined state, the predetermined state being characterized by a state in which the selection identifier is selected, and the first target position information being information in the input identifier corresponding to the target moving axis; generating a G code file according to the axis identification number and the first target position information, and sending the G code file to a PLC (Programmable Logic Controller).
[0006] Optionally, a G-code file is generated according to the axis identification number and the first target position information, including: obtaining the travel range corresponding to the target moving axis; determining the second target position information according to the first target position information and the travel range, wherein, when the first target position information is within the travel range, the first target position information is determined to be the second target position information, and when the first target position information is not within the travel range, the current position of the target moving axis is determined to be the second target position information; the G-code file is generated according to the axis identification number and the second target position information.
[0007] Optionally, an axis identification number and the corresponding second target position information constitute the first character information, and the G code file is generated according to the axis identification number and the second target position information, including: generating a character string, the character string including the G code type; determining the number of the axis identification numbers; and according to the number, adding at least each of the first character information to the end of the G code type in the character string to obtain the G code file.
[0008] Optionally, based on the quantity, at least each first character information is added after the G code type in the character string to obtain the G code file, including: when the quantity is less than or equal to a predetermined value, each first character information is sequentially added after the G code type in the character string to obtain the G code file.
[0009] Optionally, according to the quantity, at least each first character information is added after the G code type in the character string to obtain the G code file, including: when the quantity is greater than a predetermined value, the second character information is added after the G code type in the character string, wherein the second character information is the predetermined value of the first character information arranged in sequence, the first character information at the end of the second character information is the third character information, and the first character information except the second character information is arranged in sequence to constitute the fourth character information; a line break character is generated, and the line break character and the fourth character information are added in sequence after the third character information to obtain the G code file.
[0010] Optionally, in response to a second predetermined operation acting on the initial interface, the axis identification number of the target moving axis and the first target position information are determined, including: in response to the second predetermined operation acting on the selection identifier and the input identifier, traversing the state of each of the selection identifiers; when the state of the selection identifier is the predetermined state, determining that the moving axis corresponding to the predetermined state is the target moving axis; acquiring the axis identification number corresponding to the target moving axis; reading the information in the input identifier corresponding to the target moving axis to obtain the first target position information.
[0011] According to another aspect of an embodiment of the present invention, a G code generation device is also provided, including: a display unit, used to display an initial interface in response to a first predetermined operation, the initial interface including selection marks of multiple moving axes and input marks of destination positions corresponding to each of the moving axes; a determination unit, used to determine an axis identification number and first target position information of a target moving axis in response to a second predetermined operation acting on the initial interface, the target moving axis being the moving axis whose state of the selection mark is a predetermined state, the predetermined state being characterized by a state in which the selection mark is selected, and the first target position information being information in the input mark corresponding to the target moving axis; a generation unit, used to generate a G code file according to the axis identification number and the first target position information, and send the G code file to a PLC.
[0012] According to yet another aspect of the embodiments of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein the program executes any one of the methods described.
[0013] According to yet another aspect of an embodiment of the present invention, a processor is provided, wherein the processor is used to run a program, wherein any one of the methods is executed when the program is run.
[0014] According to another aspect of an embodiment of the present invention, there is also provided an electronic device, comprising: one or more processors, a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include methods for executing any one of the methods described.
[0015] In an embodiment of the present invention, first, in response to a first predetermined operation, an initial interface including selection marks of multiple moving axes and input marks of corresponding destination positions is displayed; then, in response to a second predetermined operation acting on the initial interface, the axis identification number and first target position information of the target moving axis are determined, the target moving axis is the moving axis selected by the selection mark, and the first target position information is the information in the input mark corresponding to the target moving axis; finally, according to the axis identification number and the first target position information, a G code file is generated, and the G code file is sent to the PLC, so that the PLC runs the G code file to control the corresponding moving axis to perform the corresponding movement. Compared with the existing motion control system, it takes a lot of time and effort to write a program for multiple long-distance simple movements of the control axis or simple movements of multiple axes. The present application does not need to spend a lot of time and effort to write a program for each movement of each moving axis. It only needs to select the moving axis to be moved and input the destination position on the initial interface to generate the corresponding G code file, which ensures that the G code file can be generated relatively simply and quickly, thereby ensuring that the control efficiency of the moving axis is high. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings constituting part of the present application are used to provide a further understanding of the present application. The exemplary embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0017] Figure 1 A schematic flow chart of a method for generating a G code according to an embodiment of the present application is shown;
[0018] Figure 2 A schematic structural diagram of a device for generating a G code according to an embodiment of the present application is shown;
[0019] Figure 3 A working flow chart of an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0020] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0021] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0022] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0023] It should be understood that when an element (such as a layer, film, region, or substrate) is described as being "on" another element, the element may be directly on the other element, or there may be intermediate elements. Moreover, in the specification and claims, when an element is described as being "connected" to another element, the element may be "directly connected" to the other element, or "connected" to the other element through a third element.
[0024] As mentioned in the background technology, in the motion control system of the prior art, it takes a lot of time and effort to write programs for multiple long-distance simple movements of the control axis or simple movements of multiple axes. In order to solve the above problems, in a typical embodiment of the present application, a G-code generation method, generation device, computer-readable storage medium, processor and electronic device are provided.
[0025] According to an embodiment of the present application, a method for generating a G code is provided.
[0026] Figure 1 : is a flow chart of a method for generating a G code according to an embodiment of the present application. Figure 1 As shown, the method comprises the following steps:
[0027] Step S101, in response to a first predetermined operation, an initial interface is displayed, wherein the initial interface includes selection marks of a plurality of moving axes and input marks of destination positions corresponding to the moving axes;
[0028] The above-mentioned G code generation method of the present application can be applied to a terminal. The above-mentioned first predetermined operation is an operation of starting the terminal to run the G code generation method program. The above-mentioned first predetermined operation can be an operation method such as clicking, long pressing, sliding, dragging, etc., such as clicking the start button operation.
[0029] In actual application, each moving axis of the PLC will be displayed in the above initial interface.
[0030] The selection mark may be a selection box, and the input mark may be an input box.
[0031] Specifically, before issuing the above-mentioned first predetermined operation, the user will switch the working mode of the PLC to the automatic mode.
[0032] Step S102, in response to a second predetermined operation performed on the initial interface, determining an axis identification number and first target position information of a target moving axis, wherein the target moving axis is the moving axis whose state of the selection mark is a predetermined state, wherein the predetermined state is characterized by a state in which the selection mark is selected, and the first target position information is information in the input mark corresponding to the target moving axis;
[0033] According to the received second predetermined operation, the selected moving axis and the moving end point of the moving axis are determined, so that a G code file for controlling the corresponding moving axis and controlling the moving axis to move to the corresponding position can be generated more simply and quickly, thereby realizing automatic control of the PLC moving axis.
[0034] The above-mentioned axis identification number is a unique identity identifier of each axis, which can be an axis number, an axis code, an axis serial number, or the name of the axis, etc.
[0035] In actual application, the second predetermined operation may be click, long press, slide, drag and input and other operation modes. In order to further ensure that the axis identification number and the first target position information are determined relatively simply and quickly, in an embodiment of the present application, in response to the second predetermined operation acting on the initial interface, the axis identification number and the first target position information of the target moving axis are determined, including: in response to the second predetermined operation acting on the selection mark and the input mark, traversing the state of each of the selection marks; when the state of the selection mark is the predetermined state, determining that the moving axis corresponding to the predetermined state is the target moving axis; obtaining the axis identification number corresponding to the target moving axis; reading the information in the input mark corresponding to the target moving axis to obtain the first target position information.
[0036] In a specific embodiment, the second predetermined operation on the selection mark is a click operation, and the second predetermined operation on the input mark is an input operation. In another specific embodiment, the input mark includes multiple drop-down selection marks, and the second predetermined operation on the input mark is a click operation on a certain drop-down selection mark.
[0037] Step S103, generating a G code file according to the axis identification number and the first target position information, and sending the G code file to the PLC.
[0038] The G code file can be automatically generated through the axis identification number and the first target position information, without spending a lot of time and energy to write programs for each movement of each moving axis, ensuring that the G code file can be generated relatively simply and quickly.
[0039] Specifically, the above G code file may be an NPG file.
[0040] In another specific embodiment of the present application, a G-code file is generated according to the above-mentioned axis identification number and the above-mentioned first target position information, including: obtaining the travel range corresponding to the above-mentioned target moving axis; determining the second target position information according to the above-mentioned first target position information and the above-mentioned travel range, wherein, when the above-mentioned first target position information is within the above-mentioned travel range, the above-mentioned first target position information is determined to be the above-mentioned second target position information, and when the above-mentioned first target position information is not within the above-mentioned travel range, the current position of the above-mentioned target moving axis is determined to be the above-mentioned second target position information; the above-mentioned G-code file is generated according to the above-mentioned axis identification number and the above-mentioned second target position information. Since the stroke of each moving axis is limited, in order to avoid the problem of incorrectly generated G-code files due to the position information input by the user being outside the effective stroke of the moving axis, the present application, when the first target position information is obtained and the first target position information is located within the above-mentioned stroke range, indicates that the above-mentioned first target position information is correct, and at this time, determines that the first target position information is the second target position information; when the first target position information is obtained and the first target position information is not located within the above-mentioned formation range, indicates that the above-mentioned first target position information is wrong, and at this time determines that the current position of the target moving axis is the second target position information, that is, generates a G-code file that does not control the movement of the moving axis; and then generates the above-mentioned G-code file based on the above-mentioned axis identification number and the above-mentioned second target position information, further ensuring accurate control of each moving axis and avoiding the influence of control errors on the PLC.
[0041] In order to further ensure that the G-code file is automatically generated relatively simply and quickly, thereby further ensuring that multiple long-distance simple movements of the axis or simple movements of multiple axes are controlled more efficiently, in another embodiment of the present application, the above-mentioned axis identification number and the corresponding second target position information constitute the first character information, and the above-mentioned G-code file is generated according to the above-mentioned axis identification number and the above-mentioned second target position information, including: generating a character string, the above-mentioned character string includes the G-code type; determining the number of the above-mentioned axis identification numbers; according to the above-mentioned number, at least adding each of the above-mentioned first character information to the end of the above-mentioned G-code type in the above-mentioned character string to obtain the above-mentioned G-code file.
[0042] In the embodiment of the present application, the above-mentioned G code type is G01, and its function is to move the moving axis to a specified position.
[0043] In a specific embodiment, according to the above number, at least each of the above first character information is added to the back of the above G code type in the above character string to obtain the above G code file, including: when the above number is less than or equal to the predetermined value, each of the above first character information is sequentially added to the back of the above G code type in the above character string to obtain the above G code file. Since the number of moving axes controlled by the PLC at one time is limited, that is, the above predetermined value, in this embodiment of the present application, when the above number is less than or equal to the predetermined value, the generated G code does not need to be wrapped, therefore, each of the above first character information is directly added to the back of the above G code type in the above character string in sequence to obtain the G code file, which further ensures that the G code file is automatically generated relatively simply and quickly, and further solves the problem that it takes a lot of time and effort to write a program for multiple long-distance simple movements of the control axis or simple movements of multiple axes in the motion control system of the prior art.
[0044] In actual application, generally, PLC can control 3 moving axes at a time, so the above-mentioned predetermined value can be set to 3. Of course, the above-mentioned predetermined value is not limited to the above-mentioned 3, and can also be other data, which is specifically determined according to the maximum number of moving axes that can be controlled by PLC at a time.
[0045] Specifically, when the above number is 1, it means that only one moving axis is selected, and the content of the string is: "G01 axis identification number second target position information"; when the above number is 2, it means that two moving axes are selected, and the content of the string is: "G01 axis identification number second target position information axis identification number second target position information", and so on.
[0046] Of course, the above-mentioned number may also exceed the above-mentioned predetermined value. In order to further ensure the accurate and fast generation of the G code file in this case, in another embodiment, according to the above-mentioned number, at least each of the above-mentioned first character information is added after the above-mentioned G code type in the above-mentioned character string to obtain the above-mentioned G code file, including: when the above-mentioned number is greater than the predetermined value, the second character information is added after the above-mentioned G code type in the above-mentioned character string, wherein the above-mentioned second character information is the above-mentioned predetermined value of the above-mentioned first character information arranged in sequence, the above-mentioned first character information at the end of the above-mentioned second character information is the third character information, and the above-mentioned first character information except the above-mentioned second character information is arranged in sequence to constitute the fourth character information; generate a line feed character, and add the above-mentioned line feed character and the above-mentioned fourth character information in sequence after the above-mentioned third character information to obtain the above-mentioned G code file.
[0047] For example, when the number is 4, the content of the string is: "G01 axis identification number second target position information axis identification number second target position information axis identification number second target position information line break axis identification number second target position information"
[0048] In other embodiments, according to the above-mentioned quantity, at least each of the above-mentioned first character information is added to the back of the above-mentioned G code type in the above-mentioned character string to obtain the above-mentioned G code file, which may also include: an adding step, when the above-mentioned quantity is greater than a predetermined value, adding the second character information to the back of the above-mentioned G code type in the above-mentioned character string, wherein the above-mentioned second character information is the above-mentioned predetermined value of the above-mentioned first character information arranged in sequence, and the above-mentioned first character information located at the end of the above-mentioned second character information is the third character information; a first generating step, generating a line feed character, and adding the above-mentioned line feed character to the back of the above-mentioned third character information; a determining step, determining whether the number of the above-mentioned axis identification numbers other than the above-mentioned second character information is greater than the above-mentioned predetermined value; a second generating step, in the above-mentioned axis identification numbers other than the above-mentioned second character information When the number of the axis identification numbers other than the second character information is greater than the predetermined value, generate new second character information according to the first character information except the second character information, and add the new second character information to the back of the second character information in the character string; perform the second generation step, the first generation step and the determination step at least once in sequence until the number of the axis identification numbers other than the second character information is less than or equal to the predetermined value, and when the number of the axis identification numbers other than the second character information is less than or equal to the predetermined value, arrange the first character information other than the second character information in sequence to obtain the fourth character information, and add the fourth character information to the back of the last line break in the character string to obtain the G code file.
[0049] In practical applications, the above number can be counted by a counter, and the initial value of the counter is 0.
[0050] In the above-mentioned G code generation method, firstly, in response to the first predetermined operation, an initial interface including selection marks of multiple moving axes and input marks of corresponding destination positions is displayed; then, in response to the second predetermined operation acting on the above-mentioned initial interface, the axis identification number and the first target position information of the target moving axis are determined, the above-mentioned target moving axis is the above-mentioned moving axis selected by the above-mentioned selection mark, and the above-mentioned first target position information is the information in the above-mentioned input mark corresponding to the above-mentioned target moving axis; finally, according to the axis identification number and the above-mentioned first target position information, a G code file is generated, and the above-mentioned G code file is sent to the PLC, so that the PLC runs the G code file to control the corresponding moving axis to perform the corresponding movement. Compared with the existing motion control system, it takes a lot of time and effort to write a program for multiple long-distance simple movements of the control axis or simple movements of multiple axes. The present application does not need to spend a lot of time and effort to write a program for each movement of each moving axis. It only needs to select the moving axis to be moved and input the destination position on the initial interface to generate the corresponding G code file, which ensures that the G code file can be generated relatively simply and quickly, thereby ensuring that the control efficiency of the moving axis is high.
[0051] Furthermore, compared with the manual control in the prior art, the above method of the present application can realize multiple long-distance simple movements of the automatic control axis or simple movements of multiple axes without manual operation, thus saving labor costs.
[0052] The current manual control method is suitable for simple single-axis motion, and the automatic method is suitable for repeated complex motion. This application is suitable for multiple different multi-axis motions, which can effectively reduce the time and effort required for programming G code. This application can automatically generate a G code file for simple motion control. The user only needs to check the axis that needs to be moved and enter the end point of the axis in the corresponding data input box. The G code file can be automatically generated and automatically imported into the PLC, and the user only needs to click Start to complete the control of the axis.
[0053] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0054] The embodiment of the present application also provides a G code generation device. It should be noted that the G code generation device of the embodiment of the present application can be used to execute the G code generation method provided in the embodiment of the present application. The G code generation device provided in the embodiment of the present application is introduced below.
[0055] Figure 2 Schematic diagram of a device for generating a G code according to an embodiment of the present application. Figure 2 As shown, the device comprises:
[0056] The display unit 10 is used to display an initial interface in response to a first predetermined operation, wherein the initial interface includes selection marks of a plurality of moving axes and input marks of destination positions corresponding to the plurality of moving axes;
[0057] The above-mentioned G code generation device of the present application can be applied to a terminal. The above-mentioned first predetermined operation is an operation of starting the terminal to run the G code generation device program. The above-mentioned first predetermined operation can be an operation method such as clicking, long pressing, sliding, dragging, etc., such as clicking the start button operation.
[0058] In actual application, each moving axis of the PLC will be displayed in the above initial interface.
[0059] The selection mark may be a selection box, and the input mark may be an input box.
[0060] Specifically, before issuing the above-mentioned first predetermined operation, the user will switch the working mode of the PLC to the automatic mode.
[0061] The determining unit 20 is used to determine the axis identification number and the first target position information of the target moving axis in response to the second predetermined operation acting on the initial interface, the target moving axis is the moving axis whose state of the selection mark is a predetermined state, the predetermined state is characterized by the state that the selection mark is selected, and the first target position information is the information in the input mark corresponding to the target moving axis;
[0062] According to the received second predetermined operation, the selected moving axis and the moving end point of the moving axis are determined, so that a G code file for controlling the corresponding moving axis and controlling the moving axis to move to the corresponding position can be generated more simply and quickly, thereby realizing automatic control of the PLC moving axis.
[0063] The above-mentioned axis identification number is a unique identity identifier of each axis, which can be an axis number, an axis code, an axis serial number, or the name of the axis, etc.
[0064] In actual application, the second predetermined operation may be click, long press, slide, drag and input and other operation modes. In order to further ensure that the axis identification number and the first target position information are determined relatively simply and quickly, in an embodiment of the present application, the determination unit includes: a traversal module, for traversing the state of each of the selection identifiers in response to the second predetermined operation acting on the selection identifier and the input identifier; a first determination module, for determining that the moving axis corresponding to the predetermined state is the target moving axis when the state of the selection identifier is the predetermined state; a first acquisition module, for acquiring the axis identification number corresponding to the target moving axis; and a reading module, for reading the information in the input identifier corresponding to the target moving axis to obtain the first target position information.
[0065] In a specific embodiment, the second predetermined operation on the selection mark is a click operation, and the second predetermined operation on the input mark is an input operation. In another specific embodiment, the input mark includes multiple drop-down selection marks, and the second predetermined operation on the input mark is a click operation on a certain drop-down selection mark.
[0066] The generating unit 30 is used to generate a G code file according to the axis identification number and the first target position information, and send the G code file to the PLC.
[0067] The G code file can be automatically generated through the axis identification number and the first target position information, without spending a lot of time and energy to write programs for each movement of each moving axis, ensuring that the G code file can be generated relatively simply and quickly.
[0068] Specifically, the above G code file may be an NPG file.
[0069] In another specific embodiment of the present application, the generation unit includes: a second acquisition module, used to acquire the travel range corresponding to the above-mentioned target moving axis; a second determination module, used to determine the second target position information based on the above-mentioned first target position information and the above-mentioned travel range, wherein, when the above-mentioned first target position information is within the above-mentioned travel range, the above-mentioned first target position information is determined to be the above-mentioned second target position information, and when the above-mentioned first target position information is not within the above-mentioned travel range, the current position of the above-mentioned target moving axis is determined to be the above-mentioned second target position information; a generation module, used to generate the above-mentioned G code file based on the above-mentioned axis identification number and the above-mentioned second target position information. Since the stroke of each moving axis is limited, in order to avoid the problem of incorrectly generated G-code files due to the position information input by the user being outside the effective stroke of the moving axis, the present application, when the first target position information is obtained and the first target position information is located within the above-mentioned stroke range, indicates that the above-mentioned first target position information is correct, and at this time, determines that the first target position information is the second target position information; when the first target position information is obtained and the first target position information is not located within the above-mentioned formation range, indicates that the above-mentioned first target position information is wrong, and at this time determines that the current position of the target moving axis is the second target position information, that is, generates a G-code file that does not control the movement of the moving axis; and then generates the above-mentioned G-code file based on the above-mentioned axis identification number and the above-mentioned second target position information, further ensuring accurate control of each moving axis and avoiding the influence of control errors on the PLC.
[0070] In order to further ensure that the G-code file is automatically generated relatively simply and quickly, thereby further ensuring that multiple long-distance simple movements of the axis or simple movements of multiple axes are controlled more efficiently, in another embodiment of the present application, the above-mentioned axis identification number and the corresponding second target position information constitute the first character information, and the above-mentioned generation module includes: a generation submodule, used to generate a character string, and the above-mentioned character string includes a G-code type; a determination submodule, used to determine the number of the above-mentioned axis identification numbers; an addition submodule, used to add at least each of the above-mentioned first character information to the end of the above-mentioned G-code type in the above-mentioned character string according to the above-mentioned number, to obtain the above-mentioned G-code file.
[0071] In the embodiment of the present application, the above-mentioned G code type is G01, and its function is to move the moving axis to a specified position.
[0072] In a specific embodiment, the adding submodule is also used to: when the above number is less than or equal to a predetermined value, sequentially add each of the above first character information to the back of the above G code type in the above character string to obtain the above G code file. Since the number of moving axes controlled by the PLC at one time is limited, that is, the above predetermined value, in this embodiment of the present application, when the above number is less than or equal to the predetermined value, the generated G code does not need to wrap, therefore, directly add each of the above first character information sequentially to the back of the above G code type in the above character string to obtain the G code file, which further ensures that the G code file is automatically generated relatively simply and quickly, and further solves the problem in the prior art motion control system that it takes a lot of time and effort to write a program for multiple long-distance simple movements of the control axis or simple movements of multiple axes.
[0073] In actual application, generally, PLC can control 3 moving axes at a time, so the above-mentioned predetermined value can be set to 3. Of course, the above-mentioned predetermined value is not limited to the above-mentioned 3, and can also be other data, which is specifically determined according to the maximum number of moving axes that can be controlled by PLC at a time.
[0074] Specifically, when the above number is 1, it means that only one moving axis is selected, and the content of the string is: "G01 axis identification number second target position information"; when the above number is 2, it means that two moving axes are selected, and the content of the string is: "G01 axis identification number second target position information axis identification number second target position information", and so on.
[0075] Of course, the above-mentioned number may also exceed the above-mentioned predetermined value. In order to further ensure the accurate and quick generation of the G code file in this case, in another embodiment, the above-mentioned adding submodule is also used for: when the above-mentioned number is greater than the predetermined value, adding the second character information to the back of the above-mentioned G code type in the above-mentioned character string, wherein the above-mentioned second character information is the above-mentioned predetermined value of the above-mentioned first character information arranged in sequence, the above-mentioned first character information at the end of the above-mentioned second character information is the third character information, and the above-mentioned first character information except the above-mentioned second character information is arranged in sequence to constitute the fourth character information; generate a line feed character, and add the above-mentioned line feed character and the above-mentioned fourth character information in sequence to the back of the above-mentioned third character information to obtain the above-mentioned G code file.
[0076] For example, when the number is 4, the content of the string is: "G01 axis identification number second target position information axis identification number second target position information axis identification number second target position information line break axis identification number second target position information"
[0077] In other embodiments, the adding submodule can also be used for: an adding step, in the case that the number is greater than a predetermined value, adding the second character information to the back of the G code type in the character string, wherein the second character information is the predetermined value of the first character information arranged in sequence, and the first character information at the end of the second character information is the third character information; a first generating step, generating a line feed character, and adding the line feed character to the back of the third character information; a determining step, determining whether the number of the axis identification numbers other than the second character information is greater than the predetermined value; a second generating step, in the case that the number of the axis identification numbers other than the second character information is greater than the predetermined value, generating the axis identification numbers other than the second character information according to the number of the axis identification numbers other than the second character information. The above-mentioned first character information except the second character information generates new above-mentioned second character information, and adds the new above-mentioned second character information to the back of the above-mentioned second character information in the above-mentioned character string; the above-mentioned second generation step, the above-mentioned first generation step and the above-mentioned determination step are sequentially performed at least once until the number of the above-mentioned axis identification numbers except the above-mentioned second character information is less than or equal to the above-mentioned predetermined value. In the case that the number of the above-mentioned axis identification numbers except the above-mentioned second character information is less than or equal to the above-mentioned predetermined value, the above-mentioned first character information except the above-mentioned second character information is sequentially arranged to obtain fourth character information, and the above-mentioned fourth character information is added to the back of the last above-mentioned newline character in the above-mentioned character string to obtain the above-mentioned G code file.
[0078] In practical applications, the above number can be counted by a counter, and the initial value of the counter is 0.
[0079] In the above-mentioned G code generation device, the display unit responds to the first predetermined operation to display an initial interface including selection marks of multiple moving axes and input marks of corresponding destination positions; the determination unit responds to the second predetermined operation acting on the above-mentioned initial interface to determine the axis identification number and the first target position information of the target moving axis, the above-mentioned target moving axis is the above-mentioned moving axis selected by the above-mentioned selection mark, and the above-mentioned first target position information is the information in the above-mentioned input mark corresponding to the above-mentioned target moving axis; the generation unit generates a G code file according to the axis identification number and the above-mentioned first target position information, and sends the above-mentioned G code file to the PLC, so that the PLC runs the G code file to control the corresponding moving axis to perform the corresponding movement. Compared with the existing motion control system, it takes a lot of time and effort to write a program for multiple long-distance simple movements of the control axis or simple movements of multiple axes. The present application does not need to spend a lot of time and effort to write a program for each movement of each moving axis. It only needs to select the moving axis to be moved and input the destination position on the initial interface to generate the corresponding G code file, which ensures that the G code file can be generated relatively simply and quickly, thereby ensuring that the control efficiency of the moving axis is high.
[0080] Furthermore, compared with the manual control in the prior art, the above-mentioned device of the present application can realize multiple long-distance simple movements of the automatic control axis or simple movements of multiple axes without manual operation, thus saving labor costs.
[0081] The current manual control device is suitable for simple single-axis motion, and the automatic device is suitable for repeated complex motion. This application is suitable for multiple different multi-axis motions, which can effectively reduce the time and effort required for programming G code. This application can automatically generate a G code file for simple motion control. The user only needs to check the axis that needs to be moved and enter the end point of the axis in the corresponding data input box. The G code file can be automatically generated and automatically imported into the PLC, and the user only needs to click Start to complete the control of the axis.
[0082] The above-mentioned G code generation device includes a processor and a memory. The above-mentioned display unit, determination unit and generation unit are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to realize corresponding functions.
[0083] The processor includes a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and the kernel parameters can be adjusted to solve the problem that in the existing motion control system, it takes a lot of time and effort to write programs for multiple long-distance simple movements of the control axis or simple movements of multiple axes.
[0084] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0085] An embodiment of the present invention provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, the above-mentioned G code generation method is implemented.
[0086] An embodiment of the present invention provides a processor, and the processor is used to run a program, wherein the method for generating the G code is executed when the program is run.
[0087] An embodiment of the present invention provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, at least the following steps are implemented:
[0088] Step S101, in response to a first predetermined operation, an initial interface is displayed, wherein the initial interface includes selection marks of a plurality of moving axes and input marks of destination positions corresponding to the moving axes;
[0089] Step S102, in response to a second predetermined operation performed on the initial interface, determining an axis identification number and first target position information of a target moving axis, wherein the target moving axis is the moving axis whose state of the selection mark is a predetermined state, wherein the predetermined state is characterized by a state in which the selection mark is selected, and the first target position information is information in the input mark corresponding to the target moving axis;
[0090] Step S103, generating a G code file according to the axis identification number and the first target position information, and sending the G code file to the PLC.
[0091] The electronic devices in this article can be servers, PCs, PADs, mobile phones, etc.
[0092] In one embodiment, the workflow of the electronic device is as follows: Figure 3 When the electronic device detects that a command (through the first predetermined operation) is input, the check state of the selection mark of the moving axis is checked, the content in the input mark is read, and after completing the check of all the selection marks and input marks, the corresponding G code is generated, and the G code is used to generate an NPG file in the mounting directory of the electronic device through the I / O interface, and the NPG file is sent to the PLC through the OPC server. At this time, the PLC is ready. If the user confirms that the input parameters are correct and presses the start button, the PLC will control the selected moving axis to perform the corresponding moving operation.
[0093] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program for initializing at least the following method steps:
[0094] Step S101, in response to a first predetermined operation, an initial interface is displayed, wherein the initial interface includes selection marks of a plurality of moving axes and input marks of destination positions corresponding to the moving axes;
[0095] Step S102, in response to a second predetermined operation performed on the initial interface, determining an axis identification number and first target position information of a target moving axis, wherein the target moving axis is the moving axis whose state of the selection mark is a predetermined state, wherein the predetermined state is characterized by a state in which the selection mark is selected, and the first target position information is information in the input mark corresponding to the target moving axis;
[0096] Step S103, generating a G code file according to the axis identification number and the first target position information, and sending the G code file to the PLC.
[0097] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0098] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the above-mentioned units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0099] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0100] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0101] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the above-mentioned methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0102] From the above description, it can be seen that the above embodiments of the present application achieve the following technical effects:
[0103] 1) In the above-mentioned G code generation method of the present application, firstly, in response to the first predetermined operation, an initial interface including selection marks of multiple moving axes and input marks of corresponding destination positions is displayed; then, in response to the second predetermined operation acting on the above-mentioned initial interface, the axis identification number and the first target position information of the target moving axis are determined, the above-mentioned target moving axis is the above-mentioned moving axis selected by the above-mentioned selection mark, and the above-mentioned first target position information is the information in the above-mentioned input mark corresponding to the above-mentioned target moving axis; finally, according to the axis identification number and the above-mentioned first target position information, a G code file is generated, and the above-mentioned G code file is sent to the PLC, so that the PLC runs the G code file to control the corresponding moving axis to perform the corresponding movement. Compared with the existing motion control system, it takes a lot of time and effort to write a program for multiple long-distance simple movements of the control axis or simple movements of multiple axes. In this application, there is no need to spend a lot of time and effort to write a program for each movement of each moving axis. It only needs to select the moving axis to be moved and input the destination position on the initial interface to generate the corresponding G code file, which ensures that the G code file can be generated relatively simply and quickly, thereby ensuring that the control efficiency of the moving axis is high.
[0104] 2) In the above-mentioned G code generation device of the present application, the display unit responds to the first predetermined operation to display an initial interface including selection marks of multiple moving axes and input marks of corresponding destination positions; the determination unit responds to the second predetermined operation acting on the above-mentioned initial interface to determine the axis identification number and the first target position information of the target moving axis, the above-mentioned target moving axis is the above-mentioned moving axis selected by the above-mentioned selection mark, and the above-mentioned first target position information is the information in the above-mentioned input mark corresponding to the above-mentioned target moving axis; the generation unit generates a G code file according to the axis identification number and the above-mentioned first target position information, and sends the above-mentioned G code file to the PLC, so that the PLC runs the G code file to control the corresponding moving axis to perform the corresponding movement. Compared with the existing motion control system, it takes a lot of time and effort to write a program for multiple long-distance simple movements of the control axis or simple movements of multiple axes. In this application, there is no need to spend a lot of time and effort to write a program for each movement of each moving axis. It only needs to select the moving axis to be moved and input the destination position on the initial interface to generate the corresponding G code file, which ensures that the G code file can be generated relatively simply and quickly, thereby ensuring that the control efficiency of the moving axis is high.
[0105] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for generating a G code, characterized in that: include: In response to a first predetermined operation, an initial interface is displayed, wherein the initial interface includes a plurality of selection marks of movement axes and an input mark of a destination position corresponding to each of the movement axes; In response to a second predetermined operation on the initial interface, determining an axis identification number and first target position information of a target moving axis, wherein the target moving axis is the moving axis in which the state of the selection mark is a predetermined state, wherein the predetermined state is characterized by the state in which the selection mark is selected, and the first target position information is information in the input mark corresponding to the target moving axis; Generate a G code file according to the axis identification number and the first target position information, and send the G code file to the PLC, Generate a G code file according to the axis identification number and the first target position information, including: Obtaining the travel range corresponding to the target moving axis; Determine the second target position information according to the first target position information and the travel range, wherein, when the first target position information is within the travel range, the first target position information is determined to be the second target position information, and when the first target position information is not within the travel range, the current position of the target moving axis is determined to be the second target position information; generating the G code file according to the axis identification number and the second target position information, One of the axis identification numbers and the corresponding second target position information constitutes the first character information, and the G code file is generated according to the axis identification number and the second target position information, including: Generate a character string, wherein the character string includes a G code type; determining the number of the axis identification numbers; According to the number, at least each of the first character information is added after the G code type in the character string to obtain the G code file, According to the quantity, at least each of the first character information is added after the G code type in the character string to obtain the G code file, including: When the number is greater than a predetermined value, the second character information is added after the G code type in the character string, wherein the second character information is the predetermined value of the first character information arranged in sequence, the first character information at the end of the second character information is the third character information, and the first character information except the second character information is arranged in sequence to constitute the fourth character information; Generate a line break character, and sequentially add the line break character and the fourth character information to the end of the third character information to obtain the G code file.
2. The method according to claim 1, characterized in that According to the quantity, at least each of the first character information is added after the G code type in the character string to obtain the G code file, including: When the number is less than or equal to a predetermined value, each of the first character information is sequentially added after the G code type in the character string to obtain the G code file.
3. The method according to claim 1 or 2, characterized in that: In response to a second predetermined operation acting on the initial interface, determining an axis identification number of a target moving axis and first target position information includes: In response to the second predetermined operation acting on the selection mark and the input mark, traversing the states of the selection marks; When the state of the selection mark is the predetermined state, determining the moving axis corresponding to the predetermined state as the target moving axis; Obtaining the axis identification number corresponding to the target moving axis; The information in the input identifier corresponding to the target moving axis is read to obtain the first target position information.
4. A G-code generating device, characterized in that: include: A display unit, configured to display an initial interface in response to a first predetermined operation, wherein the initial interface includes selection marks of a plurality of moving axes and input marks of destination positions corresponding to the moving axes; a determination unit, configured to determine, in response to a second predetermined operation performed on the initial interface, an axis identification number of a target moving axis and first target position information, wherein the target moving axis is the moving axis in which the state of the selection mark is a predetermined state, wherein the predetermined state is characterized by a state in which the selection mark is selected, and the first target position information is information in the input mark corresponding to the target moving axis; a generating unit, configured to generate a G code file according to the axis identification number and the first target position information, and send the G code file to the PLC, The generating unit comprises: A second acquisition module is used to acquire the travel range corresponding to the target moving axis; A second determination module is used to determine the second target position information according to the first target position information and the travel range, wherein, when the first target position information is within the travel range, the first target position information is determined to be the second target position information, and when the first target position information is not within the travel range, the current position of the target moving axis is determined to be the second target position information; A generating module, used for generating the G code file according to the axis identification number and the second target position information, One of the axis identification numbers and the corresponding second target position information constitutes the first character information, and the generating module includes: A generating submodule, used for generating a character string, wherein the character string includes a G code type; A determination submodule, used to determine the number of the axis identification numbers; an adding submodule, for adding at least each of the first character information to the back of the G code type in the character string according to the quantity, to obtain the G code file, The adding submodule is also used to: When the number is greater than a predetermined value, the second character information is added after the G code type in the character string, wherein the second character information is the predetermined value of the first character information arranged in sequence, the first character information at the end of the second character information is the third character information, and the first character information except the second character information is arranged in sequence to constitute the fourth character information; Generate a line break character, and sequentially add the line break character and the fourth character information to the end of the third character information to obtain the G code file.
5. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method of any one of claims 1 to 3.
6. A processor, characterized in that: The processor is used to run a program, wherein the program executes the method according to any one of claims 1 to 3 when running.
7. An electronic device, characterized in that: include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include methods for executing any one of claims 1 to 3.
Citation Information
Patent Citations
Generation method and generation device of G code processing file, and processor
CN112859748A
Numerical control device
US20150253758A1