Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the technical solutions of the present invention are described below clearly and completely, and it is obvious that the described embodiments are some, not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Notation and terminology interpretation:
H-BOT: the synchronous belt transmission mechanism is simplified after Corexy;
an OLED: organic Light-Emitting diodes (OLEDs);
g code: the G code is an instruction in the numerical control program. Commonly referred to as G instructions. The fast positioning, the inverse circle interpolation, the forward circle interpolation, the middle point circular arc interpolation, the radius programming and the skip processing can be realized by using the G code;
l Xe |: the total number of steps the cutter should travel in the X-axis direction;
i Ye i: the total number of steps the cutter should travel in the Y-axis direction;
f: a deviation value;
when the linear interpolation starts, F is equal to 0,
when the moving point passes through the coordinate axis, when Xc is 0 and Yc >0, the moving point passes through the positive half axis of the Y axis, and the rest is analogized in turn.
For convenience of description, some symbols are first defined as follows:
l: a straight line;
SR: following a circular arc;
NR: reverse circular arc;
number of subscript: quadrant of curve:
l1, L2, L3 and L4: quadrant 1, 2, 3, and 4 straight lines;
SR1, SR2, SR3, and SR 4: quadrants 1, 2, 3 and 4 follow the arc;
NR1, NR2, NR3 and NR 4: quadrants 1, 2, 3 and 4 are the inverse arcs.
Fi+1=Fi-2|Yi|+1
Fi+1=Fi+2|Xi|+1
Fi+1=Fi-2|Xi|+1
Fi+1=Fi+2|Yi|+1。
FiIs the interpolated deviation value, Xi,YiIs the coordinate of the moving point. Calculating deviation value to judge the next step Fi+1Direction of circular interpolation.
The system structure for implementing the invention needs to have the following functions:
the invention mainly realizes serial asynchronous communication, OLED display, independent key, serial data analysis, G code analysis, forward and reverse rotation of a stepping motor, linear interpolation and circular interpolation cross-quadrant.
(1) The serial port asynchronous communication is mainly used for completing real-time data transmission from the upper computer to the lower computer, the lower computer analyzes and executes movement by receiving the data of the upper computer, and specific parameters are returned after the movement is completed;
the USART serial communication is asynchronous communication configured through STM32, and data transmission between the upper computer and the lower computer is realized.
(2) The display module displays the current target position coordinate and the last state position coordinate, provides a human-computer interaction interface and can realize real-time monitoring on drawing;
the OLED display realizes a human-computer interaction interface on the singlechip through a 4-wire SPI communication interface.
(3) And independent keys are used for scanning whether the keys are pressed down or not, flag bits are set, if the conditions are met, the system is entered for drawing, and if not, the system exits from the drawing and waits for starting.
The independent key realizes the start-stop mode of the system through the selection of the key.
(4) And (3) data analysis, namely extracting floating point numbers starting from specified characters in the character string, stopping when non-numeric characters are encountered, and assigning values to double-precision floating point numbers.
The data analysis is to analyze the serial port data sent by the upper computer into corresponding specific numerical values.
(5) And G code analysis, wherein different state values are set according to the read G code, and the different state values are used for selecting the working modes of the following linear interpolation and circular interpolation.
(6) The normal operation of the stepping motor needs an annular distribution circuit and a pulse amplification circuit, but the driving module of the stepping motor adopted by the invention can automatically generate four paths of driving circuit signals only by inputting one pulse signal. Therefore, the purposes of forward and reverse rotation and speed regulation are achieved by configuring different state values of the DIR pin and the frequency of the pulse signals connected with the DIR of the A4988 module.
The stepping motor is controlled by setting the received G code into different state values, assigning coordinate values and selecting different motion modes.
(7) The invention adopts the optimization algorithm of the linear interpolation, and reduces the bytes occupied by the linear interpolation program in the singlechip.
(8) Circular interpolation, traditional circular interpolation can only accomplish circular interpolation in single quadrant, and this design adopts four-quadrant circular interpolation, has solved the problem that circular interpolation can not stride the quadrant.
A control system method based on an H-BOT structure is characterized by comprising the following steps:
step 1, initializing the system, pressing a key, inputting data from a serial port to a control module, and enabling the OLED to enter a main interface of the system.
Step 2, the control module analyzes the data, including extracting floating point numbers starting from specified characters in the character string, stopping when non-numeric characters are encountered, and assigning values to double-precision floating point numbers; the control module analyzes the G code.
Step 3, the control module judges motion control or steering engine control according to the input instruction;
if the linear interpolation is used in motion control, the pulse frequency is calculated, the stepping motor is controlled to move to a specified position, and the control module, namely the lower computer returns data to the upper computer through a serial port.
The linear interpolation algorithm is an interpolation method which adopts a small line segment to approach a large line segment. Any numerical control system has the capability of processing straight lines in different quadrants, firstly needs to determine four quadrants executed by interpolation, and then executes different interpolation schemes in different judged quadrants.
a. Optimization scheme of linear interpolation:
first, some symbols are defined as follows:
l: a straight line;
number of subscript: the quadrant where the curve is located;
l1, L2, L3 and L4: are quadrant 1, 2, 3 and 4 straight lines, respectively;
linear interpolation of the second quadrant
As shown in fig. 3, when the straight line is in quadrant 2, 3 or 4, the interpolation formula of the straight line in quadrant 1, which is symmetrical to the straight line, can be used for calculation, and only different feeding directions are used according to different quadrants.
That is, the interpolation problem of the 2 nd, 3 rd and 4 th quadrant straight lines can be reduced to the interpolation problem of the 1 st quadrant straight line symmetrical thereto.
The following table shows the interpolation feed direction and the interpolation calculation formula of four quadrant lines
Fig. 5 shows a flowchart of the linear interpolation process in the four quadrants, according to the table above and fig. 4.
The process of the point-by-point comparison linear interpolation mainly comprises four processes of deviation judgment, coordinate feeding, new deviation calculation and end point judgment. The flow shown in fig. 5 is to calculate the total steps Σ to be taken for X, Y coordinate axes. And feeding the X axis and the Y axis by judging the positive and negative of the deviation value F, wherein the negative value of the coordinate feeding is obtained by deviation calculation and table lookup, and finally when sigma is 0, the interpolation is finished.
As shown in fig. 6(a) and 6(b), fig. 6(a) and 6(b) illustrate that if the relative coordinates (Xe, Ye) are (0,4) and the first pass is uniformly determined in the X-axis feed direction, there is an error of root number 2 between (0,4) and (1,3) after the interpolation is completed, the Y-axis feed may be performed first after the determination of | Ye | > | Xe | is completed, and the same applies to (4, 0).
However, the above calculation concept has a disadvantage that if the cutting is performed in the X-axis direction uniformly when F is 0, the error ratio is large for the line of | Ye | > | Xe |, and the maximum error can be reached
Equivalent of one pulse. If we agree to feed uniformly in the Y-axis direction when F is 0, the error is also large for the line | Xe | > | Ye |, and the maximum can be reached similarly
Equivalent of one pulse.
In order to compensate for the above algorithm, assuming that the initial offset value F is 0, the error may be increased whether the first feed to the X axis or the Y axis is agreed.
In order to reduce the error, when F is 0, the process should be performed according to the specific situation of the straight line.
The method comprises the following steps that firstly, one step is appointed to be carried out in the Y-axis direction for a straight line of Ye | > | Xe |;
② for the straight line of | Xe | > | Ye |, one step is agreed to be taken in the X-axis direction.
The linear interpolation flow chart designed according to the improved algorithm is shown in fig. 7.
FIG. 7 is a process of determining the magnitude of | Ye | and | Xe | added to FIG. 5, wherein the total number of steps Σ taken by two coordinate axes is calculated X, Y, the magnitude of | Ye | and | Xe | is determined, and feeding of the X-axis and the Y-axis is performed by determining the positive and negative of the deviation value F, wherein the negative of the coordinate feeding is obtained by deviation calculation and table lookup;
in the case where F is 0, the following process should be performed according to the specific case of the straight line:
the method comprises the following steps that firstly, one step is appointed to be carried out in the Y-axis direction for a straight line of Ye | > | Xe |;
② for a straight line of | Xe | > | Ye |, it is agreed to go one step in the X-axis direction, and finally when Σ is 0, the interpolation is completed.
Simulation test
The simulation test environment is Matlab, linear interpolation of four quadrants is tested, F is 0, the initial state of the linear interpolation is obtained, and an initial feeding direction is given by comparing the X and Y feeding sizes of the absolute coordinates of the target.
As shown in fig. 14, in the first quadrant linear interpolation, the input end point abscissa X, Xe, the output end point coordinate Y, Ye, and h are 100, 30, and 4, respectively.
As shown in fig. 15, in the second quadrant linear interpolation, the input end point coordinate X, Xe, the input end point ordinate Y, Ye, and h are-30, 45, and 1, respectively.
As shown in fig. 16, in the third quadrant linear interpolation, the input end point abscissa X, Xe, the input end point ordinate Y, Ye, and the input step h are 90, 37, and 3, respectively.
As shown in fig. 17, in the fourth quadrant linear interpolation, the end point abscissa X is input, Xe is-39, the end point ordinate Y is input, Ye is-44, and the input step h is 1.
If the interpolation is circular interpolation, the stepping motor is controlled to move to a designated position, and the detection module returns data to the control module through the serial port.
Aiming at circular interpolation in four quadrants, firstly, analyzing the problem of circular arc trend of a first quadrant along a circular arc in the circular interpolation process except the quadrant problem.
A first quadrant is provided following the arc SE, as shown in fig. 8.
The deviation calculation formula is as follows:
the direction of movement of the tool is
Feeding one step to the-Y direction when the moving point is on the circular arc or in the area outside the circular arc;
and secondly, when the moving point is in the area inside the arc, feeding one step in the + X direction.
Discretizing the deviation value calculation formula to obtain the following calculation table:
summarizing the conditions of the forward arc and the reverse arc of the first quadrant as follows:
comparing these two cases, two features can be found:
(ii) when X, Y is reversed, the feeding direction of SR1 is changed to the feeding direction of NR 1; also the feed direction of NR1 is changed to the feed direction of SR 1.
X, Y is exchanged, the deviation calculation formula of SR1 is converted into a deviation calculation formula of NR 1; also the deviation calculation formula of NR1 is converted into a deviation calculation formula of SR 1.
The interpolation problem of the second, third and fourth quadrant forward circular arcs can be converted into the interpolation problem of the first quadrant reverse circular arc, and the conversion method comprises the following steps:
exchanging X, Y coordinates of the starting point of the circular arc to serve as the starting point of the inverse circular arc of the first quadrant;
the X, Y coordinates of the arc end point are exchanged to be used as the end point of the inverse arc of the first quadrant;
performing interpolation operation on the first quadrant inverse circular arc obtained by conversion:
when the calculation result is-X direction movement, an actual control signal in-Y direction is sent out;
when the calculation result is + Y direction movement, sending out an actual control signal in the + X direction;
symmetry of different quadrant circular interpolation
By analyzing arcs of different directions in other quadrants in a similar manner, the feed direction and deviation calculation formula is shown in fig. 11 and the following table:
(1) SR1 → NR2 (X-axis reversal);
SR1 → NR4 (Y-axis reversal);
SR1 → SR3(X and Y axes are reversed at the same time);
NR1 → SR2 (X-axis reversal);
NR1 → SR4 (Y-axis reversal);
NR1 → NR3 (X-axis, Y-axis are reversed at the same time);
(2) SR1 → NR1(X, Y for exchange);
NR1 → SR1(X, Y exchange);
its features can be summarized as follows:
(1) SR1 → NR2 (X-axis reversal);
SR1 → NR4 (Y-axis reversal);
SR1 → SR3(X and Y axes are reversed at the same time);
the deviation calculation formulas of the four line types of SR1, NR2, SR3 and NR4 are the same.
NR1 → SR2 (X-axis reversal);
SR1 → SR4 (Y-axis reversal);
SR1 → NR3 (X-axis, Y-axis are reversed at the same time);
the formulas for calculating the deviations of the four line types NR1, SR2, NR3 and SR4 are also the same.
(2) SR1 → NR1(X, Y for exchange);
NR1 → SR1(X, Y exchange);
it can be seen that by switching the X, Y signal and changing the feeding direction, the arc interpolation motion of different directions of each quadrant can be completed by performing the interpolation calculation of the arc following the first quadrant or the interpolation calculation of the arc reversing the first quadrant. The flow chart corresponding to the above table is shown in fig. 12.
Explanation of four-quadrant circular interpolation
Aiming at the phenomenon that the circular arc crosses a quadrant and enters and exits from the original four-quadrant interpolation, after the coordinate of an H-Bot structure is converted, the recorded position often has the characteristic of trans-quadrant, and the four-quadrant circular interpolation cannot meet the requirement.
The straight line can only be in one quadrant, so there is no over-quadrant problem. However, the arc may span several quadrants, and corresponding processing is required at the junction of two quadrants, which is the problem of the arc crossing the quadrants.
When the circular arc passes through the quadrant, the device has the following characteristics:
firstly, before and after passing through a quadrant, the sign of a moving point coordinate is changed;
and ② after passing through the quadrant, the trend of the arc is unchanged.
The sequence of the inverse circular arc passing through the quadrant is as follows: NR1 → NR2 → NR3 → NR4 → NR1 → ·
The sequence of passing through the quadrants along the circular arc is as follows: SR1 → SR4 → SR3 → SR2 → SR1 → · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · → SR's → SR4 → SR 3526 → SR2 → SR
And thirdly, the quadrant-passing circular arc and the coordinate axis have intersection points, and when the moving point is on the coordinate axis, a coordinate value is zero. This point may be used as a sign of over-quadrant.
And fourthly, judging the end point, wherein the three methods cannot be directly used simply, and otherwise, a part of circular arc outline is lost.
The three methods are respectively as follows:
1. determining the distance of the moving point from the centre of the circle, i.e.
2. In the ordinary circular interpolation of the judgment quadrant,
Fi+1=Fi-2Yi+1
Fi+1=Fi+2Xi+1
3. by using the novel circular interpolation of symmetry,
Fi+1=Fi-2|Yi|+1
Fi+1=Fi+2|Xi|+1
Fi+1=Fi-2|Xi|+1
Fi+1=Fi+2|Yi|+1
according to the idea of circular interpolation mentioned in the theory of linear and circular interpolation across arbitrary quadrants research and trajectory simulation-Wangweig, only the number of intersection points between the circular arc at the starting point of the circular interpolation and the circular arc at the end point needs to be judged for several times. The invention does not need to carry out the judgment, judges the quadrant where the moving point is positioned again after each interpolation is finished, and can skillfully avoid calculating the number of intersection points of the circular arc and the coordinate axis.
The process of the circular interpolation across quadrants can be completed only by continuously judging the quadrant of the moving point in the process of the circular interpolation and then carrying out the ordinary circular interpolation program. One of the difficulties is how to judge the coordinate system where the next movement trend of the moving point is when the moving point moves on the coordinate axis, and the following conclusions can be drawn because the movement trends of the forward and backward arcs are different. If it is on the coordinate axis, then,
clockwise arc:
if (Xc ═ 0& & Yc >0) motion trend is the first quadrant
if (Xc >0& & Yc ═ 0) motion trend is fourth quadrant
if (Xc ═ 0& & Yc <0) motion trend is the third quadrant
if (Xc <0& & Yc ═ 0) motion trend is the second quadrant
Counterclockwise arc:
if (Xc ═ 0& & Yc >0) motion trend is the second quadrant
if (Xc <0& & Yc ═ 0) motion trend is the third quadrant
if (Xc ═ 0& & Yc <0) motion trend is the fourth quadrant
if (Xc >0& & Yc ═ 0) motion trend is the first quadrant
The method avoids sacrificing the calculation time of the floating point number of the singlechip. Compared with the interpolation algorithm mentioned in the literature of 'any quadrant crossing linear and circular interpolation principle research and track simulation' adopted before, the method is simpler and faster.
The invention receives and analyzes a sentence of G code to execute, and executes an interpolation process after the sentence of G code is analyzed. The stm32 single chip microcomputer is a 32-bit microcontroller with ARM core-M3 as a carrier, is an MCU with the highest operation speed except a DSP in the same price, and can meet the normal working requirement.
Simulation environment Matlab, circular interpolation data content:
as shown in fig. 18, the input end point abscissa Xc, Xc is 70, the input end point ordinate Yc, Yc is 71, the input end point abscissa X, Xt is 56, the input end point ordinate Y, Yt is-82, the input bsiscw 0- > clockwise, 1- > counterclockwise, bsisccw is 0, and the step length is 227.
As shown in fig. 19, across the first and second quadrants, the input end abscissa Xc, Xc is 70, the input end ordinate Yc, Yc is 71, the input end abscissa X, Xt is-94, the input end ordinate Y, Yt is 34, the input bsicw 0- > clockwise 1- > counterclockwise, bsicw 1, and the step length is 259.
As shown in fig. 20, in the interpolation of the optimal arc, the end point abscissa Xc, Xc-59, the end point ordinate Yc, Yc-81, the end point abscissa X, Xt-94, the end point ordinate Y, Yt-34, the input bsiscw 0- > clockwise 1- > counterclockwise, bsiscw 1, and the step 644.
As shown in fig. 21, in the round interpolation, the input end point abscissa Xc, Xc equals 100, the input end point ordinate Yc, Yc equals 0, the input end point abscissa X, Xt equals 100, the input end point ordinate Y, Yt equals 0, the input bsiscw 0- > clockwise 1- > counterclockwise, bsiscw equals 0, and the step size equals 800.
As shown in fig. 22, 1/4 is interpolated by circular interpolation, where the input end point abscissa Xc, Xc is 100, the input end point ordinate Yc, Yc is 0, the input end point abscissa X, Xt is 0, the input end point ordinate Y, Yt is 100, the input bsicw 0- > clockwise 1- > counterclockwise, bsicw 1, and the step size is 200.
The further technical scheme of the invention is that the control system of the H-BOT structure comprises: the control module, the OLED module, the independent keys and the stepping motor;
the control module is provided with a serial port asynchronous communication, data analysis and G code analysis functional unit;
the DIR pin of the control module controls the positive and negative rotation of the stepping motor by inputting different pulse signal frequencies and configuring different state values;
the control module is in signal connection with the OLED module and the independent key module through serial asynchronous communication interfaces of the control module.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.