From 09cb60c8bcbb4f7371e8b692da9af00c5d4fc538 Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期二, 01 八月 2023 15:22:55 +0800 Subject: [PATCH] 小车行走路径锁定方案,走一步锁两步,走完即解锁 --- src/main/java/com/zy/common/utils/NyHttpUtils.java | 56 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/zy/common/utils/NyHttpUtils.java b/src/main/java/com/zy/common/utils/NyHttpUtils.java index e34f52e..4228f55 100644 --- a/src/main/java/com/zy/common/utils/NyHttpUtils.java +++ b/src/main/java/com/zy/common/utils/NyHttpUtils.java @@ -1,17 +1,19 @@ package com.zy.common.utils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.zy.common.model.NavigateNode; import com.zy.core.model.command.NyShuttleHttpCommand; +import com.zy.core.model.protocol.NyShuttleProtocol; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; +import java.util.*; /** * 鐗涚溂鍥涘悜绌挎杞TTP璇锋眰宸ュ叿绫� */ public class NyHttpUtils { + + private static final String requestUrl = "localhost:9090/skwcs"; //鑾峰彇HTTP璇锋眰鏍囧噯缁撴瀯浣� public static NyShuttleHttpCommand getHttpStandard(Integer shuttleNo) { @@ -52,8 +54,8 @@ HashMap<String, Object> body = new HashMap<>(); body.put("requestType", "move");//绉诲姩鍛戒护 body.put("taskId", wrkNo);//浠诲姟鍙� - body.put("start", start);//璧风偣 - body.put("target", target);//缁堢偣 + body.put("start", navigateNodeToNyPointNode(start));//璧风偣 + body.put("target", navigateNodeToNyPointNode(target));//缁堢偣 request.setBody(body); httpStandard.setRequest(request); @@ -68,8 +70,8 @@ HashMap<String, Object> body = new HashMap<>(); body.put("requestType", in ? "intoLift" : "outLift");//杩涘嚭鎻愬崌鏈� body.put("taskId", wrkNo);//浠诲姟鍙� - body.put("start", start);//璧风偣 - body.put("target", target);//缁堢偣 + body.put("start", navigateNodeToNyPointNode(start));//璧风偣 + body.put("target", navigateNodeToNyPointNode(target));//缁堢偣 request.setBody(body); httpStandard.setRequest(request); @@ -265,7 +267,43 @@ //鑾峰彇璇锋眰缂栧彿 public static Integer getRequestId() { Random random = new Random(); - return random.nextInt(); + return random.nextInt(9999999); + } + + //鍙戝嚭璇锋眰 + public static JSONObject requestCommand(NyShuttleHttpCommand httpCommand) { + try { + String response = new HttpHandler.Builder() + .setUri(requestUrl) + .setPath("/static/readStatus.json") + .setJson(JSON.toJSONString(httpCommand)) + .build() + .doGet(); + JSONObject jsonObject = JSON.parseObject(response); + JSONObject response2 = jsonObject.getJSONObject("response"); + JSONObject body = response2.getJSONObject("body"); + + if (body.get("responseType").equals("state")) {//璇诲彇鐘舵�侊紝涓嶉渶瑕佸垽鏂璼uccess + return body; + } + + if (body.get("result").equals("success")) { + return body; + } + } catch (Exception e) { +// e.printStackTrace(); + } + return null; + } + + //鍦板浘鑺傜偣杞崲鐗涚溂鑺傜偣 + public static NyShuttleProtocol.NyShuttlePointClass navigateNodeToNyPointNode(NavigateNode node) { + int[] NyPosition = NavigatePositionConvert.WCSXyzToNyXyz(node.getX(), node.getY(), node.getZ());//WCS绯荤粺鍧愭爣杞墰鐪煎潗鏍� + NyShuttleProtocol.NyShuttlePointClass point = new NyShuttleProtocol.NyShuttlePointClass(); + point.setX(NyPosition[0]); + point.setY(NyPosition[1]); + point.setZ(NyPosition[2]); + return point; } } -- Gitblit v1.9.1