Skip to content
Snippets Groups Projects
Commit e43b4d6f authored by Martin Teichmann's avatar Martin Teichmann Committed by Martin Teichmann
Browse files

encoder working for chem

not much more though, especially not the motor
parent f5a18444
No related merge requests found
from asyncio import gather, sleep, ensure_future
from struct import unpack
from .terminals import EL7041, EL5042, Skip
from .devices import Motor, Counter, AnalogInput
from .ebpfcat import FastEtherCat, FastSyncGroup, SyncGroup
con = Skip()
tm1 = EL7041()
te12 = EL5042()
tm2 = EL7041()
ec = FastEtherCat("enp0s31f6", [con, tm1, te12, tm2])
async def monitor(ec):
while True:
print("M", ec.ebpf.count, ec.ebpf.allcount, await tin.get_state())
await sleep(0.1)
async def main():
await ec.connect()
await ec.scan_bus()
#ensure_future(monitor(ec))
print("S", await te12.set_state(2))
for i in [1, 2, 3] + list(range(0x11, 0x19)):
print(f"P{i:x}", await te12.sdo_read(0x8018, i))
await te12.sdo_write(b"\0", 0x8018, 0x2) # statusbits
await te12.sdo_write(b"\0", 0x8018, 0x15) # multi
#await te12.sdo_write(b"\x1a", 0x8018, 0x16) # singleturn
await te12.sdo_write(b" ", 0x8018, 0x16) # singleturn
for i in [1, 2, 3]:
print(f"S{i:x}", await te12.sdo_read(0xB018, i))
print(f"Pos", await te12.sdo_read(0x6010, 0x11))
print(f"V", await te12.sdo_read(0xA018, 0x5))
print(f"M", await te12.sdo_read(0x10F3, 0x6))
print("State", await te12.get_state())
print("S", await tm2.set_state(2))
for i in [1,2,3,4,5,6,7,9,0x10,0x11]:
print(f"M{i:x}", unpack("H", await tm2.sdo_read(0x8010, i))[0])
m1 = Motor()
m1.velocity = tm2.velocity
m1.encoder = te12.channel2.position
m1.enable = tm2.enable
aie = AnalogInput(te12.channel2.status)
aim = AnalogInput(tm2.status)
fsg = SyncGroup(ec, [m1, aie, aim])
print("do start")
fsg.start()
print("did start")
for i in range(10):
print("P", m1.current_position, hex(aie.value), hex(aim.value))
await sleep(0.02)
for i in [1,2,3,4,5,6,7]:
print(f"I{i:x}", unpack("B", await tm2.sdo_read(0x6010, i))[0])
for i in [1,2,3]:
print(f"O{i:x}", unpack("B", await tm2.sdo_read(0x7010, i))[0])
print(f"V", unpack("H", await tm2.sdo_read(0x7010, 0x21))[0])
m1.velocity = 1000
m1.enable = True
await sleep(0.1)
for i in [1,2,3]:
print(f"O{i:x}", unpack("B", await tm2.sdo_read(0x7010, i))[0])
print(f"V", unpack("H", await tm2.sdo_read(0x7010, 0x21))[0])
m1.velocity = 0
#m1.enable = True
for i in range(10):
print("P", m1.current_position, hex(aie.value), hex(aim.value))
await sleep(0.02)
#m1.enable = False
m1.velocity = 0
if __name__ == "__main__":
from asyncio import get_event_loop
loop = get_event_loop()
loop.run_until_complete(main())
......@@ -174,6 +174,11 @@ class Motor(Device):
self.velocity = velocity
self.enable = self.set_enable
def update(self):
self.current_position = self.encoder
self.velocity = self.set_velocity
self.enable = self.set_enable
def program(self):
with self.ebpf.tmp:
self.ebpf.tmp = self.proportional * (self.target - self.encoder)
......
......@@ -691,21 +691,19 @@ class Terminal:
async def main():
from .bpf import lookup_elem
ec = EtherCat("eth0")
ec = EtherCat("enp0s31f6")
print(1)
await ec.connect()
#map_fd = await install_ebpf2()
print(2)
tin = Terminal()
tin.ec = ec
tout = Terminal()
tout.ec = ec
tdigi = Terminal()
tdigi.ec = ec
tin.ec = tout.ec = tdigi.ec = ec
print(3)
await gather(
tin.initialize(-4, 19),
tout.initialize(-2, 55),
tdigi.initialize(0, 22),
tin.initialize(-1, 5),
tout.initialize(-2, 6),
tdigi.initialize(-3, 22),
)
print("tin")
#await tin.to_operational()
......
......@@ -27,6 +27,7 @@ class Skip(EBPFTerminal):
pass
<<<<<<< HEAD
class EL1808(EBPFTerminal):
compatibility = {(2, 118501458)}
......@@ -53,6 +54,8 @@ class EL2808(EBPFTerminal):
ch8 = PacketDesc((1, 0), 7)
=======
>>>>>>> a6f8814 (encoder working for chem)
class EL4104(EBPFTerminal):
ch1_value = PacketDesc((1, 0), 'H')
ch2_value = PacketDesc((1, 2), 'H')
......@@ -85,7 +88,7 @@ class EK1814(EBPFTerminal):
class EL5042(EBPFTerminal):
compatibility = {(2, 330444882)}
class Channel(Struct):
position = PacketDesc((0, 2), "q")
position = PacketDesc((0, 2), "Q")
warning = PacketDesc((0, 0), 0)
error = PacketDesc((0, 0), 1)
status = PacketDesc((0, 0), "H")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment