You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

85 lines
2.6 KiB

const gstore = '500_500'
const agvId = '2'
const demoLocList = ['rack1/0/2/0', 'rack1/1/2/0', 'rack1/2/2/0', 'rack1/3/2/0']
while (true) {
const [carInv] = (await LCC.queryInv({ rack: agvId, bay: 0, level: 0, cell: 0 })).data
const [dd] = (await LCC.queryInv({ rack: gstore })).data
// demoLocList.reverse()
if (dd) {
// 地堆上有托盘, 找一个空货位放过去
LCC.log('地堆上有托盘')
const freeLoc = await findFreeLoc()
if (carInv) {
// 托盘在车上
LCC.log('托盘在车上')
LCC.log(`RCS.agvUnload('${agvId}', '${freeLoc}')`)
await RCS.agvUnload(agvId, freeLoc)
await RCS.waitTaskFinish(agvId)
await LCC.sleep(1000)
continue
}
LCC.log(`RCS.agvCarry('${agvId}', '${gstore}', '${freeLoc}')`)
await RCS.agvCarry(agvId, gstore, freeLoc)
await RCS.waitTaskFinish(agvId)
} else {
// 地上没有托盘位, 找个位置拖过去
if (carInv) {
// 托盘在车上
LCC.log('托盘在车上')
LCC.log(`RCS.agvUnload('${agvId}', '${gstore}')`)
await RCS.agvUnload(agvId, gstore)
await RCS.waitTaskFinish(agvId)
await LCC.sleep(1000)
continue
}
const invLoc = await findRackInvLoc()
if (!invLoc) {
LCC.log('货架没有托盘,无法执行')
} else {
LCC.log(`RCS.agvCarry('${agvId}', '${invLoc}', '${gstore}')`)
await RCS.agvCarry(agvId, invLoc, gstore)
await RCS.waitTaskFinish(agvId)
}
}
await LCC.sleep(1000)
}
async function findFreeLoc() {
for (const loc of shuffleArray(demoLocList)) {
const [rack, bay, level] = loc.split('/')
if (!rack) {
continue
}
const [emptyLoc] = (await LCC.queryInv({ rack, bay: parseInt(bay), level: parseInt(level) })).data
if (!emptyLoc) {
// 这是一个好位置
return loc
}
}
}
async function findRackInvLoc() {
for (const loc of shuffleArray(demoLocList)) {
const [rack, bay, level, cell] = loc.split('/')
const [palletLoc] = (await LCC.queryInv({ rack, bay: parseInt(bay), level: parseInt(level) })).data
if (palletLoc) {
return loc
}
}
}
// 打乱数组顺序的函数
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1)); // 随机选择一个位置 j
[array[i], array[j]] = [array[j], array[i]] // 交换元素
}
return array
}