越疆机器人TCP通讯之12点标定脚本程序

-- Version: Lua 5.4.4
-- 此线程为主线程,可调用任何指令
--必须先示教P1点位置,运行到P5点后手动暂停将当前位置保存到P2
--P2作为角度旋转标定基准位
--本程序用于越疆Robot和海康Vision master 12点标定
     VelL(20)             -- 设置线性速度
     AccL(20)             -- 设置线性加速度
     SpeedFactor(20)      -- 设置全局速度

     MovL(P1)---初始化位置

     x=50---X赋值
     y=50---Y赋值
     r=15---角度赋值
---------字符串分割----------
     function string.split(str,delimiter)
     if str==nil or str=='' or delimiter==nil then
     return nil
     end
     local result = {}
     for match in (str..delimiter):gmatch("(.-)"..delimiter) do
     table.insert(result,match)
     end
     return result
     end

------------------通讯连接---------------------

     function Connect(isServer,ip,prot)--建立TCP通信
     ::Cab_PC::  --跳转标签
     err, socket = TCPCreate(isServer,ip,prot)-- isServer:表示客户端或服务器(false: 表示创建客户端; true: 表示创建服务)  i
     print("err=",err)
     Wait(100)
     if err ~= 0 then
     print("创建链接失败,重新创建链接...\r\n")
     Wait(100)
     goto Cab_PC  --创建服务器失败跳转到create_serverCab标签继续创建
     end
     err = TCPStart(socket,0)--socket:socket对象  0:如果为0,则一直等待连接。如果不为0,则超过设定 的时间后退出连接。
     if err ~= 0 then
     print("握手失败,重新发起...\r\n")
     TCPDestroy(socket)--关闭TCP功能
     Wait(100)
     goto Cab_PC
     end
     print("握手成功...\r\n")
     end

-----------------数据交互-----------------
     function ReceiveData()          --数据接受                      
     local
     local DataArrayS={}
     err,Recbuf=TCPRead(socket,0,"string")    
     if err==0 and Recbuf~="" then
     DataArrayS=string.split(Recbuf,",")
     else   
     Connect(false,"192.168.1.90",8604) 
     end
     return DataArrayS
end    
----------数据发送-----------
     function SendData(socket,Str)   
     if Str~="" then
     err=TCPWrite(socket, Str)
     print("err=",err)
     if err==0 then
     print("Send Data OK")
     else
     Connect(false,"192.168.1.90",8604)          --接受失败,再次调用重连机制
     print("Send Data NG")
     end
     end
     end

---------------------------main-----------------------------
---P1
     Connect(false,"192.168.1.90",8604)      --建立TCP通信
     print("hello world")
     MovL(P1,{user=0,tool=1})
     Wait(500)
     currentPose_1=GetPose(0,1)
     Wait(300)
     print("currentPose_1=",currentPose_1)
     Test1="A"..","..tonumber(currentPose_1.pose[1])..","..tonumber(currentPose_1.pose[2])..","..tonumber(currentPose_1.pose[6])
     SendData(socket,Test1)
     Wait(1000)

---P2
     RelMovLUser({0,y,0,0,0,0})
     Wait(500)
     currentPose_2=GetPose(0,1)
     Wait(300)
     print("currentPose_2=",currentPose_2)
     Test2="A"..","..tonumber(currentPose_2.pose[1])..","..tonumber(currentPose_2.pose[2])..","..tonumber(currentPose_2.pose[6])
     SendData(socket,Test2)
     Wait(1000) 

     ---P3
     RelMovLUser({0,y,0,0,0,0})
     Wait(500)
     currentPose_3=GetPose(0,1)
     Wait(300)
     print("currentPose_3=",currentPose_3)
     Test3="A"..","..tonumber(currentPose_3.pose[1])..","..tonumber(currentPose_3.pose[2])..","..tonumber(currentPose_3.pose[6])
     SendData(socket,Test3)
     Wait(1000)

-- Version: Lua 5.4.4
-- 此线程为主线程,可调用任何指令
--必须先示教P1点位置,运行到P5点后手动暂停将当前位置保存到P2
--P2作为角度旋转标定基准位
--本程序用于越疆Robot和海康Vision master 12点标定
     VelL(20)             -- 设置线性速度
     AccL(20)             -- 设置线性加速度
     SpeedFactor(20)      -- 设置全局速度

     MovL(P1)---初始化位置

     x=50---X赋值
     y=50---Y赋值
     r=15---角度赋值
---------字符串分割----------
     function string.split(str,delimiter)
     if str==nil or str=='' or delimiter==nil then
     return nil
     end
     local result = {}
     for match in (str..delimiter):gmatch("(.-)"..delimiter) do
     table.insert(result,match)
     end
     return result
     end

------------------通讯连接---------------------

     function Connect(isServer,ip,prot)--建立TCP通信
     ::Cab_PC::  --跳转标签
     err, socket = TCPCreate(isServer,ip,prot)-- isServer:表示客户端或服务器(false: 表示创建客户端; true: 表示创建服务)  i
     print("err=",err)
     Wait(100)
     if err ~= 0 then
     print("创建链接失败,重新创建链接...\r\n")
     Wait(100)
     goto Cab_PC  --创建服务器失败跳转到create_serverCab标签继续创建
     end
     err = TCPStart(socket,0)--socket:socket对象  0:如果为0,则一直等待连接。如果不为0,则超过设定 的时间后退出连接。
     if err ~= 0 then
     print("握手失败,重新发起...\r\n")
     TCPDestroy(socket)--关闭TCP功能
     Wait(100)
     goto Cab_PC
     end
     print("握手成功...\r\n")
     end

-----------------数据交互-----------------
     function ReceiveData()          --数据接受                      
     local
     local DataArrayS={}
     err,Recbuf=TCPRead(socket,0,"string")    
     if err==0 and Recbuf~="" then
     DataArrayS=string.split(Recbuf,",")
     else   
     Connect(false,"192.168.1.90",8604) 
     end
     return DataArrayS
end    
----------数据发送-----------
     function SendData(socket,Str)   
     if Str~="" then
     err=TCPWrite(socket, Str)
     print("err=",err)
     if err==0 then
     print("Send Data OK")
     else
     Connect(false,"192.168.1.90",8604)          --接受失败,再次调用重连机制
     print("Send Data NG")
     end
     end
     end

---------------------------main-----------------------------
---P1
     Connect(false,"192.168.1.90",8604)      --建立TCP通信
     print("hello world")
     MovL(P1,{user=0,tool=1})
     Wait(500)
     currentPose_1=GetPose(0,1)
     Wait(300)
     print("currentPose_1=",currentPose_1)
     Test1="A"..","..tonumber(currentPose_1.pose[1])..","..tonumber(currentPose_1.pose[2])..","..tonumber(currentPose_1.pose[6])
     SendData(socket,Test1)
     Wait(1000)

---P2
     RelMovLUser({0,y,0,0,0,0})
     Wait(500)
     currentPose_2=GetPose(0,1)
     Wait(300)
     print("currentPose_2=",currentPose_2)
     Test2="A"..","..tonumber(currentPose_2.pose[1])..","..tonumber(currentPose_2.pose[2])..","..tonumber(currentPose_2.pose[6])
     SendData(socket,Test2)
     Wait(1000) 

     ---P3
     RelMovLUser({0,y,0,0,0,0})
     Wait(500)
     currentPose_3=GetPose(0,1)
     Wait(300)
     print("currentPose_3=",currentPose_3)
     Test3="A"..","..tonumber(currentPose_3.pose[1])..","..tonumber(currentPose_3.pose[2])..","..tonumber(currentPose_3.pose[6])
     SendData(socket,Test3)
     Wait(1000)
 

Read more

前后端跨域处理全指南:Java后端+Vue前端完整解决方案

摘要:本文详细介绍跨域问题的产生原因、浏览器同源策略机制,以及基于Java后端和Vue前端技术栈的多种跨域处理方案。涵盖@CrossOrigin注解、全局CORS配置、过滤器、Spring Security集成、Vue代理配置、Nginx反向代理等多种方案,并提供完整可运行的代码示例,适用于初中级开发者学习参考。 一、跨域基础概念 1.1 什么是跨域? 跨域(Cross-Origin)是指浏览器出于安全考虑,限制从一个域(协议+域名+端口)加载的网页去请求另一个域的资源。当协议、域名或端口三者中有任意一项不同时,就会触发跨域限制。 示例: * http://localhost:3000 → http://localhost:8080(端口不同)❌ 跨域 * http://example.com → https://example.com(协议不同)❌ 跨域 * http://api.example.

【博客之星】GIS老矣尚能饭否?WebGIS项目实战经验与成果展示

【博客之星】GIS老矣尚能饭否?WebGIS项目实战经验与成果展示

目录 一、最前面的话 二、前言  1、关于“夜郎king” 3、GIS的“老骥伏枥” 4、WebGIS的“新程启航” 三、WebGIS技术简介 1、前、后技术简介 2、系统功能架构 四、WebGIS项目应用效果 1、应急灾害 2、交通运输 3、智慧文旅 4、其它项目 五、未来与展望 1、云计算+数据存储 2、GIS+AI融合 一、最前面的话         在这个快速迭代的数字时代,技术如同潮水般汹涌而来。每一次代码的敲击、每一行算法的优化,都是我们探索未知的足迹。技术的力量是背后清晰的思路与逻辑;技术的本质,从来不是冰冷的代码,而是温暖人心的智慧。

【红黑树进阶】手撕STL源码:从零封装RB-tree实现map和set

【红黑树进阶】手撕STL源码:从零封装RB-tree实现map和set

👇点击进入作者专栏: 《算法画解》 ✅ 《linux系统编程》✅ 《C++》 ✅ 文章目录 * 一. 源码及框架分析 * 1.1 STL源码中的设计思想 * 1.2 STL源码框架分析 * 二. 模拟实现map和set(实现复用红黑树的框架) * 2.1 红黑树节点的定义 * 2.2 红黑树的基本框架 * 2.3 解决Key的比较问题:KeyOfT仿函数 * 2.4 支持insert插入 * 2.5 map和set的insert封装 * 三. 迭代器的实现 * 3.1 迭代器结构设计 * 3.2 迭代器的++操作 * 3.3 迭代器的--操作 * 3.4 RBTree中的迭代器接口 * 四. map和set对迭代器的封装 * 4.