Skip to content

寻路算法 - PathPlanning

函数简介

提供二值化地图自动寻路功能,白色为可通行区域,黑色为障碍物,在指定起点和终点之间寻找最优路径。当起点和终点在不可通信区域时会自动吸附到最近的可通行区域

接口名称

PathPlanning

DLL调用

c
long PathPlanning(long instance, long image, int startX, int startY, int endX, int endY, double potentialRadius, double searchRadius);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
image长整数型二值化图像句柄。
startX整数型起点X坐标。
startY整数型起点Y坐标。
endX整数型终点X坐标。
endY整数型终点Y坐标。
potentialRadius双精度浮点数势场半径。半径小:势场计算更"局部",每个点主要考虑附近几格的距离;半径大:势场计算更"全局",路径更平滑但计算量更大。
searchRadius双精度浮点数搜索半径,限制搜索范围。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long image = ola.LoadImage("maps/path_map.png");
if (image != 0) {
    auto path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    ola.FreeImage(image);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long image = ola.LoadImage("maps/path_map.png");
if (image != 0)
{
    var path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    ola.FreeImage(image);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
image = ola.LoadImage("maps/path_map.png")
if image != 0:
    path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0)
    ola.FreeImage(image)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long image = ola.LoadImage("maps/path_map.png");
if (image != 0) {
    var path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    ola.FreeImage(image);
}
cpp
var ola = com("OlaPlug.OlaSoft")
var image = ola.LoadImage("maps/path_map.png")
if(image) {
    ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    ola.FreeImage(image)
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
image = ola.LoadImage("maps/path_map.png")
If image <> 0 Then
    ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    ola.FreeImage(image)
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
image = ola.LoadImage ("maps/path_map.png")
.如果真 (image ≠ 0)
    ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    ola.FreeImage (image)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var image = ola.LoadImage("maps/path_map.png");
if(image){
    ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    ola.FreeImage(image);
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 image = ola.LoadImage("maps/path_map.png")
如果真 (image ≠ 0)
{
    ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    ola.FreeImage(image)
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long image = ola.LoadImage("maps/path_map.png");
if (image != 0) {
    ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    ola.FreeImage(image);
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long image = LoadImage(instance, "maps/path_map.png");
if (image != 0) {
    auto path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    FreeImage(instance, image);
}
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
long image = LoadImage(instance, "maps/path_map.png");
if (image != 0) {
    var path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0);
    FreeImage(instance, image);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
image = ola.LoadImage(instance, b"maps/path_map.png")
if image:
    path = ola.PathPlanning(image, 10, 10, 500, 400, 3.0, 50.0)
    ola.FreeImage(instance, image)

返回值

返回值说明
(返回值)返回路径规划结果字符串指针,格式为JSON:。
json
[
  {"x": 1, "y": 2},
  {"x": 2, "y": 1}
]
字段名类型说明
x整数x 字段值。
y整数y 字段值。

返回的字符串指针需要调用 FreeStringPtr 释放内存。

注意事项

项目说明
路径potentialRadius、searchRadius 为负数时只返回JPS寻路数据,不做路径优化。
输入的图像为二值化图像确保输入的图像为二值化图像,白色区域为可通行,黑色区域为障碍物。
起点和终点坐标必须在图像范围内起点和终点坐标必须在图像范围内。