index.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>华力机电SIMANC</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <!--标准mui.css-->
  10. <link rel="stylesheet" type="text/css" href="css/mui.min.css">
  11. <!--App自定义的css-->
  12. <link rel="stylesheet" type="text/css" href="css/app.css" />
  13. <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  14. <link rel="stylesheet" type="text/css" href="css/style.css" />
  15. </head>
  16. <body style="background: url(img/bg.png) no-repeat 0px -0px;width:99%;">
  17. <div id="title" style="height: 4%;text-align: center;padding-top: 10px;padding-bottom: 5px;background: url(img/title_bg.png) no-repeat 0 17px;background-size:100%;">
  18. <a style="color: #FFFFFF;font-size: 20px;">华力西曼克</a>
  19. </div>
  20. <div id="top" style="height: 30%;text-align: center;padding-top: 1px;background: url(img/top_bg.png) no-repeat 0 0px;background-size:100%;">
  21. <div class="mui-row">
  22. <div class="mui-col mui-col-xs-12">
  23. <div style="height: 10%;width: 50%;padding-top: 10px;float: left;">
  24. <img id="speed" src="img/speed-high.png" style="margin-left: -80px;width: 13%;">
  25. </div>
  26. <div style="height: 10%;width: 50%;padding-top: 10px;float: left;">
  27. <img id="battery" src="img/battery-100.png" style="margin-right: -80px;width: 23%;">
  28. </div>
  29. </div>
  30. <div class="mui-col mui-col-xs-12">
  31. <div id="tgts" style="width: 120px;height:90px;border-radius: 12px;border: 2px solid #298890;float: left;margin-left: 23px;">
  32. <div style="margin-left: -60px;margin-top: 15px;">
  33. <a style="color: #FFFFFF;font-size: 18px;">目标</a><br>
  34. </div>
  35. <div style="margin-left: -60px;margin-top: 10px;">
  36. <a style="color: #FFFFFF;font-size: 18px;">站点</a><br>
  37. </div>
  38. <div style="margin-left: 40px;margin-top: -40px;">
  39. <a id="tgtstation" style="color: #FFFFFF;font-size: 50px;"></a><br>
  40. </div>
  41. </div>
  42. <div id="jack" style="width: 120px;height:90px;border-radius: 12px;border: 2px solid #298890;float: right;margin-right: 20px;">
  43. <div style="margin-left: -60px;margin-top: 15px;">
  44. <a style="color: #FFFFFF;font-size: 18px;">顶升</a><br>
  45. </div>
  46. <div style="margin-left: -60px;margin-top: 10px;">
  47. <a style="color: #FFFFFF;font-size: 18px;">状态</a><br>
  48. </div>
  49. <div style="margin-left: 60px;margin-top: -55px;">
  50. <img id="liftstatus" src="img/liftstatus.png" width="60%">
  51. </div>
  52. </div>
  53. </div>
  54. <br>
  55. <br>
  56. <div style="width: 100%;height: 50px;margin-top: 100px;margin-left: 20px;">
  57. <div id="stop" style="width: 28%;height: 40px;line-height:40px;float: left;margin-left: 5px;background: url(img/btn4_bg.png);color: #FFFFFF;text-align: center;">停止</div>
  58. <div id="run" style="width: 28%;height: 40px;line-height:40px;float: left;margin-left: 5px;background: url(img/btn4_bg.png);color: #FFFFFF;text-align: center;">运行</div>
  59. <div id="warning" style="width: 28%;height: 40px;line-height:40px;float: left;margin-left: 5px;background: url(img/btn4_bg.png);color: #FFFFFF;text-align: center;">注意</div>
  60. </div>
  61. <div id="info" style="width: 87%;height: 30px;margin-left: 25px;color:#ccc;font-size:4px;line-height: 30px;background-color: #0b6d78;border-radius: 3px;text-align: left;padding-left: 5px;"></div>
  62. <div class="mui-content-padded" style="background: url(img/btlist5_bg.png) no-repeat 10px 0;margin-top: 25px;width: 100%;height: auto;">
  63. <div class="mui-row">
  64. <div class="mui-col mui-col-xs-12" id="btlist" style="padding-top:10px;min-height:285px;overflow-y:auto;max-height:285px"></div>
  65. <div class="mui-col mui-col-xs-12" style="text-align: center;padding-bottom: 13px;">
  66. <div class="mui-col mui-col-xs-3" id="gomoving">
  67. <button type="button" class="mui-btn mui-btn-royal mui-btn-block operation" id="moving" style="border:1px solid #4a5a6a;">移动</button>
  68. </div>
  69. <div class="mui-col mui-col-xs-3" id="gostart">
  70. <button type="button" class="mui-btn mui-btn-royal mui-btn-block operation" id="start" style="border:1px solid #4a5a6a;">搬运</button>
  71. </div>
  72. <div class="mui-col mui-col-xs-3">
  73. <button type="button" class="mui-btn mui-btn-royal mui-btn-block operation" id="cancel" style="border:1px solid #4a5a6a;">取消</button>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. <div style="height: 15px;width: 101%;background: url(img/bottom_bg.png) no-repeat -25px 0;"></div>
  79. </div>
  80. </div>
  81. </body>
  82. <script src="js/jquery.min.js"></script>
  83. <script src="js/mui.min.js"></script>
  84. <script src="js/msg.js"></script>
  85. <script src="js/lodash.js"></script>
  86. <script src="js/backbone.js"></script>
  87. <script src="js/rappid.min.js"></script>
  88. <script src="js/models/joint.shapes.smcr.js"></script>
  89. <script src="js/map.js"></script>
  90. <script src="js/models/joint.shapes.app.js"></script>
  91. <script type="text/javascript">
  92. var $btlist = $('#btlist');
  93. $(function() {
  94. //获取保存的ip、agvid、mapid等,如果没有数据,则设置为默认
  95. if (localStorage.getItem("ip") == "" || localStorage.getItem("ip") == null) {
  96. ip = "192.168.1.92:8888";
  97. url = "http://192.168.1.92:8888"
  98. } else {
  99. ip = localStorage.getItem("ip") + ":8888";
  100. url = "http://" + localStorage.getItem("ip") + ":8888";
  101. }
  102. if (localStorage.getItem("agvid") == "" || localStorage.getItem("agvid") == null) {
  103. agvid = 1;
  104. } else {
  105. agvid = parseInt(localStorage.getItem("agvid"))
  106. }
  107. if (localStorage.getItem("mapid") == "" || localStorage.getItem("mapid") == null) {
  108. mapid = "2019081410472902";
  109. } else {
  110. mapid = localStorage.getItem("mapid")
  111. }
  112. //获取按钮
  113. createList();
  114. //获取状态
  115. startLog();
  116. setInterval(function() {
  117. if (ws.readyState === 3) {
  118. startLog();
  119. }
  120. }, 1000);
  121. //设置操作按钮
  122. $("#gostart").addClass("mui-hidden");
  123. $("#moving").attr("disabled", true);
  124. $("#start").attr("disabled", true);
  125. //设置页面可以左滑右滑跳转页面
  126. var windowHeight = $(window).height(),
  127. $body = $("body");
  128. $("body").on("touchstart", function(e) {
  129. e.preventDefault();
  130. startX = e.originalEvent.changedTouches[0].pageX,
  131. startY = e.originalEvent.changedTouches[0].pageY;
  132. });
  133. $("body").on("touchmove", function(e) {
  134. e.preventDefault();
  135. moveEndX = e.originalEvent.changedTouches[0].pageX,
  136. moveEndY = e.originalEvent.changedTouches[0].pageY,
  137. X = moveEndX - startX,
  138. Y = moveEndY - startY;
  139. if (Math.abs(X) > Math.abs(Y) && X > 0) {
  140. window.location.href = "internet.html"; //right
  141. } else if (Math.abs(X) > Math.abs(Y) && X < 0) {
  142. window.location.href = "remote.html"; //left
  143. } else if (Math.abs(Y) > Math.abs(X) && Y > 0) {
  144. return //bottom
  145. } else if (Math.abs(Y) > Math.abs(X) && Y < 0) {
  146. return //top
  147. } else {
  148. return
  149. }
  150. });
  151. })
  152. //按钮点击事件
  153. function onSelectStation(evt) {
  154. var $this = $(this);
  155. if ($("div[id='btlist']").is(':active')) {
  156. $this.removeClass('active');
  157. } else {
  158. $this.addClass('active');
  159. }
  160. if ($("div[id='btlist']").find(".active").length == 1) {
  161. $("#moving").attr("disabled", false);
  162. $this.addClass('up');
  163. $("#start").removeAttr("disabled");
  164. $("#cancel").removeAttr("disabled");
  165. } else if ($("div[id='btlist']").find(".active").length == 2) {
  166. $("#gomoving").addClass("mui-hidden");
  167. $("#gostart").removeClass("mui-hidden");
  168. $this.addClass('down');
  169. $('#start').attr("disabled", false);
  170. $("#handling").removeAttr("disabled");
  171. }
  172. if ($("div[id='btlist']").find(".active").length >= 2) {
  173. $("button[name='stbtn']").css("pointer-events", "none")
  174. } else {
  175. $("button[name='stbtn']").css("pointer-events", "auto")
  176. }
  177. };
  178. //取消按钮操作
  179. function Reset(evt) {
  180. if ($("div[id='btlist']").find(".active")) {
  181. $("#gostart").addClass("mui-hidden");
  182. $("#gomoving").removeClass("mui-hidden");
  183. $("button[name='stbtn']").removeClass('up');
  184. $("button[name='stbtn']").removeClass('down');
  185. $("button[name='stbtn']").removeClass('active');
  186. $("button[name='stbtn']").css("pointer-events", "auto");
  187. $('#start').attr("disabled", true);
  188. $('#cancel').attr("disabled", true);
  189. $('#moving').attr("disabled", true);
  190. }
  191. }
  192. //移动按钮
  193. $("#moving").click(function() {
  194. let to;
  195. $("div[id='btlist']").find(".up").each(function(evt){
  196. to = parseInt(($(this).context).id);
  197. });
  198. SendCmd(AgvId, msgTypeToStation, {"Stn":to}, function(d) {
  199. console.log("AddTransTask", d);
  200. Reset()
  201. })
  202. });
  203. //搬运按钮
  204. $("#start").click(function() {
  205. var bt_value = [];
  206. $("div[id='btlist']").find(".up").each(function(evt) {
  207. bt_value.push($(this).val());
  208. });
  209. $("div[id='btlist']").find(".down").each(function(evt) {
  210. bt_value.push($(this).val());
  211. });
  212. AddTransTask(AgvId, bt_value[0], bt_value[1], function(d) {
  213. //console.log("AddTransTask", d);
  214. Reset()
  215. })
  216. });
  217. function AddTransTask(agvId, from, to, callback){
  218. $.post(url+"/task", {
  219. id:agvId,
  220. from: from,
  221. to: to
  222. }, callback);
  223. };
  224. function SendCmd(agvId, cmd, opt, func) {
  225. let param = {"t":cmd};
  226. opt = _.extend(param, opt);
  227. //console.log("param", opt);
  228. $.post(url+"/agv/SendString/" + agvId,
  229. JSON.stringify(opt),
  230. func
  231. );
  232. }
  233. //取消按钮
  234. $("#cancel").on("click", Reset);
  235. //填充按钮列表
  236. function createList() {
  237. $.get(url + "/map/getStations/" + mapid, function(data) {
  238. trs = "";
  239. for (i in data) {
  240. if (data[i].Name != "") {
  241. trs += '<div class="mui-col mui-col-xs-3" drag-id="' + data[i].Id + '">' +
  242. '<button type="button" class="mui-btn mui-btn-royal mui-btn-block" name="stbtn" id="' + data[i].Id +
  243. '" value="' + data[i].Id + '">' +
  244. data[i].Name + '</button></div>'
  245. }
  246. }
  247. $btlist.append(trs);
  248. //注册按钮点击事件
  249. $("button[name]").on("touchstart", onSelectStation);
  250. });
  251. }
  252. //新建ws连接,获取agv的状态
  253. let ws;
  254. function startLog() {
  255. ws = new WebSocket("ws://" + ip + "/ws/msg/" + agvid);
  256. ws.onmessage = function(e) {
  257. let result;
  258. let msg = JSON.parse(e.data);
  259. switch (msg.type) {
  260. case msgTypeStatus:
  261. // 每秒一次状态
  262. let stMap = JSON.parse(msg.data);
  263. //根据状态设置图标等
  264. showStatusValue(stMap);
  265. //当前站点按钮文字闪烁
  266. if (agvid == msg.id) {
  267. let stMap = JSON.parse(msg.data);
  268. $("#" + stMap.Station + "").toggleClass("text-success");
  269. }
  270. break;
  271. //读取设置状态,可以获得电池伏数
  272. case msgTypeGetCfg:
  273. //console.log(msg.type, msg.data);
  274. break;
  275. default:
  276. console.log(msg.type, msg.data);
  277. }
  278. };
  279. }
  280. //根据获取到的agv状态,设置速度、电量、站点、顶升、提示信息、运行按钮等的颜色和文字显示
  281. function showStatusValue(status) {
  282. for (let k in status) {
  283. let v = status[k];
  284. //速度显示
  285. if (k == "Speed") {
  286. if (v >= "30") { //SpeedHigh
  287. document.getElementById("speed").src = "img/speed-high.png";
  288. }
  289. if (v >= "20") { //SpeedMid
  290. document.getElementById("speed").src = "img/speed-medium.png";
  291. }
  292. if (v <= "10") { //SpeedLow
  293. document.getElementById("speed").src = "img/speed-low.png";
  294. }
  295. }
  296. //电量显示
  297. if (k == "BatteryVolt") {
  298. if (v >= "52") { //BatteryVoltFull
  299. document.getElementById("battery").src = "img/battery-100.png";
  300. }
  301. if ("52" < v >= "50") { //BatteryVoltHigh
  302. document.getElementById("battery").src = "img/battery-80.png";
  303. }
  304. if ("50" < v >= "48") { //BatteryVoltMid
  305. document.getElementById("battery").src = "img/battery-60.png";
  306. }
  307. if ("48" < v >= "47") { //BatteryVoltLow
  308. document.getElementById("battery").src = "img/battery-40.png";
  309. }
  310. if ("47" < v >= "45") { //BatteryVoltWarn
  311. document.getElementById("battery").src = "img/battery-20.png";
  312. }
  313. if (v <= "45") { //BatteryVoltStop
  314. document.getElementById("battery").src = "img/battery-0.png";
  315. }
  316. }
  317. //目标站点
  318. if (k == "TgtStation") {
  319. if (v == "65535") {
  320. $("#tgtstation").text("0");
  321. } else {
  322. $("#tgtstation").text(v);
  323. }
  324. }
  325. //顶升状态
  326. if (k == "liftstatus") {
  327. if (v == "1" || v == "3" || v == "5" || v == "7") {
  328. document.getElementById("liftstatus").src = "img/liftstatus-up.png";
  329. } else if (v == "0") {
  330. document.getElementById("liftstatus").src = "img/liftstatus.png";
  331. } else {
  332. document.getElementById("liftstatus").src = "img/liftstatus-down.png";
  333. }
  334. }
  335. //停止运行注意按钮及信息提示框
  336. if (k == "Status") {
  337. if (v == "1") {
  338. $("#info").text("未设置状态");
  339. }
  340. if (v == "2") {
  341. document.getElementById("run").style.backgroundImage = "url('img/btn2_bg.png')";
  342. }
  343. if (v == "3" || v == "4" || v == "9") {
  344. if (v == "3") {
  345. $("#info").text("停止状态");
  346. }
  347. if (v == "4") {
  348. $("#info").text("急停按钮急停状态");
  349. }
  350. if (v == "9") {
  351. $("#info").text("手动控制状态");
  352. }
  353. document.getElementById("stop").style.backgroundImage = "url('img/btn3_bg.png')";
  354. }
  355. if (v == "6") {
  356. $("#info").text("驱动器错误");
  357. }
  358. if (v == "7") {
  359. $("#info").text("导航错误");
  360. }
  361. if (v == "8") {
  362. $("#info").text("任务错误");
  363. }
  364. if (v == "11" || v == "22") {
  365. if (v == "11") {
  366. $("#info").text("遇到障碍物停止 或者 冲突区域");
  367. }
  368. if (v == "22") {
  369. $("#info").text("车辆遇到障碍物靠近");
  370. }
  371. document.getElementById("warning").style.backgroundImage = "url('img/btn1_bg.png')";
  372. }
  373. if (v == "12") {
  374. $("#info").text("防撞条紧急停止");
  375. }
  376. if (v == "15") {
  377. $("#info").text("电压低");
  378. }
  379. if (v == "21") {
  380. $("#info").text("车辆低电压运行");
  381. }
  382. if (v == "31") {
  383. $("#info").text("正方向磁导航脱线");
  384. }
  385. if (v == "32") {
  386. $("#info").text("反方向磁导航脱线");
  387. }
  388. if (v == "33") {
  389. $("#info").text("正方向磁导航脱线");
  390. }
  391. if (v == "34") {
  392. $("#info").text("反方向磁导航脱线");
  393. }
  394. if (v == "71" || v == "72" || v == "73") {
  395. $("#info").text("取货物时举升不为空");
  396. }
  397. }
  398. }
  399. }
  400. </script>
  401. </html>