Skip to content

Commit

Permalink
normalize getPosition and status() with fullturn
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Briegel committed Mar 11, 2024
1 parent 6b0ba08 commit 62b43e5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions python/lvmtan/BasdaCluPythonServiceWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def init(self):
self.service = Basda.Basdard.interface(self.cfgNode.node("SERVICE").String)
dev_name = self.service.config().node("DEVICE").String

self.device = Basda.Basdard.device(dev_name)q
self.device = Basda.Basdard.device(dev_name)

self.simulate = self.device.config().node("LOAD").MapStringString["LIB"] == "BasdaMoccaNDeviceDummy"
I_LOG(f"simulate: {self.simulate}")
Expand All @@ -151,6 +151,7 @@ def init(self):
self.unit = self.cfgNode.node("UNIT").String


# needed for wheel device
if (
self.device.config().exist("CFG.FULLTURN")
and self.device.config().node("CFG.FULLTURN").hasLeaf()
Expand All @@ -160,7 +161,6 @@ def init(self):
else:
self.fullturn = 0


def abort(self):
self.terminated = True
Nice.U8_LOG("abort")
Expand Down
6 changes: 5 additions & 1 deletion python/lvmtan/BasdaMoccaBaseCluPythonServiceWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ async def stopMovement(self, command: Command):
command.fail(error=e)


def _getPosition(self):
return self.service.getPosition()


async def _status(self, reachable=True):
"""Status implementation"""
lock = asyncio.Lock()
Expand All @@ -113,7 +117,7 @@ async def _status(self, reachable=True):
"AtHome": self.service.isAtHome() if reachable else "Unknown",
"Moving": self.service.isMoving() if reachable else "Unknown",
switchStatusName: switchStatusValue,
"Position": self.service.getPosition() if reachable else nan,
"Position": self._getPosition() if reachable else nan,
"DeviceEncoder": {"Position": self.service.getDeviceEncoderPosition("STEPS") if reachable else nan,
"Unit": "STEPS"},
"Velocity": self.service.getVelocity() if reachable else nan,
Expand Down
5 changes: 1 addition & 4 deletions python/lvmtan/BasdaMoccaCluPythonServiceWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ async def getAbsoluteEncoderPosition(self, command: Command):
async def getPosition(self, command: Command):
"""Returns internal motorcontroller position counter"""
try:
if self.fullturn:
return command.finish(Position=((self.service.getPosition()%self.fullturn)+self.fullturn)%self.fullturn)
else:
return command.finish(Position=self.service.getPosition())
return command.finish(Position=self._getPosition())
except Exception as e:
command.fail(error=e)

Expand Down
5 changes: 5 additions & 0 deletions python/lvmtan/BasdaMoccaWheelCluPythonServiceWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def __init__(self, _svcName):
BasdaMoccaCluPythonServiceWorker.__init__(self, _svcName)
self.hasLimitSwitch=False

def _getPosition(self):
if self.fullturn:
return ((self.service.getPosition()%self.fullturn)+self.fullturn)%self.fullturn
else:
return self.service.getPosition()

@command_parser.command("scanAllReferenceSwitches")
@BasdaCluPythonServiceWorker.wrapper
Expand Down

0 comments on commit 62b43e5

Please sign in to comment.