Firstly, this paper introduces the overall structure block diagram, elaborates on the graph search algorithm that is widely used in path planning, and analyzes its principle and the composition of the evaluation function in detail. Secondly, the distance calculation method in the heuristic function of the graph search algorithm is described. Aiming at the traditional Euclidean distance calculation method, an improved distance calculation method, which effectively reduces the number of search nodes of the algorithm, is proposed. Then, the path planning results of different search neighborhoods are compared and the appropriate search neighborhoods are selected. Finally, this paper introduces the robot safe motion planning method based on minimized hazard index and uses minimized Snap method with the safe corridor to generate trajectory. Experiments are carried out in ROS simulation environments and real scenes. The experimental results show that compared with traditional path planning algorithms, the proposed algorithm in this paper has more advantages in global path security and smoothness.
3.3. Construction of Grid Map Based on Risk Factor Grade
At present, grid map is widely used to represent environment information in robot path planning. Grid map is composed of a series of pixels, which correspond to a certain gray value within 0–255. The gray value of obstacle area is 0, and the gray value of blank grid is 255. Therefore, it is necessary to transform the environment information of robot into grid information. Blank grid is a space where robots can pass freely, while black grid represents the position of obstacles. Whether the obstacles can completely occupy the grid or not, the grid should be marked as an obstacle area. Robots cannot pass through the black grid, and robots need to plan a collision-free route from the space where the blank grid is located.
To ensure the distance between the planned path and obstacles, the cost map [
30] is introduced into the algorithm. The cost map in this paper is mainly composed of three layers, which are the obstacle layer, danger layer, and buffer layer. The specific cost map is shown in
Figure 4. When the raster map is loaded as a cost map, the cost map needs to be expanded according to the size of obstacles, but there are no obstacles in the expansion area, so it is necessary to use substitute value to express the cost of collision between robot and obstacles within the expansion distance of obstacles. Specifically, the obstacle layer is constructed according to the environmental information of the robot, which is represented in black in the figure and is the bottom layer of the whole cost map, in which the danger level of obstacles should be the highest, and the planned path should not collide with or cross it. The dangerous layer is indicated in dark blue on the map, which mainly expands the obstacles in the cost map. In practical application, the expansion distance can be set as the radius r of the tangent circle of the robot, and the path planned by the robot should intersect with the dangerous area as little as possible. The buffer layer is further expanded based on the dangerous area, which is represented by light blue in the figure. In practical applications, the r-2r area can be set as the buffer layer, and the robot will not collide with obstacles in this area. However, to prevent the occurrence of uncontrollable factors and leave enough safety margin, the robot should try to avoid entering the buffer layer when the space allows. The cost map is obtained by superimposing the obstacle layer, danger layer, and buffer layer.
To correctly express the generation value of different positions in the map, the distance between the current node and the obstacle is considered and converted into the gray value of the point. The conversion formula is given as Equation (
2).
where
d is the distance between the robot and the obstacle,
is the weight coefficient with the value of 0.5,
is the gray value of the point, and the gray value of the grid is converted into the substitute value of 0 ∼ 100 in the cost map. The substitute value cost calculation formula of the points is given in Equations (
3) and (
4).
where
q is the ratio of the gray values of the current grid, OG is the threshold of the occupied grid,
x is the image value of the grid, and FG is the threshold of the idle grid. When
q is greater than OG, it can be considered as an obstacle grid with a generation value of 100. When
q is less than FG, it can be considered as completely idle, with a generation value of 0. When
q is between FG and OG, conversion to a value between 0 and 100 is needed. In such cases (between FG and OG), the closer
q is to obstacles, the more dangerous it is, and as such, the higher its generation value should be. The schematic diagram of path planning in the cost map is shown in
Figure 5. For clear representation, only one layer of grid around obstacles is constructed as a dangerous layer, but no buffer layer is constructed. The algorithm needs to design a path from the starting point to the target point without passing through obstacles, and the planned path should avoid passing through the dangerous layer area as much as possible.
After determining the danger value of each point, if the free space of the environment is large because the map generation value outside the buffer layer is 0, the path planned by the robot is often close to the edge of the obstacle, and a large amount of free space is not used. If a function can be applied so that the planned path can keep a certain safe distance from obstacles, the designed danger index
can be determined as follows:
where
is the distance factor given the value 10 and
is the minimum Euclidean distance between the robot and the obstacle. It can be seen from Equation (
5) that when the distance between the path and the obstacle is very small, the danger index value is very large.
3.4. Improvement of Distance Calculation Method
In the path planning of mobile robots, a heuristic function is a function used to estimate the distance between the current node and the target state, which is used to guide the search of the path planning algorithm. This kind of search is called “Heuristic Search”, and its function is to help the algorithm find a high-quality path quickly and avoid invalid search directions as much as possible. The design of the heuristic function needs to consider two factors: accuracy and efficiency. Accuracy refers to whether the heuristic function can reflect the real distance between nodes, and efficiency refers to whether the computational cost of the heuristic function is low. Generally speaking, the more accurate the heuristic function is, the easier it is for the search algorithm to find the optimal path; the simpler the heuristic function, the more time and space the search algorithm saves.
The traditional A* search algorithm is mainly suitable for grid-based environments, and the heuristic function is related to the changing distance between the target point and the current position. The heuristic function is not affected by various obstacles in the robot’s forward path, which makes the algorithm more effective in identifying grids. In the heuristic function of the A* algorithm, the calculation method of distance has a great influence on the number of search nodes of the algorithm. The commonly used distance forms are Euclidean distance, Manhattan distance, and diagonal distance. The following is a brief description of the calculation methods of several distance formulas: the specific expressions of Euclidean distance, diagonal distance, and Manhattan distance between two points in a two-dimensional plane. Equation (
6) shows the Euclidean distance calculation method.
In Equation (
6),
a and
b represent the position information of the first and last two points, and their coordinates are
and
, respectively.
At present, Euclidean distance [
31] is the most widely used distance calculation method in path planning. To speed up the algorithm, this paper proposes a new Euclidean distance calculation method, which designs a guide function according to the connection between the starting point and the target point. This method makes the searched nodes as close to the guideline as possible, reduces the number of nodes in the search process, and guides the target point faster. The designed linear guide distance calculation function is given in Equation (
7).
In Equation (
7), the left term represents the degree of deviation between the current node and the line connecting the starting point and target point. The further the current node is away from the line, the greater the value of the equation.
a,
b, and
c are constant coefficients of the first-order function
formed by the line connecting the starting point and the target point. When the starting point and target point are in a straight line,
a and
b can be taken as 0, while
c cannot be taken as 0.
To verify whether the improved distance function can reduce the number of search nodes, simulation experiments are carried out. In a python 3.7 environment, numpy 1.24.2 is used to realize read and write data operations, and matplotlib 3.7.0 functions are also used as a map drawing tool. The path planning algorithm uses traditional Euclidean distance and the improved distance function proposed in this section for simulation and verification in an environment with obstacles. The starting point coordinates are (0, 0), target point coordinates are (32, 50), in
Figure 6, a dot represents the starting point, asterisks represent the target point, and “+” marks represent expanded nodes in the search process. Eight is used as the neighborhood search, starting points and target points remain unchanged in the two simulated searches, and the distribution of obstacles also remain unchanged. The results are shown in
Figure 6, and related data are shown in
Table 1.
By analyzing the experimental results, it can be found that the execution time of the algorithm is shortened by 30.7%, the number of turning points is reduced to 75%, and the number of search nodes is reduced by 23.3%. It can be seen that the new distance calculation method can approach the target point faster with fewer expanding directions, thus effectively reducing the number of search nodes and improving the running efficiency of the algorithm. To better verify the robustness of the distance calculation function, under the same obstacle distribution, different starting points and target points are selected for ten experiments, and the experimental results as shown in the bar chart in
Figure 7.
The abscissa in the graph represents the number of experiments, and the ordinate represents the number of search nodes of the A* algorithm. By observing the data in the graph, it can be seen that the number of search nodes obtained using the improved distance function is lower than that of Euclidean distance. The number of search nodes in ten experiments decreases from 15.4% to 30.8%, with an average of 23.5%. It can be found that the improved distance function has an obvious effect on reducing the search nodes of the A* algorithm.
3.5. Determination of Search Neighborhood
In the process of A* algorithm searching for the next node according to the current node, the number of nodes searched every time will determine the execution time of the algorithm and the length of the final path, so it is very important to choose the search neighborhood of the algorithm reasonably [
32]. As shown on the left in
Figure 8, it is a schematic diagram of the 4-neighborhood search, in which 1 is the position that can be reached by the next search, and 0 is that the current node cannot be searched. That is, in the next node expansion, only nodes in four directions can be searched and put into the open list. In this way, the path angle is usually an integer multiple of π/2, which does not conform to the turning characteristics of the robot. Conversely, the right side in
Figure 8 shows a schematic diagram of 8-neighborhood search that is more suitable for robots. In each node expansion, nodes in eight directions outside the node will enter the open list, so that the rotation angle of the path will be further reduced, and each turn angle is an integer multiple of π/4, which will be beneficial to the execution of the robot.
To further improve the minimum moving angle of the robot at each tracking stage, a more accurate angle can be obtained by expanding the unfolding area, which expands the nodes into two layers outside the node to achieve 24-neighborhood search, as shown in
Figure 9. With the decrease in the minimum rotation angle, the final planned path length will decrease; however, too large an unfolding range will lead to an increase in the number of nodes searched every time, increasing computational complexity and causing poor real-time performance of the algorithm. To better choose the search neighborhood and weigh the relationship between path length and search time, simulation software is used for analysis.
To better select a search neighborhood, the path planning simulation experiment is carried out in a python 3.7 environment. The simulation environment is a square grid map with a size of 70 m × 70 m. During the experiment, the starting point and target point are kept unchanged, the starting point coordinates are (0, 0), and the target point coordinates are (34, 50). The A* algorithm uses 4 neighborhoods, 8 neighborhoods, and 24 neighborhoods to plan the path, as shown in
Figure 10, where the green dot is the starting point, the + sign represents the target point, and the black area is an obstacle.The relevant experimental data are shown in
Table 2.
By analyzing the experimental results, we can find that the path length of the 4-neighborhood is 27.9% longer than the 8-neighborhood, and the 8-neighborhood is 40.1% longer than the 24-neighborhood. The turning point of the 4-neighborhood is longer than that of the 8-neighborhood, and the 8-neighborhood longer than 24-neighborhood, by 140% and 300%, respectively. The running time of the 4-neighborhood is 19.7% less than the 8-neighborhood, and the 8-neighborhood is less than 24-neighborhood by 44.5%. It can be concluded that with the increase in the number of neighbors, the path length and turning point decreases greatly, but the running speed of the algorithm is sacrificed. To better control the path length and the number of turning points while taking into account the running time of the algorithm, 8 neighbors should be selected as the search neighborhood.
3.6. CRI-A* Algorithm
After the research and analysis of the above two sections, it is determined to use the improved distance calculation method and 8-neighborhood path search, and at the same time, based on the traditional evaluation function, increase the cost map generation value and the danger index. Finally, the evaluation function of CRI-A* proposed in this paper is given as follows:
where
is the actual generation value from the starting point to the current node
m;
is the heuristic generation value of the current node
m to the end point;
is design danger index;
is the cost map value of a point on the grid map.
Algorithm 1 is a pseudocode showing the implementation steps of the CRI-A* algorithm. The input of the system is the starting point
and the target point
of the robot path planning, and the output is the waypoint
of the path planning. in steps 1 to 3, the starting point is passed into the Openlist and the evaluation function value is initialized; in steps 4 to 7, a judgement is made on whether the smallest evaluation value in the Openlist is a target point, and if so, other nodes are deleted from the Openlist. If it is, it means that the target point has been found and the program ends; steps 8 to 13 are to put the
S section with the minimum evaluation function value into Closelist, traverse the 8 adjacent nodes of the current node, and set their parent node to
. If the node is not in Openlist, the evaluation function value of this point is calculated and put into Openlist; steps 14 to 19 recalculate the evaluation function value of the node if the point is already in Openlist, and update it if the new value is lower. Finally, after searching for the target point, all nodes in the Closelist are outputted.
Algorithm 1 CRI-A* algorithm. |
Input: start point ; goal point ; |
Output: ; |
1: Openlist = |
2: Closelist = { } |
3: G() = 0; F() = H() |
4: while Openlist is not empty do |
5: ; |
6: if then Break |
7: else |
8: Closedlist.Add(S); |
9: for S nodes in each 8 neighborhood do |
10: if = then |
11: G() = G() + dis(, ); |
12: F(m) = G() + H() + L(m) + Cost(m); |
13: Insert Openlist(); |
14: else if = Openlist |
15: if G() > G() + dis(, ) then |
16: F(m) = G() + H() + L(m) + Cost(m) |
17: end if |
18: end if |
19: end for |
20: end if |
21: end while |
3.7. Trajectory Generation
After path searching, the obtained path is composed of a series of discrete waypoints, which are sparse and do not contain time information, so it is impossible for the robot to track and control directly. In order to reduce the energy loss and better control the smooth motion of the robot, it is necessary to transform the sparse waypoints into continuous and smooth curves. In order to solve the above problems, this paper proposes to use a high-order polynomial function for trajectory smoothing. By calculating the polynomial coefficients of each waypoint trajectory, the overall polynomial trajectory satisfies the constraints of the first and last states and the middle point, ensuring that the high-order derivatives of the left and right limits of the front and back segments of the middle point trajectory are the same. This makes the piecewise polynomial smooth and continuous, and also minimizes the energy function. In order to limit the derivative of jerk and meet the requirement of a semidefinite solution of the equation, it is necessary to construct a polynomial objective function of degree 7. Let the whole trajectory be divided into h segments; then, any trajectory can be expressed as Equation (
9).
where
is the coefficient of the polynomial and
t is the time of the current trajectory. For the whole trajectory, it can be regarded as a combination of
h segments of piecewise trajectories at a given time, which can be expressed as Equation (
10).
where
is the time at the end of the trajectory in the
h section. After obtaining the polynomial function of each trajectory, the velocity, acceleration, jerk, and jerk change rate of each trajectory are obtained.
To avoid collision between trajectory and obstacles, it is necessary to limit the shape of the global trajectory, and the trajectory expected to be planned must be in a safe corridor. If the passable safe area is added to the path smoothing problem as a constraint, the trajectory will naturally be in the safe corridor. To impose security constraints, Bezier curves are introduced, and given in Equation (
11):
where
is the
control points of a convex hull polygon, and
is a Berstein basis function, whose expression is defined as Equation (
12):
There is a transformation relationship between Bezier curve and polynomial curve, which can be described as Equation (
13):
By limiting the control points of the Bezier curve, the shape of the curve can be controlled. The schematic diagram of the Bezier curve is shown in
Figure 11, and the Bezier curve is limited in the area surrounded by the control points.
By deriving a 4-degree polynomial function, the expression of the change rate of jerk of any trajectory can be obtained as shown in Equation (
14):
By substituting Equation (
14) into Equation (
10), the minimized snap minimization objective function of the whole trajectory is constructed, which is the integral of the square of the rate of change of jerk in the corresponding time segment of each trajectory, and is given in Equation (
16).
In the formula, , all denote the coefficients of each order of the polynomial trajectory, i and l are the orders of the trajectory polynomial, and j denotes the respective trajectory serial numbers in different time periods ().
The snap minimization objective function of each trajectory is expressed in matrix form as Equation (
17):
where
is the coefficient matrix of the j-th trajectory polynomial;
is the information matrix of locus polynomial in paragraph
j.
Substituting formula (
17) into formula (
16), the snap minimization objective function of the whole trajectory is extended, as in Equation (
18):
Therefore, the problem of minimizing the objective function is modeled as a mathematical quadratic programming (QP) problem. The standard mathematical form of a quadratic programming problem can be expressed as in Equation (
19):
where
P is a symmetric matrix;
G and
A are n-dimensional real vectors; and
q,
h and
b are real numbers. A standard quadratic programming problem consists of objective function, equality constraint, and inequality constraint.
After constructing the objective function to be optimized, because each trajectory is represented by two searched waypoints as endpoints and polynomial functions, as shown in
Figure 12, the
trajectory is connected with the
trajectory at the
point. In order to ensure that the trajectories with different parameters at both ends have better curvature connectivity at this point and make the final generated trajectory continuous, it is necessary to add continuity constraints and smoothness constraints to the constructed quadratic programming problem.
The continuity constraint of trajectory can be described as the position, velocity, acceleration, and jerk of the end of the j-segment trajectory and the head of the j + 1-segment trajectory being equal, respectively, which can ensure the continuity of the whole trajectory after optimization. Therefore, the continuity equality constraint is constructed as Equation (
20):
where
k is the order of derivative
, denoting position, velocity, acceleration, and jerk of each segment respectively; and
represent the polynomial coefficients of the end of segment
j and the beginning of segment
, respectively.
The trajectory is relatively stable at the starting point, the ending point, and the path connection point of every two trajectories. Also, the velocity, acceleration, and jerk of the trajectories at both ends should meet a certain value. Therefore, the smoothness equality constraint of the trajectory can be constructed according to the constraint condition in Equation (
21):
where
c represents the
x and
y axes. To ensure the safety of the trajectory, a collision-free safe corridor is constructed according to the waypoint searched by the path planning algorithm, and the trajectory is generated in the corridor, so the trajectory must be safe and collision-free, as shown in the
Figure 13. The security constraints are imposed as Equation (
22):
where
is the maximum and minimum limit position of the safe corridor, and
is the control point of the Bezier curve of order
r and degree
i of the
j-th trajectory on the
axis.
The objective function based on minimizing snap is solved for the x-axis and y-axis, respectively, and the coefficients q of each trajectory satisfying the constraint conditions are obtained. The coefficients are then substituted into the state equations of each segment to solve the state variables in all directions of the whole trajectory, We apply the quadratic programming solver IPOPT library to perform online trajectory smoothing calculations. Finally, the trajectory to be optimized is obtained.