--- Auto generated by 'aubo_scope' v0.31.1-beta.21 2025-07-08 10:26:22
--- DO NOT MODIFY IT!
local app = {}
local aubo = require('aubo')
local sched = sched or aubo.sched
local math = aubo.math or math
local realtime = aubo.realtime or realtime

local sleep = sched.sleep
local thread = sched.thread
local sync = sched.sync
local run = sched.run
local kill = sched.kill
local halt = sched.halt

app.PRIORITY = 1000 -- set the app priority, which determines app execution order
app.VERSION = "0.1"
app.VENDOR = "Aubo Robotics"

function p_chuansongdai_biaoding()
    local _ENV = sched.select_robot(1)
    local lang = "zh_CN"
    local __VAR = {}
    setCollisionStopType(1)
    setCollisionLevel(0)
    setFreedriveDamp({0.5,0.5,0.5,0.5,0.5,0.5})
    setHomePosition({0,-0.2617993877991494,1.74532925199433,0.4363323129985824,1.570796326794897,0}    )
    setDigitalInputActionDefault()
    setDigitalOutputRunstateDefault()
    setStandardDigitalInputAction(0, StandardInputAction.ConveyorTrack)
    setPayload(0, {0,0,0}, {0,0,0}, {0,0,0,0,0,0,0,0,0})
    setTcpOffset({0,0,0,0,0,0})
    setToolVoltageOutputDomain(0)
    setToolIoInput(0, true)
    setToolIoInput(1, true)
    setToolIoInput(2, true)
    setToolIoInput(3, true)
    bd_pose1 = {-0.37645392316501,-0.64162514926721,-0.080661283024476,-3.1409844005579,-0.0011074626197713,0.00060989913788359}
    bd_pose2 = {0.41879936801257,-0.59376571811613,-0.090415121297636,-3.14103280579,-0.0010776858452206,0.00057129597564275}
    bd_tick1 = -1908946638
    bd_tick2 = -1908978262
    direction = {0.99811920489568,0.060068179405514,-0.012242003157852,0.0,0.0,0.0}
    tickPerMeter = 39691.0
    bd_tick3 = -1880525676
    conveyor_start = 0.3
    conveyor_end = 0.9
    conveyor_limit = 1.1
    bd_tick4 = -1880531100
    sensor_offset = 0.3
    conveyor_comp = 0.032
    item_id_tracking = -1
    color_tracking = -1
    pid_tracking = -1
    item_id = 48
    color = 148
    pid = 1048
    line = {}
    t_line = -1
    t_id = 633
    t_name = "路点_4"
    update = false
    ticks = nil
    distance = nil
    Base= {0,0,0,0,0,0}
    Tool= {0,0,0,0,0,0}
    setLabel(1, "初始变量")
    u8defu70b9_1_p = {-0.3764545432404466,-0.6416244569794648,-0.08066155053796357,-3.140984609891754,-0.0011073822131843,0.0006101210783225175}    
    u8defu70b9_1_q = {-1.937839474170174,-1.15541968448981,1.230484168047304,0.8146048875911714,1.569528641021673,-0.3683025432451432}    
    u8defu70b9_0_p = {0.418799536781868,-0.5937658879016575,-0.09041431411307985,-3.141033605997409,-0.001078479288895748,0.0005712970625502109}    
    u8defu70b9_0_q = {-0.78907070215794,-1.144217258034441,1.297981576496881,0.8722285636917857,1.569933652450819,0.7804718743809513}    
    u8defu70b9_2_p = {0.8360315895180731,0.5504537588799971,0.1979152515831011,-3.136758615564259,0.004061832470805526,1.567737830359373}    
    u8defu70b9_2_q = {0.7752944782783846,-0.7437413878718163,1.376999707987243,0.5457475006201267,1.572338070301841,0.7766269658802707}    
    u8defu70b9_3_p = {0.8389839043414232,0.5519176379187338,0.4134748023887504,-3.136759310951569,0.004058352758295606,1.567733358660552}    
    u8defu70b9_3_q = {0.774057843381396,-0.6027137081674292,1.195095574777376,0.2228183877820669,1.57210181363484,0.7754753833834025}    
    
    setLabel(2, "机器人编程")
    setLabel(3, "biaoding.lua")
    --subscript context start
    local app = {}
    local aubo = require('aubo')
    local sched = sched or aubo.sched
    local math = aubo.math or math
    local realtime = aubo.realtime or realtime
    local sleep = sched.sleep
    local thread = sched.thread
    local sync = sched.sync
    local run = sched.run
    local kill = sched.kill
    local halt = sched.halt
    app.PRIORITY = 1000 -- set the app priority, which determines app execution order
    app.VERSION = "0.1"
    app.VENDOR = "Aubo Robotics"
    function distance_cal(pose1,pose2)
        local dx = pose2[1] - pose1[1]
        local dy = pose2[2] - pose1[2]
        local dz = pose2[3] - pose1[3]
        return math.sqrt(dx*dx + dy*dy + dz*dz)
    end
    function direction_cal(pose1,pose2,distance)
        local dx = pose2[1] - pose1[1]
        local dy = pose2[2] - pose1[2]
        local dz = pose2[3] - pose1[3]
        return {dx / distance,dy / distance,dz / distance,0.0,0.0,0.0}
    end
    function tickPerMeter_cal(ticks ,distance)
       local tickpermeter = ticks / distance
       tickpermeter = math.abs(tickpermeter)
       tickpermeter = math.floor(tickpermeter)
       return tickpermeter
    end
    function ws_cal(tick1, tick2, tickpermeter)
       local _ENV = sched.select_robot(1)
       local ws = unwindEncDeltaTickCount(tick1-tick2) / tickpermeter
       ws = math.abs(ws)
       return ws
    end
    --subscript context end
    
    
    
    
    
end

function app:start(api)
  --
  self.api = api
  print("start---")
  p_chuansongdai_biaoding()
end

function app:robot_error_handler(name, err)
  --
  print("An error hanppen to robot "..name)
end

-- return our app object
return app


