Skip to content

Commit

Permalink
Merge pull request #13 from gelio5/12-encoder-integration
Browse files Browse the repository at this point in the history
encoder integration
  • Loading branch information
gelio5 authored Nov 14, 2023
2 parents bec42de + d881b30 commit 2fcd03e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='step_driver_g071_api',
version='0.8',
version='0.9',
packages=['step_driver_g071_api'],
url='https://github.com/gelio5/step_driver_G071_API.git',
license='MIT',
Expand Down
19 changes: 19 additions & 0 deletions step_driver_g071_api/step_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ class StepDriver:
For simultaneously objects use moving methods in thread with pause between threads <= 50 ms.
"""

# pylint: disable=too-many-instance-attributes

def __init__(self,
port: str,
modbus_address: int,
speed_to_search_home_pos: int = 5000,
max_pos: int = None):
self._commands: dict = {
'MOVE': 0x01,
'UPDATE': 0x02,
'INIT': 0x03,
'STOP': 0x04
}
Expand All @@ -47,6 +50,7 @@ def __init__(self,
self._address = modbus_address
self._speed_to_search_home_pos = speed_to_search_home_pos
self._max_position = max_pos
self._encoder: int = 0

def _get_status(self) -> bool:
return self._status
Expand Down Expand Up @@ -122,4 +126,19 @@ def _update_info(self) -> None:
self._status = bool(received_data[0])
self._current_pos = unpack('<I', pack('<HH', *received_data[1:]))[0]

def _update_encoder(self) -> None:
"""Update encoder value by register 13 READ, expected range [0 ... 4095]"""
with self.device:
self.device.write_registers(slave=self._address,
address=0,
values=[self._commands['UPDATE']])
with self.device:
received_data = self.device.read_holding_registers(slave=self._address,
count=1,
address=12).registers
self._encoder = unpack('<I', pack('<H', *received_data[0]))[0]

def _get_encoder(self) -> int:
return self._encoder
status = property(fget=_get_status)
encoder = property(fget=_get_encoder)

0 comments on commit 2fcd03e

Please sign in to comment.