neural cleanup

This commit is contained in:
kepler155c@gmail.com
2019-03-19 01:41:32 -04:00
parent b4c894b8a1
commit b1c709795f
5 changed files with 61 additions and 88 deletions

View File

@@ -4,27 +4,18 @@ local Project = require('neural.project')
local UI = require('ui')
local Util = require('util')
local peripheral = _G.peripheral
local turtle = _G.turtle
local device = _G.device
local function equip(side, rawName)
return turtle and turtle.equip(side, rawName) and peripheral.wrap(side)
end
local target = nil
local ni = peripheral.find('neuralInterface')
local sensor = ni or
peripheral.find('plethora:sensor') or
peripheral.find('manipulator') or
equip('left', 'plethora:module:3')
if not sensor or not sensor.sense then
local glasses = device['plethora:glasses']
local intro = device['plethora:introspection']
local sensor = device['plethora:sensor'] or
error('Plethora sensor must be equipped')
end
UI:configure('Entities', ...)
UI:configure('Sensor', ...)
local config = Config.load('Entities', {
local target
local config = Config.load('Sensor', {
ignore = { }
})
if not config.ignore then
@@ -127,7 +118,7 @@ function page:eventHandler(event)
elseif event.type == 'totals' then
config.totals = not config.totals
Config.update('Entities', config)
Config.update('Sensor', config)
elseif event.type == 'detail' or event.type == 'grid_select' then
local selected = self.grid:getSelected()
@@ -144,20 +135,22 @@ function page:eventHandler(event)
if selected then
config.ignore[selected.name] = true
end
Config.update('Entities', config)
Config.update('Sensor', config)
elseif event.type == 'project' or event.type == 'project-target' then
if event.type == 'project' then
target = nil
end
config.projecting = not config.projecting
if config.projecting then
Project:init(ni.canvas())
else
Project.canvas:clear()
if glasses then
config.projecting = not config.projecting
if config.projecting then
Project:init(glasses.canvas())
else
Project.canvas:clear()
end
end
Config.update('Entities', config)
Config.update('Sensor', config)
end
UI.Page.eventHandler(self, event)
@@ -167,8 +160,8 @@ Event.onInterval(.5, function()
local entities = sensor.sense()
Util.filterInplace(entities, function(e) return not config.ignore[e.name] end)
if config.projecting then
local meta = ni.getMetaOwner()
if config.projecting and glasses and intro then
local meta = intro.getMetaOwner()
Project.canvas:clear()
local t = entities
if target then
@@ -194,13 +187,13 @@ Event.onInterval(.5, function()
page:sync()
end)
if config.projecting then
Project:init(ni.canvas())
if config.projecting and glasses then
Project:init(glasses.canvas())
end
UI:setPage(page)
UI:pullEvents()
if config.projecting then
if config.projecting and glasses then
Project.canvas:clear()
end

16
neural/apis/kinetic.lua Normal file
View File

@@ -0,0 +1,16 @@
local Angle = require('neural.angle')
local Util = require('util')
local device = _G.device
local module = device['plethora:kinetic'] or error('Missing kinetic')
local Kinetic = Util.shallowCopy(module)
function Kinetic.lookAt(pt)
--local x = pt.x < 0 and pt.x + .5 or pt.x - .5
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
return Kinetic.look(yaw, pitch)
end
return Kinetic

View File

@@ -1,17 +1,19 @@
local ni = require('neural.interface')
local Point = require('point')
local Util = require('util')
local Array = require('array')
local kinetic = require('plethora.kinetic')
local Point = require('point')
local os = _G.os
local device = _G.device
local os = _G.os
local pos = { x = 0, y = 0, z = 0 }
local meta = ni.getMetaOwner()
local sensor = device['plethora:sensor'] or error('Missing sensor')
local intro = device['plethora:introspection'] or error('Missing introspection module')
local ID = intro.getMetaOwner()
local function findTargets()
local l = ni.sense()
Util.filterInplace(l, function(a)
return math.abs(a.motionY) > 0 and meta.id ~= a.id
local l = Array.filter(sensor.sense(), function(a)
return math.abs(a.motionY) > 0 and ID ~= a.id
end)
table.sort(l, function(e1, e2)
return Point.distance(e1, pos) < Point.distance(e2, pos)
@@ -26,24 +28,19 @@ local count = 0
while true do
local target = findTargets()
if target and (not last or Point.distance(last, target) > .2) then
-- last = target
if last then print(Point.distance(last, target)) end
last = target
--print(target.x, target.y, target.z, count)
ni.lookAt(target)
count = 0
os.sleep(0)
-- elseif count < 10 then
-- count = count + 1
-- os.sleep(.1)
-- end
last = target
kinetic.lookAt(target)
count = 0
os.sleep(0)
else
count = count + 1
if count > 50 or not target then
ni.lookAt({ x = math.random(-10, 10),
y = math.random(-10, 10),
z = math.random(-10, 10) })
os.sleep(3)
kinetic.lookAt({
x = math.random(-10, 10),
y = math.random(-10, 10),
z = math.random(-10, 10)
})
os.sleep(3)
else
os.sleep(.1)
end

View File

@@ -1,12 +1,10 @@
_G.requireInjector(_ENV)
local ni = require('neural.interface')
local Util = require('util')
local os = _G.os
while true do
local target = Util.find(ni.sense(), 'name', 'joebodo')
local target = Util.find(ni.sense(), 'name', '///////')
if target then
if math.abs(target.x) < 2 and
math.abs(target.z) < 2 then

View File

@@ -1,31 +0,0 @@
_G.requireInjector(_ENV)
local ni = require('neural.interface')
local uid = ni.getID and ni.getID() or error('Introspection module is required')
local os = _G.os
local args = { ... }
local function findEntity(name)
for _,v in pairs(ni.sense()) do
if v.id ~= uid and v.name == name then
return v
end
end
end
print('Targets:')
for _,v in pairs(ni.sense()) do
print(v.name)
end
local target = args[1] or error('specify target name')
repeat
local entity = findEntity(target)
if entity then
ni.shootAt(entity, 1)
end
os.sleep(.5)
until not entity