修复地图yaml解析
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
stopDispatchRosInspectionTask,
|
||||
} from "@/api/rosCar";
|
||||
import { getToken } from "@/utils/auth";
|
||||
import { parseRosMapYaml } from "@/utils/rosMapYaml";
|
||||
import { BASE_URL } from "@/utils/request";
|
||||
import { getRecentAlertPhoto } from "../shared/alertPhotos";
|
||||
|
||||
@@ -376,23 +377,6 @@ function buildFileAccessUrl(fileUrl: string) {
|
||||
return `${BASE_URL}${fileUrl.startsWith("/") ? fileUrl : `/${fileUrl}`}`;
|
||||
}
|
||||
|
||||
// 解析 ROS 地图 YAML 中的分辨率和原点,供真实坐标映射使用
|
||||
function parseRosMapYaml(content: string): RosMapMeta {
|
||||
const resolution = Number(content.match(/^\s*resolution\s*:\s*([^\s#]+)\s*$/m)?.[1]);
|
||||
const originValue = content.match(/^\s*origin\s*:\s*\[([^\]]+)\]\s*$/m)?.[1];
|
||||
const origin = originValue
|
||||
?.split(",")
|
||||
.map((value) => Number(value.trim()))
|
||||
.slice(0, 3);
|
||||
|
||||
return {
|
||||
resolution: Number.isFinite(resolution) && resolution > 0 ? resolution : 0.05,
|
||||
origin: origin?.length === 3 && origin.every((value) => Number.isFinite(value))
|
||||
? origin as [number, number, number]
|
||||
: [0, 0, 0],
|
||||
};
|
||||
}
|
||||
|
||||
function readPgmToken(bytes: Uint8Array, cursor: { index: number }) {
|
||||
while (cursor.index < bytes.length) {
|
||||
const code = bytes[cursor.index];
|
||||
@@ -737,7 +721,11 @@ async function loadRobotMap(device: DeviceItem) {
|
||||
}
|
||||
|
||||
const styledMap = buildStyledPgmMap(await pgmResponse.arrayBuffer());
|
||||
const meta = parseRosMapYaml(await yamlResponse.text());
|
||||
const parsedMeta = parseRosMapYaml(await yamlResponse.text());
|
||||
const meta: RosMapMeta = {
|
||||
resolution: parsedMeta.resolution ?? 0.05,
|
||||
origin: parsedMeta.origin ?? [0, 0, 0],
|
||||
};
|
||||
|
||||
rosMap.value = {
|
||||
...meta,
|
||||
|
||||
Reference in New Issue
Block a user