Disclosure of Invention
Aiming at the defects of the existing method, the invention solves the problems of longer running track of the mechanical arm and poor path optimizing performance in the existing method.
The technical scheme adopted by the invention is as follows: a material sorting mechanical arm path planning method and system based on an improved ant colony algorithm comprises the following steps:
step one, constructing a three-dimensional space plane of a mechanical arm, and extracting grid points required by a three-dimensional path from the three-dimensional space by adopting an equal space method;
modeling threat and topographic obstacle in the mechanical arm environment;
step three, constructing an objective function in the operation process of the mechanical arm;
step four, constructing a preparation check point set, and calculating the number of sections;
further, the formula of the number of the sections is:
wherein L is sg (x) S is the distance between the starting point and the end point along the X-axis direction w Is the width of the section.
The width of the section is set as an adjustable parameter, so that the acceleration change times of joints of the mechanical arm are reduced, and the mechanical arm operates more stably.
Step five, obtaining a theoretical shortest path of the mechanical arm according to the starting point and the end point of the path of the track of the mechanical arm; taking a tangent plane formed by any two axes, rounding the intersection point of the theoretical shortest path and the tangent plane, constructing a plurality of rectangular ranges by taking the rounded intersection point as the center, and uniformly selecting a plurality of preparation check points in each rectangular range;
further, culling is performed when the preliminary checkpoints are duplicate points or outside the map range.
Compared with the existing method for uniformly taking the points on the whole tangent plane, the method has the advantages that the points are taken by setting different rectangles, and on the premise of keeping global exploration capacity, the refinement and the accuracy are considered, so that the probability of obtaining a better path by an algorithm is greatly improved.
And step six, constructing an improved ant algorithm, and optimizing the track path of the mechanical arm.
Further, the method specifically comprises the following steps:
step 61, initializing ant colony parameters, and calculating heuristic values between each check point and a next layer of check points;
further, the calculation formula of the heuristic value is:
wherein, (x) i ,y i ,z i ) For the coordinate value of the current checkpoint i, (x) j ,y j ,z j ) Is the coordinate value of the next layer check point j.
Step 62, ants search feasible paths, and the ants start from a starting point and select the next road point according to a roulette mode;
step 63, checking the obtained path and updating the local pheromone to obtain the pheromone change value of the checked path; fitting the road points obtained by ants into a track of the movement of the mechanical arm, and calculating the movement track path of the end effector and the angle variation of each joint;
further, the formula for obtaining the pheromone change value of the inspected path is as follows:
wherein item is the current iteration number, t is the number of times the search road section is searched, item_max is the maximum iteration number, and the local pheromone intensity Q is a constant; l (L) path (tk) represents the length of the current whole path; deltaτ i,j (t) is the old pheromone change value transferred from grid point i to grid point j.
Step 64, improving the pheromone volatilization factor of the current iteration pheromone change value;
further, the formula for improving the pheromone volatilization factor is as follows:
in the method, in the process of the invention,representing a global volatility constraint coefficient; c is a compensation coefficient, iter is the current iteration number, ρ (iter) represents the pheromone volatilization factor in the ith iteration, ρ min Is the minimum value of the pheromone volatilization factors.
The invention has the beneficial effects that:
1. the ant colony algorithm can select a passing check point, and after a starting point and a finishing point of the conveying are determined in consideration of the working environment of the material sorting mechanical arm, the working space of the mechanical arm is cut along the X-axis direction, and a series of cut surfaces are generated between the starting point and the finishing point; then constructing a straight line according to the positions of the starting point and the end point, wherein the straight line and each tangent plane have an intersection point, constructing a rectangular range by taking the intersection point as a center, and uniformly selecting a preparation check point in the rectangular range; compared with the original method for uniformly taking the points on the whole tangent plane, the point taking mode has the advantages that on the premise of keeping global exploration capacity, the refinement and the accuracy are considered, so that the probability of obtaining a better path by an algorithm is greatly improved;
2. the improvement of ant colony pheromone updating, which is to improve the pheromone updating mode of an ant colony algorithm, in the local updating, for the paths obtained by ant exploration, the path segments on the paths are checked, and different pheromone updating modes are set for the non-passing path segments, the previously searched path segments and the previously unsearched path segments; setting the pheromone value to be-1 on the road section which cannot pass, wherein the probability of being selected in the next iteration is 0 because the initial pheromone value is 1; the searched path segment is updated with pheromone according to the current searched path length; the newly searched path segment starts to increase more pheromones, so that the probability of being selected next time is increased, and along with the increase of the iteration times, the pheromones obtained by the newly searched path segment are gradually reduced, so that the environmental factors can be effectively controlled and regulated;
3. when the global pheromone is updated, the pheromone volatilization coefficient has self-adaptive characteristic, and changes along with the change of the iteration times, the adjustment strategy of the global pheromone volatilization coefficient can effectively control and optimize the system performance, and can better overcome the local optimum, thereby more effectively exploring the global optimum solution.
Detailed Description
The invention will be further described with reference to the accompanying drawings and examples, which are simplified schematic illustrations showing only the basic structure of the invention and thus showing only those constructions that are relevant to the invention.
As shown in fig. 1, the method and the system for planning the path of the material sorting mechanical arm based on the improved ant colony algorithm comprise the following steps:
step one, constructing a three-dimensional space plane of a working space of a mechanical arm, and extracting grid points required by a three-dimensional path from the three-dimensional space by adopting an equal space dividing method;
as shown in fig. 2, the working space of the mechanical arm is determined by taking the vertex of the lower left corner of the three-dimensional map as the coordinate origin a of the three-dimensional space, and a three-dimensional coordinate system is established at the point a, wherein the X axis is along the increasing direction of longitude, the Y axis is along the increasing direction of latitude, and the Z axis is perpendicular to the sea level direction.
Taking the point A as the vertex, taking the maximum length AB=n of the three-dimensional map along the X-axis direction, taking the maximum length AD=m of the three-dimensional map along the Y-axis direction, and taking the maximum length AA 1=h of the three-dimensional map along the Z-axis direction, so that a cube region ABCD-A1B1C1D1 containing the three-dimensional map is constructed, wherein the region is the planning space of the three-dimensional path.
After the three-dimensional path space is established, grid points required by the three-dimensional path are extracted from the three-dimensional space by adopting a method of equally dividing the space; dividing a space ABCD-A1B1C1D1 into n parts along an X-axis side AB to obtain n+1 YZ planes; secondly, dividing the n+1 planes into m parts along the Y-axis side AD equally to obtain m+1 XZ planes; dividing the plane into h parts along the Z-axis edge AA1 equally to obtain h+1 XY planes; and finally, solving the grid points of which the inner intersection points are used for the ant colony algorithm planning.
The intersection points of the planes in the three-dimensional space are grid points for an ant colony algorithm; because the workspace is not necessarily a cube, a generalized length setting is employed.
Modeling threats and topographic barriers in the environment;
after the three-dimensional path space is built, modeling is carried out on threats and topographic barriers in the environment, and a threat equivalent topographic mathematical model can be obtained:
where z (x, y) is a terrain elevation function, x and y are the abscissa and ordinate, respectively, of a point on the horizontal projection plane, and z is the corresponding terrain elevation at the horizontal projection plane coordinate point (x, y);representing the center coordinates of the jth peak;And->The attenuation of the jth peak along the X axis and the Y axis is respectively used for controlling the gradient; h is a 0 The reference height of the terrain is the ground height without threat or obstacle; n is the number of threats and obstructions;maximum height for the jth threat or obstacle;And->Is a parameter for controlling the range of influence of a threat or obstacle; t (T) j Is the range of influence on the j-th threat or obstacle horizontal projection plane.
By changing these parameters in the threat equivalent terrain mathematical model as shown in fig. 3, threat equivalent peak terrain can be simulated, and peaks of different numbers, heights and slopes can be realized.
Step three, constructing an adaptability value of an objective function in the operation process of the mechanical arm;
after threat equivalent terrain model is adopted, setting the starting point of the track path of the mechanical arm as P s (x s ,y s ,z s ) The end point is P g (x g ,y g ,z g ) The starting point and the end point are required to be unable to be obstacle points, so that raster data of threat equivalent terrain in a raster map is obtained, and passable raster points are determined; in addition, the mechanical arm requires as few joint accumulated rotation angles as possible in the running process so as to reduce energy consumption, and can not collide with obstacles for running safety and stability; constructing an optimized fitness value f of the objective function according to the requirements K The objective function is formed by obstacle avoidance objective f CO Shortest path f of motion track of mechanical arm end effector l And a minimum target f for each joint angle change Q The composition, formula is as follows:
f K =f CO *(η 1 f Q +η 2 f l )(2)
wherein eta 1 And v 2 Is f Q 、f l Weight coefficient f of (1) CO Is an obstacle avoidance target; f when collision occurs CO =inf, when no collision occursAt time f CO =1。
Step four, constructing a preparation check point set allow, and initializing parameters; between the starting point and the end point, according to the set section width S along the X-axis section w Calculating the number S of the sections n The method comprises the steps of carrying out a first treatment on the surface of the Number of cut surfaces S n The calculation mode is as shown in formula (3):
wherein L is sg (x) For starting point P s (x s ,y s ,z s ) And endpoint P g (x g ,y g ,z g ) In the X-axis direction, i.e. L sg (x)=|x s -x g |,S w Is the width of the section.
The section width S of the invention w Is set according to the mechanical properties, e.g. S w The mechanical arm running route is formed by a plurality of sections of straight lines which are not shorter than 20, so that the mechanical arm can have a longer straight running route when running, the joint speed is not changed drastically, the joint acceleration is not changed frequently, and the mechanical arm running is more stable; the first step of the ant colony algorithm is to carry an object from the a side to the b side according to the working condition of the mechanical arm, coincide the carrying direction of the a-b with the X-axis direction and carry out the cutting operation.
Step five, according to the starting point P of the track path of the mechanical arm s (x s ,y s ,z s ) And endpoint P g (x g ,y g ,z g ) Is the theoretical shortest path L for position determination small The equation for the straight line is constructed as follows:
wherein, (x) s ,y s ,z s ) Is the coordinates of the path start point s, (x) g ,y g ,z g ) For the coordinates of the path end point g, the parameter t E [0,1],tStart point coordinates when=0 and end point coordinates when t=1.
As shown in FIG. 6, the shortest path L is exemplified by a section formed by the Y-axis and the Z-axis (XY-axis, XZ-axis may be used) small The method has the advantages that the method has intersection points with each section, the coordinates are (x, y, z), the intersection points are rounded, and 100 grid check points are uniformly taken on the range of each section in the prior method; the invention respectively constructs three rectangular ranges on each tangent plane by taking the intersection point as the center, namely, the first to third range frame lines on the graph, the area of the rectangle is determined according to the influence range of the obstacle in the formula (1), and the maximum influence range of the single obstacle is easy to be knownSet in experiments->The inscribed rectangle side length of the range isIs circumscribed by a square with a side length of 20; constructing a rectangle by using the side length of the inscribed rectangle as a first range area, constructing a rectangle by 2 times of the side length of the circumscribed rectangle as a second range area, and constructing a rectangle by 4 times of the side length of the circumscribed rectangle as a third range area; 36, 25 grid points are selected from the first to third range frame lines as preliminary check points. The number of the points near the intersection point of the shortest path and the tangent plane is increased by the points in the first range, so that the probability that the path searched by the ant colony is closer to the shortest path is increased, and the path quality is greatly improved; meanwhile, the second range and the third range are sequentially increased and the points are respectively taken, so that the whole point taking range is overlapped with the whole tangent plane range as much as possible, the exploration capacity of the tangent plane space is ensured, and the situation that a feasible path cannot be searched because the selected points are too concentrated and blocked by obstacles is avoided; meanwhile, the repeated points and points outside the map range need to be removed; checking passable checkpoints according to map information, storing the passable checkpoints into a preparation checkpoint set allowances, and setting the range and the number of checkpoints according to the situation.
The existing ant colony algorithm is used for constructing a preliminary check point by uniformly selecting the whole section according to a certain step length; in order to enhance the purpose of selecting check points, the method selects around the intersection point of the straight line formed from the starting point to the end point and the tangent plane, and ensures the direction and the purpose of the ant colony algorithm path.
Step six, constructing an improved ant algorithm, and optimizing the track path of the mechanical arm;
step 61, initializing ant colony related parameters, including: the ant number m, the maximum iteration number iter_max, the pheromone factor alpha, the heuristic function factor beta, the pheromone volatilization factor rho and the local pheromone intensity Q.
Initializing a pheromone value tau between each check point and the check point of the next layer to be 1, and setting the coordinate of the current point to be P i (x i ,y i ,z i ) The coordinate of the next layer of check point is P j (x j ,y j ,z j ) Initializing a heuristic value eta between each check point and the next-layer check point according to a formula (5) ij The formula is:
wherein, (x) i ,y i ,z i ) For the coordinate value of the current checkpoint i, (x) j ,y j ,z j ) Is the coordinate value of the next layer check point j.
Because the mode of selecting the check point is changed, the method has stronger purpose, and when the check point of the section selected area of the new layer is selected, the path between the two adjacent layers is ensured to be as short as possible, so the calculation mode of the heuristic value is determined and modified by the original distance between the current point and the end point to be the distance between the current point and the check point of the next layer.
Step 62, ants search feasible paths, ants start from the starting point and select the next road point according to the roulette mode, P ij Is the probability of transitioning from point i to point j, calculated according to equation (6).
Wherein alpha is a pheromone factor, beta is a heuristic function factor, eta ik (t) heuristic value representing ant transfer from grid point i to next layer of check point k, τ ik (t) is the pheromone value transferred from i to the next layer of checkpoints k.
η ij (t) heuristic value representing ant transfer from grid point i to target point j, τ ij (t) is a pheromone value transferred from i to j, and allow (i+1) is a passable next-layer grid point set; ants search sequentially along the section until reaching the end point.
Step 63, checking the obtained path and updating the local pheromone to obtain the pheromone change value of the checked path; fitting the road points obtained by ants into the motion track of the mechanical arm, and calculating the motion track path f of the end effector L And the angle change of each joint f Q The method comprises the steps of carrying out a first treatment on the surface of the Collision detection is carried out on the path to obtain a collision target f CO And recording the path segment where the collision occurred; according to the checking result, updating the local pheromone of the path section on the path according to a formula (7), and according to whether the path section can pass or not, whether the path section is respectively updated after being explored in the previous ant search or not, wherein the formula is as follows:
wherein iter is the current iteration number, and the local pheromone strength Q is a constant; l (L) path (tk) represents the length of the current whole path; deltaτ i,j (t+1) is a new pheromone change value transferred from grid point i to grid point j; deltaτ i,j (t) is the old pheromone change value transferred from grid point i to grid point j.
The pheromone updating mode of the invention is that after each ant searches the completion path, the pheromone updating mode with volatilization function is carried out, so that the probability of the searched path being selected is reduced, and the occurrence of local optimum is prevented; the new pheromone updating mode adopts an off-line mode, namely, when the same iteration is performed, the probability that all ants select new points is not influenced by other ants; meanwhile, changing the updating mode of the pheromone according to different path conditions; taking negative one when the traffic is impossible, and setting the pheromone to be zero when the global pheromone is updated; when a new path is obtained, more pheromones are accumulated, and the number of the pheromones approaches to the old path along with the increase of the iteration times; when the old path is obtained again, accumulation is performed on the basis of the original pheromone.
Step 64, extracting the change value of each road section pheromone in the local pheromone updating, and carrying out global pheromone updating on all the path sections; after one iteration is finished, updating the pheromones of all path segments according to a formula (8), wherein the pheromone volatilization factor rho changes along with the iteration times, and the change mode is shown as a formula (9), and the iteration is finished.
τ i,j (iter+1)=(1-ρ)*τ i,j (iter)+△τ i,j (iter) (8)
In the method, in the process of the invention,representing a global volatility constraint coefficient; c is a compensation coefficient for keeping the volatilization coefficient within a fixed range; the item is the current iteration number, ρ (item) represents the pheromone volatilization factor at the item iteration time, ρ min Is the minimum value of the pheromone volatilization factors.
In the global pheromone updating mode of the original ant algorithm, the volatile factor rho is fixed, the coefficient after modification gradually decreases along with the increase of iteration times, the proportion of the volatile pheromones on the paths gradually decreases along with the progress of iteration, the probability of exploring a new path is improved in the early stage of algorithm iteration, and the convergence rate of the algorithm is accelerated in the later stage of algorithm iteration.
And evaluating the optimization problem and searching a global optimal path.
Has obtained theory ofShortest path L small After one iteration is finished, determining the optimal fitness value of the iteration according to the fitness value of m ant paths, and calculating the fitness value of each ant searched path according to a formula (2); finding out the global optimal path of the iteration according to the fitness value; determining whether the path has reached a theoretical shortest path or whether the number of iterations has reached a predetermined maximum number of iterations; this step is to confirm whether optimization needs to be continued, and if one of the two conditions is satisfied, the system will output the current optimal path; however, if none of the above conditions are met, the system jumps to step 62 and proceeds to the subsequent optimization iteration process; such an iterative process will continue until the theoretical shortest path is reached or the maximum number of iterations is reached, to ensure that the path solution is finally obtained as optimally as possible.
In order to verify the effectiveness and superiority of the ant colony algorithm (Ant Clony Algorithm, ACA) and the improved ant colony algorithm (ImprovedAnt Colony Algorithm, IACA) in the mechanical arm track planning, the simulation experiment is respectively carried out on the basis of the ant colony algorithm and the improved ant colony algorithm, and the results are analyzed.
Simulation environment setting: the simulation platform is MATLAB 2021b, the processor is Intel (R) Core (TM) i5-8300H CPU@2.30GHz, and the memory is 16GB.
As shown in fig. 4, the equivalent topography of the working space of the mechanical arm is set as a region with 100cm x 100cm, the coordinates of the starting point are (18,16,10), the coordinates of the ending point are (93,79,50), and the peak topography is the equivalent of obstacles, accumulated materials and the like; setting parameters of an ant colony algorithm: the ant number m=10, the maximum iteration number iter_max=100, the pheromone factor alpha=5, the heuristic function factor beta=1, the pheromone volatilization factor ρ=0.1 and the local pheromone intensity q=1.
FIG. 4 is a graph of two algorithmic optimal path comparisons, with squares as the starting points and stars as the ending points; the solid line is the path obtained by the IACA algorithm, and the dotted line is the path obtained by the ACA algorithm; observing the drawn path, the improved path is smoother and more close to a straight line, which shows that the improved algorithm considers the characteristics of the terrain more fully in path planning, so that the operation is smoother and the path length is obviously shorter
The line graph of the iteration times and the fitness value is shown in fig. 5, the trend of the curve is observed, and the improved algorithm IACA can search a shorter path in the initial stage, because an innovative point selection scheme is adopted, and then the curve rapidly descends and becomes stable; in addition, compared with the final fitness value of the two algorithms under the same iteration times, the improved algorithm has better performance on the fitness value, which means that the improved algorithm has more advantages in the aspect of problem solving.
The theoretical optimal fitness and the actual optimal fitness values of the simulation results are shown in table 1; the difference error between the theoretical optimal fitness and the actual optimal fitness value of the improved ant colony algorithm is relatively small, which indicates that the improved ant colony algorithm has a remarkable optimization effect on the problem of path planning of the mechanical arm, can effectively approach to an expected optimal solution, and fully considers the influence of topography and obstacles in path planning, so that the running path of the mechanical arm is more reasonable and safer.
TABLE 1 theoretical optimal fitness and actual optimal fitness of simulation results
With the above-described preferred embodiments according to the present invention as an illustration, the above-described descriptions can be used by persons skilled in the relevant art to make various changes and modifications without departing from the scope of the technical idea of the present invention. The technical scope of the present invention is not limited to the description, but must be determined according to the scope of claims.