hexss 0.22.2__tar.gz → 0.22.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hexss-0.22.2/hexss.egg-info → hexss-0.22.4}/PKG-INFO +1 -1
- {hexss-0.22.2 → hexss-0.22.4}/hexss/__init__.py +1 -1
- {hexss-0.22.2 → hexss-0.22.4}/hexss/modbus/serial/app.py +2 -7
- {hexss-0.22.2 → hexss-0.22.4}/hexss/modbus/serial/robot.py +168 -49
- hexss-0.22.4/hexss/num/__init__.py +50 -0
- {hexss-0.22.2 → hexss-0.22.4/hexss.egg-info}/PKG-INFO +1 -1
- {hexss-0.22.2 → hexss-0.22.4}/hexss.egg-info/SOURCES.txt +1 -0
- {hexss-0.22.2 → hexss-0.22.4}/LICENSE +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/MANIFEST.in +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/README.md +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/__main__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/box.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/config.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/constants/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/constants/terminal_color.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/app.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/pretty_dataframe.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/robot.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/server.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/static/css/dashboard.css +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/static/css/global.css +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/static/css/light.css +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/static/css/primer-primitives.css +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/static/css/primer.css +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/static/handsontable.full.min.css +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/static/handsontable.full.min.js +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/static/header.css +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/static/jquery-3.6.0.min.js +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/static/styles.css +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/templates/head_import.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/templates/header.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/templates/index.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/templates/register.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/control_robot/templates/table_editor.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/detector/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/detector/object_detector.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/env.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/example/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/example/camera_server.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/example/detector.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/example/image.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/example/templates/index.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/example/threading1.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/example/threading2.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/example/threading_app.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/git/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/git/test.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/github/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/github/download.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/image/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/image/capture.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/image/classifier.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/image/detector.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/image/func.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/image/im.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/json/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/kill.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/latex.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/modbus/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/modbus/serial/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/modbus/serial/run.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/modbus/serial/templates/header.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/modbus/serial/templates/index.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/modbus/serial/templates/register.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/multiprocessing/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/multiprocessing/func.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/multiprocessing/multicore.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/network.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/numpy/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/pandas/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/pandas/dataframe_transformation.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/path.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/python/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/python/packages.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/raspberrypi/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/raspberrypi/gpio.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/serial/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/server/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/server/camera_server.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/server/file_manager_server.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/server/processes.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/server/static/jquery-3.6.0.min.js +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/server/static/script.js +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/server/static/styles.css +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/server/templates/camera.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/server/templates/file_manager.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/server/templates/process.html +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/string/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/threading/__init__.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss/threading/mutithread.py +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss.egg-info/dependency_links.txt +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss.egg-info/entry_points.txt +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/hexss.egg-info/top_level.txt +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/setup.cfg +0 -0
- {hexss-0.22.2 → hexss-0.22.4}/setup.py +0 -0
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
|
-
import time
|
|
3
2
|
import traceback
|
|
4
|
-
from datetime import datetime
|
|
5
3
|
from functools import wraps
|
|
6
|
-
|
|
7
|
-
import struct
|
|
4
|
+
|
|
8
5
|
import hexss
|
|
9
6
|
|
|
10
7
|
hexss.check_packages('pandas', 'Flask', auto_install=True)
|
|
@@ -115,7 +112,6 @@ def read_register_socket():
|
|
|
115
112
|
def generate():
|
|
116
113
|
last = None
|
|
117
114
|
while True:
|
|
118
|
-
print(f'read_register_socket {slave}')
|
|
119
115
|
robot.update_registers(slave, show_results=False)
|
|
120
116
|
json_data = robot.to_json(slave).replace('\n', '').replace(' ', '')
|
|
121
117
|
if json_data != last:
|
|
@@ -135,12 +131,11 @@ def current_position_socket():
|
|
|
135
131
|
def generate():
|
|
136
132
|
last_data = ''
|
|
137
133
|
while True:
|
|
138
|
-
print('current_position_socket')
|
|
139
134
|
out = {}
|
|
140
135
|
for slave_id in range(num_slaves):
|
|
141
136
|
slave = robot.slaves[slave_id]
|
|
142
137
|
out[slave_id] = {
|
|
143
|
-
'position': slave.
|
|
138
|
+
'position': slave.get_current_position(),
|
|
144
139
|
'emergency_status': slave.is_emergency(),
|
|
145
140
|
'servo_on': slave.is_servo_on(),
|
|
146
141
|
'pause_status': slave.is_paused()
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import math
|
|
2
3
|
import time
|
|
3
|
-
from pprint import pprint
|
|
4
4
|
from typing import List, Optional, Dict, Any
|
|
5
5
|
from hexss import check_packages
|
|
6
6
|
from hexss.numpy import split_int32_to_uint16, int16, int32
|
|
7
|
+
from hexss.num import unpack_16bit, pack_16bit
|
|
7
8
|
|
|
8
9
|
check_packages('pandas', 'pymodbus', 'Flask', 'pyserial', auto_install=True)
|
|
9
10
|
|
|
@@ -72,13 +73,6 @@ REGISTERS: Dict[int, Dict[str, Any]] = {
|
|
|
72
73
|
'signals': {}
|
|
73
74
|
},
|
|
74
75
|
|
|
75
|
-
0x0400: {
|
|
76
|
-
'symbol': 'CPOS', 'name': 'current_position', 'description': '',
|
|
77
|
-
},
|
|
78
|
-
0x0401: {
|
|
79
|
-
'symbol': 'CPOS', 'name': 'current_position', 'description': '',
|
|
80
|
-
},
|
|
81
|
-
|
|
82
76
|
# 4.3.2 Details of Modbus Registers (page 35/388)
|
|
83
77
|
0x0500: {
|
|
84
78
|
'name': 'Alarm detail code', 'symbol': 'ALA0', 'description': '0x0500 Alarm detail code | 0x0501 Alarm address',
|
|
@@ -167,6 +161,23 @@ REGISTERS: Dict[int, Dict[str, Any]] = {
|
|
|
167
161
|
0: {'symbol': 'PC1', 'name': 'Position command bit 1', 'description': '-'}
|
|
168
162
|
}
|
|
169
163
|
},
|
|
164
|
+
0x1000: {'name': 'Target position 0', 'symbol': 'PCMD0'},
|
|
165
|
+
0x1001: {'name': 'Target position 0', 'symbol': 'PCMD0'},
|
|
166
|
+
0x1002: {'name': 'Positioning band 0', 'symbol': 'INP0'},
|
|
167
|
+
0x1003: {'name': 'Positioning band 0', 'symbol': 'INP0'},
|
|
168
|
+
0x1004: {'name': 'Speed command 0', 'symbol': 'VCMD0'},
|
|
169
|
+
0x1005: {'name': 'Speed command 0', 'symbol': 'VCMD0'},
|
|
170
|
+
0x1006: {'name': 'Individual zone boundary + 0', 'symbol': 'ZNMP0'},
|
|
171
|
+
0x1007: {'name': 'Individual zone boundary + 0', 'symbol': 'ZNMP0'},
|
|
172
|
+
0x1008: {'name': 'Individual zone boundary - 0', 'symbol': 'ZNLP0'},
|
|
173
|
+
0x1009: {'name': 'Individual zone boundary - 0', 'symbol': 'ZNLP0'},
|
|
174
|
+
0x100A: {'name': 'Acceleration command 0', 'symbol': 'ACMD0'},
|
|
175
|
+
0x100B: {'name': 'Deceleration command 0', 'symbol': 'DCMD0'},
|
|
176
|
+
0x100C: {'name': 'Push-current limiting value 0', 'symbol': 'PPOW0'},
|
|
177
|
+
0x100D: {'name': 'Load current threshold 0', 'symbol': 'LPOW0'},
|
|
178
|
+
0x100E: {'name': 'Control flag specification 0', 'symbol': 'CTLF0'},
|
|
179
|
+
|
|
180
|
+
# 4000 to 83FF: Reserved for system
|
|
170
181
|
0x8400: {
|
|
171
182
|
'name': 'Total moving count', 'symbol': 'TLMC', 'description': '-', 'signals': {}
|
|
172
183
|
},
|
|
@@ -534,7 +545,7 @@ class Register:
|
|
|
534
545
|
self.name = name
|
|
535
546
|
self.signals = signals
|
|
536
547
|
self.description = description
|
|
537
|
-
self.values: List[int] = [0
|
|
548
|
+
self.values: List[int] = [0 for _ in address]
|
|
538
549
|
self.value: Optional[int] = None
|
|
539
550
|
self.client = client
|
|
540
551
|
self.id = slave_id
|
|
@@ -555,26 +566,29 @@ class Register:
|
|
|
555
566
|
}
|
|
556
567
|
|
|
557
568
|
def read(self) -> Optional[List[int]]:
|
|
558
|
-
|
|
559
|
-
resp = self.client.read_input_registers(self.address[0], count=l, slave=self.id + 1)
|
|
569
|
+
resp = self.client.read_input_registers(self.address[0], count=len(self.address), slave=self.id + 1)
|
|
560
570
|
if resp.isError():
|
|
561
571
|
print(f"Error reading SLAVE {self.id} @ 0x{self.address[0]:04X}: {resp}")
|
|
562
572
|
self.value = None
|
|
563
573
|
return None
|
|
564
574
|
self.values = resp.registers
|
|
565
|
-
value =
|
|
566
|
-
for v in self.values:
|
|
567
|
-
value = (value << 16) | v
|
|
568
|
-
self.value = int16(value) if l == 1 else int32(value)
|
|
575
|
+
self.value = unpack_16bit(self.values)
|
|
569
576
|
return self.values
|
|
570
577
|
|
|
571
578
|
def write(self, values: List[int]) -> bool:
|
|
572
579
|
resp = self.client.write_registers(self.address[0], values=values, slave=self.id + 1)
|
|
573
580
|
if resp.isError():
|
|
574
|
-
print(f"Error writing SLAVE {self.id} @ 0x{self.address[0]:}: {resp}")
|
|
581
|
+
print(f"Error writing SLAVE {self.id} @ 0x{self.address[0]:04X}: {resp}")
|
|
575
582
|
return False
|
|
576
583
|
return True
|
|
577
584
|
|
|
585
|
+
def read_value(self) -> Optional[int]:
|
|
586
|
+
self.read()
|
|
587
|
+
return self.value
|
|
588
|
+
|
|
589
|
+
def write_value(self, value: int) -> None:
|
|
590
|
+
self.write(pack_16bit(value, len(self.address)))
|
|
591
|
+
|
|
578
592
|
def get_bit(self, bit: int) -> bool:
|
|
579
593
|
self.read()
|
|
580
594
|
segment = 0 if bit >= 16 else -1
|
|
@@ -627,7 +641,6 @@ class Registers:
|
|
|
627
641
|
# 'PEND': [0x010C],
|
|
628
642
|
# 'CEND': [0x010D],
|
|
629
643
|
# 'CLBS': [0x010E],
|
|
630
|
-
'CPOS': [0x0400, 0x0401],
|
|
631
644
|
# 'ALA0': [0x0500, 0x0501],
|
|
632
645
|
# 'ALC0': [0x0503],
|
|
633
646
|
# 'ALT0': [0x0504, 0x0505],
|
|
@@ -638,7 +651,7 @@ class Registers:
|
|
|
638
651
|
# 'ODOM': [0x8402, 0x8403],
|
|
639
652
|
# 'TIMN': [0x8422],
|
|
640
653
|
# 'TFAN': [0x842E],
|
|
641
|
-
|
|
654
|
+
'PNOW': [0x9000, 0x9001],
|
|
642
655
|
# 'ALMC': [0x9002],
|
|
643
656
|
# 'DIPM': [0x9003],
|
|
644
657
|
# 'DOPM': [0x9004],
|
|
@@ -681,7 +694,6 @@ class Registers:
|
|
|
681
694
|
PEND: Register = None
|
|
682
695
|
CEND: Register = None
|
|
683
696
|
CLBS: Register = None
|
|
684
|
-
CPOS: Register = None
|
|
685
697
|
ALA0: Register = None
|
|
686
698
|
ALC0: Register = None
|
|
687
699
|
ALT0: Register = None
|
|
@@ -752,10 +764,21 @@ class Slave:
|
|
|
752
764
|
self.client = client
|
|
753
765
|
self.registers: Registers = _populate_registers(self.client, self.id)
|
|
754
766
|
|
|
767
|
+
def read_register(self, address: int, count: int = 1) -> Optional[int]:
|
|
768
|
+
resp = self.client.read_input_registers(address, count=count, slave=self.id + 1)
|
|
769
|
+
if resp.isError():
|
|
770
|
+
print(f"Error reading SLAVE {self.id} @ 0x{address:04X}: {resp}")
|
|
771
|
+
return None
|
|
772
|
+
values = resp.registers
|
|
773
|
+
value = 0
|
|
774
|
+
for v in values:
|
|
775
|
+
value = (value << 16) | v
|
|
776
|
+
value = int16(value) if count == 1 else int32(value)
|
|
777
|
+
return value
|
|
778
|
+
|
|
755
779
|
def update_registers(self) -> None:
|
|
756
780
|
for symbol in Registers.ADDRESS_DATA.keys():
|
|
757
|
-
|
|
758
|
-
reg.read()
|
|
781
|
+
getattr(self.registers, symbol).read()
|
|
759
782
|
|
|
760
783
|
def alarm_reset(self) -> None:
|
|
761
784
|
self.registers.DRG1.set_bit(Signal.ALRS)
|
|
@@ -773,19 +796,30 @@ class Slave:
|
|
|
773
796
|
else:
|
|
774
797
|
self.registers.DRG1.reset_bit(Signal.STP)
|
|
775
798
|
|
|
776
|
-
def home(self, alarm_reset=False,
|
|
777
|
-
if alarm_reset:
|
|
778
|
-
|
|
779
|
-
if
|
|
780
|
-
self.servo(True)
|
|
781
|
-
if unpause:
|
|
782
|
-
self.pause(False)
|
|
799
|
+
def home(self, alarm_reset: bool = False, servo_on: bool = False, unpause: bool = False) -> None:
|
|
800
|
+
if alarm_reset: self.alarm_reset()
|
|
801
|
+
if servo_on: self.servo(True)
|
|
802
|
+
if unpause: self.pause(False)
|
|
783
803
|
self.registers.DRG1.set_bit(Signal.HOME)
|
|
784
804
|
self.registers.DRG1.reset_bit(Signal.HOME)
|
|
785
805
|
|
|
786
|
-
def move(self, position: int):
|
|
806
|
+
def move(self, position: int) -> None:
|
|
787
807
|
self.registers.PCMD.write(split_int32_to_uint16(position).tolist())
|
|
788
808
|
|
|
809
|
+
def move_to(self, row: int) -> None:
|
|
810
|
+
self.registers.POSR2.write([row])
|
|
811
|
+
|
|
812
|
+
def wait(self, error_emergency: bool = True, error_servo_off: bool = True,
|
|
813
|
+
error_paused: bool = False) -> Optional[str]:
|
|
814
|
+
while self.is_moving():
|
|
815
|
+
if self.is_emergency() and error_emergency:
|
|
816
|
+
return 'emergency'
|
|
817
|
+
if self.is_servo_off() and error_servo_off:
|
|
818
|
+
return 'servo off'
|
|
819
|
+
if self.is_paused() and error_paused:
|
|
820
|
+
return 'paused'
|
|
821
|
+
return None
|
|
822
|
+
|
|
789
823
|
def is_moving(self) -> bool:
|
|
790
824
|
return bool(self.registers.DSSE.get_bit(Signal.MOVE))
|
|
791
825
|
|
|
@@ -795,12 +829,28 @@ class Slave:
|
|
|
795
829
|
def is_servo_on(self) -> bool:
|
|
796
830
|
return bool(self.registers.DSS1.get_bit(Signal.SON))
|
|
797
831
|
|
|
832
|
+
def is_servo_off(self) -> bool:
|
|
833
|
+
return not self.is_servo_on()
|
|
834
|
+
|
|
798
835
|
def is_emergency(self) -> bool:
|
|
799
|
-
return bool(self.registers.DSS1.get_bit(
|
|
836
|
+
return bool(self.registers.DSS1.get_bit(Signal.EMG))
|
|
837
|
+
|
|
838
|
+
def get_current_position(self) -> int:
|
|
839
|
+
self.registers.PNOW.read()
|
|
840
|
+
return self.registers.PNOW.value
|
|
841
|
+
|
|
842
|
+
def get_target_position(self, row: Optional[int] = None) -> int:
|
|
843
|
+
if row is None:
|
|
844
|
+
self.registers.PCMD.read()
|
|
845
|
+
return self.registers.PCMD.value
|
|
846
|
+
else:
|
|
847
|
+
return self.read_register(0x1000 + 16 * row, count=2)
|
|
848
|
+
|
|
849
|
+
def set_target_position(self, pos: int) -> None:
|
|
850
|
+
self.registers.PCMD.write_value(pos)
|
|
800
851
|
|
|
801
|
-
def
|
|
802
|
-
self.
|
|
803
|
-
return self.registers.CPOS.value
|
|
852
|
+
def get_distance(self, row: Optional[int] = None) -> int:
|
|
853
|
+
return abs(self.get_target_position(row) - self.get_current_position())
|
|
804
854
|
|
|
805
855
|
|
|
806
856
|
class Robot:
|
|
@@ -819,7 +869,7 @@ class Robot:
|
|
|
819
869
|
if self.client:
|
|
820
870
|
self.client.close()
|
|
821
871
|
|
|
822
|
-
def update_registers(self, slave_id=None, show_results: bool = False) -> None:
|
|
872
|
+
def update_registers(self, slave_id: Optional[int] = None, show_results: bool = False) -> None:
|
|
823
873
|
def showbin(n):
|
|
824
874
|
b = f"{n:032b}"
|
|
825
875
|
left = b[:16]
|
|
@@ -844,7 +894,8 @@ class Robot:
|
|
|
844
894
|
txt += f'\t{YELLOW}{showbin(reg.value)} {CYAN}{reg.symbol}: {reg.value}{END}\n'
|
|
845
895
|
print(txt)
|
|
846
896
|
|
|
847
|
-
def to_json(self, slave_id=None,
|
|
897
|
+
def to_json(self, slave_id: Optional[int] = None, just_vals: bool = False) -> str:
|
|
898
|
+
# get all self.slaves if slave_id is None
|
|
848
899
|
result: Dict[str, Any] = {}
|
|
849
900
|
for slave in self.slaves:
|
|
850
901
|
if slave_id and slave_id != slave.id:
|
|
@@ -872,9 +923,49 @@ class Robot:
|
|
|
872
923
|
'signals': signals_dict
|
|
873
924
|
}
|
|
874
925
|
reg_just_val_dict[symbol] = {'val': reg.value}
|
|
875
|
-
result[f"Slave {slave.id}"] = reg_just_val_dict if
|
|
926
|
+
result[f"Slave {slave.id}"] = reg_just_val_dict if just_vals else reg_dict
|
|
876
927
|
return json.dumps(result, indent=4)
|
|
877
928
|
|
|
929
|
+
def alarm_reset(self) -> None:
|
|
930
|
+
for slave in self.slaves:
|
|
931
|
+
slave.alarm_reset()
|
|
932
|
+
|
|
933
|
+
def servo(self, on: bool = True) -> None:
|
|
934
|
+
for slave in self.slaves:
|
|
935
|
+
slave.servo(on)
|
|
936
|
+
|
|
937
|
+
def pause(self, pause: bool = True) -> None:
|
|
938
|
+
for slave in self.slaves:
|
|
939
|
+
slave.pause(pause)
|
|
940
|
+
|
|
941
|
+
def home(self, alarm_reset: bool = False, on_servo: bool = False, unpause: bool = False) -> None:
|
|
942
|
+
for slave in self.slaves:
|
|
943
|
+
slave.home(alarm_reset, on_servo, unpause)
|
|
944
|
+
|
|
945
|
+
def move_to(self, row: int):
|
|
946
|
+
for slave in self.slaves:
|
|
947
|
+
slave.move_to(row)
|
|
948
|
+
|
|
949
|
+
def wait(self) -> Optional[str]:
|
|
950
|
+
while self.is_any_moving():
|
|
951
|
+
while self.is_any_paused():
|
|
952
|
+
pass
|
|
953
|
+
if self.is_any_servo_off():
|
|
954
|
+
return 'servo off'
|
|
955
|
+
return None
|
|
956
|
+
|
|
957
|
+
def get_distance(self, row: Optional[int] = None):
|
|
958
|
+
return math.sqrt(sum((slave.get_distance(row)) ** 2 for slave in self.slaves))
|
|
959
|
+
|
|
960
|
+
def is_any_moving(self) -> bool:
|
|
961
|
+
return any(slave.is_moving() for slave in self.slaves)
|
|
962
|
+
|
|
963
|
+
def is_any_paused(self) -> bool:
|
|
964
|
+
return any(slave.is_paused() for slave in self.slaves)
|
|
965
|
+
|
|
966
|
+
def is_any_servo_off(self) -> bool:
|
|
967
|
+
return not all(slave.is_servo_on() for slave in self.slaves)
|
|
968
|
+
|
|
878
969
|
|
|
879
970
|
if __name__ == "__main__":
|
|
880
971
|
comport = get_comport(
|
|
@@ -892,26 +983,54 @@ if __name__ == "__main__":
|
|
|
892
983
|
robot.update_registers()
|
|
893
984
|
print(robot.to_json())
|
|
894
985
|
|
|
895
|
-
#
|
|
986
|
+
# setup slave and reset alarm
|
|
896
987
|
slave = robot.slaves[0]
|
|
897
988
|
slave.alarm_reset()
|
|
898
|
-
slave.home()
|
|
899
989
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
990
|
+
# on servo
|
|
991
|
+
if robot.is_any_servo_off():
|
|
992
|
+
robot.alarm_reset()
|
|
993
|
+
robot.servo(True)
|
|
994
|
+
|
|
995
|
+
# unpause
|
|
996
|
+
if robot.is_any_paused():
|
|
997
|
+
robot.pause(False)
|
|
998
|
+
|
|
999
|
+
# test move and wait (1)
|
|
1000
|
+
slave.move_to(0)
|
|
1001
|
+
while slave.is_moving(): pass
|
|
1002
|
+
|
|
1003
|
+
# test move and wait (2)
|
|
1004
|
+
slave.home()
|
|
1005
|
+
status = slave.wait()
|
|
1006
|
+
if status: print(f'{RED}{status}{END}')
|
|
908
1007
|
|
|
1008
|
+
# test move and wait (3)
|
|
909
1009
|
stop = False
|
|
910
|
-
for pos in [
|
|
1010
|
+
for pos in [40000, 0, 40000, 0, 40000]:
|
|
1011
|
+
print(pos)
|
|
911
1012
|
slave.move(pos)
|
|
912
|
-
|
|
1013
|
+
|
|
1014
|
+
# status = slave.wait()
|
|
1015
|
+
# if status: print(f'{RED}{status}{END}')
|
|
1016
|
+
# if status == 'servo off':
|
|
1017
|
+
# stop = True
|
|
1018
|
+
# break
|
|
1019
|
+
# if stop:
|
|
1020
|
+
# break
|
|
1021
|
+
# time.sleep(0.5)
|
|
1022
|
+
|
|
1023
|
+
... or ...
|
|
1024
|
+
|
|
1025
|
+
while True:
|
|
1026
|
+
slave.registers.PNOW.read()
|
|
1027
|
+
slave.registers.PCMD.read()
|
|
1028
|
+
print(f'{slave.registers.PNOW.value} -> {slave.registers.PCMD.value} | dist={slave.get_distance()}')
|
|
1029
|
+
|
|
1030
|
+
if not slave.is_moving():
|
|
1031
|
+
break
|
|
913
1032
|
while slave.is_paused():
|
|
914
|
-
|
|
1033
|
+
pass
|
|
915
1034
|
if not slave.is_servo_on():
|
|
916
1035
|
stop = True
|
|
917
1036
|
break
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def unpack_16bit(words: List[int]) -> int:
|
|
5
|
+
'''
|
|
6
|
+
Example:
|
|
7
|
+
>>> unpack_16bit([65535])
|
|
8
|
+
-1
|
|
9
|
+
>>> unpack_16bit([200])
|
|
10
|
+
200
|
|
11
|
+
>>> unpack_16bit([65535, 200])
|
|
12
|
+
-65336
|
|
13
|
+
>>> unpack_16bit([0, 65535, 200])
|
|
14
|
+
4294901960
|
|
15
|
+
>>> unpack_16bit([1, 200])
|
|
16
|
+
65736
|
|
17
|
+
>>> unpack_16bit([2, 1, 200])
|
|
18
|
+
8590000328
|
|
19
|
+
>>> unpack_16bit([1, 2, 1, 200])
|
|
20
|
+
281483566710984
|
|
21
|
+
>>> unpack_16bit([0xFFFF] * 8)
|
|
22
|
+
-1
|
|
23
|
+
'''
|
|
24
|
+
val = sum((w & 0xFFFF) << (16 * i) for i, w in enumerate(reversed(words)))
|
|
25
|
+
bits = 16 * len(words)
|
|
26
|
+
return val - (1 << bits) if val >> (bits - 1) else val
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def pack_16bit(val: int, count: int = 1) -> List[int]:
|
|
30
|
+
'''
|
|
31
|
+
Example:
|
|
32
|
+
>>> pack_16bit(-1, 1)
|
|
33
|
+
[65535]
|
|
34
|
+
>>> pack_16bit(-1, 2)
|
|
35
|
+
[65535, 65535]
|
|
36
|
+
>>> pack_16bit(-1, 4)
|
|
37
|
+
[65535, 65535, 65535, 65535]
|
|
38
|
+
>>> pack_16bit(200)
|
|
39
|
+
[200]
|
|
40
|
+
>>> pack_16bit(200, 2)
|
|
41
|
+
[0, 200]
|
|
42
|
+
>>> pack_16bit(65736, 2)
|
|
43
|
+
[1, 200]
|
|
44
|
+
>>> pack_16bit(65736, 1)
|
|
45
|
+
[200]
|
|
46
|
+
>>> pack_16bit(-1, 8)
|
|
47
|
+
[65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535]
|
|
48
|
+
'''
|
|
49
|
+
val &= (1 << (16 * count)) - 1
|
|
50
|
+
return [(val >> (16 * i)) & 0xFFFF for i in reversed(range(count))]
|
|
@@ -70,6 +70,7 @@ hexss/modbus/serial/templates/register.html
|
|
|
70
70
|
hexss/multiprocessing/__init__.py
|
|
71
71
|
hexss/multiprocessing/func.py
|
|
72
72
|
hexss/multiprocessing/multicore.py
|
|
73
|
+
hexss/num/__init__.py
|
|
73
74
|
hexss/numpy/__init__.py
|
|
74
75
|
hexss/pandas/__init__.py
|
|
75
76
|
hexss/pandas/dataframe_transformation.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|