joong925-sdk-python 0.1.0__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.
- joong925_sdk_python-0.1.0/LICENSE +21 -0
- joong925_sdk_python-0.1.0/PKG-INFO +28 -0
- joong925_sdk_python-0.1.0/README.md +4 -0
- joong925_sdk_python-0.1.0/joong925_sdk_python.egg-info/PKG-INFO +28 -0
- joong925_sdk_python-0.1.0/joong925_sdk_python.egg-info/SOURCES.txt +14 -0
- joong925_sdk_python-0.1.0/joong925_sdk_python.egg-info/dependency_links.txt +1 -0
- joong925_sdk_python-0.1.0/joong925_sdk_python.egg-info/requires.txt +2 -0
- joong925_sdk_python-0.1.0/joong925_sdk_python.egg-info/top_level.txt +1 -0
- joong925_sdk_python-0.1.0/pyproject.toml +3 -0
- joong925_sdk_python-0.1.0/setup.cfg +4 -0
- joong925_sdk_python-0.1.0/setup.py +22 -0
- joong925_sdk_python-0.1.0/tesollo_sdk_python/__init__.py +6 -0
- joong925_sdk_python-0.1.0/tesollo_sdk_python/constants.py +65 -0
- joong925_sdk_python-0.1.0/tesollo_sdk_python/controller.py +86 -0
- joong925_sdk_python-0.1.0/tesollo_sdk_python/delto.py +122 -0
- joong925_sdk_python-0.1.0/tesollo_sdk_python/visualize.py +56 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tesollo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: joong925-sdk-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Gripper
|
|
5
|
+
Author: cjo
|
|
6
|
+
Author-email: cjo@tesollo.com
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: numpy
|
|
14
|
+
Requires-Dist: opencv-python
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: author-email
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: description
|
|
19
|
+
Dynamic: description-content-type
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: requires-python
|
|
23
|
+
Dynamic: summary
|
|
24
|
+
|
|
25
|
+
# delto-sdk-python
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install delto-sdk-python
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: joong925-sdk-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Gripper
|
|
5
|
+
Author: cjo
|
|
6
|
+
Author-email: cjo@tesollo.com
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: numpy
|
|
14
|
+
Requires-Dist: opencv-python
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: author-email
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: description
|
|
19
|
+
Dynamic: description-content-type
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: requires-python
|
|
23
|
+
Dynamic: summary
|
|
24
|
+
|
|
25
|
+
# delto-sdk-python
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install delto-sdk-python
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
joong925_sdk_python.egg-info/PKG-INFO
|
|
6
|
+
joong925_sdk_python.egg-info/SOURCES.txt
|
|
7
|
+
joong925_sdk_python.egg-info/dependency_links.txt
|
|
8
|
+
joong925_sdk_python.egg-info/requires.txt
|
|
9
|
+
joong925_sdk_python.egg-info/top_level.txt
|
|
10
|
+
tesollo_sdk_python/__init__.py
|
|
11
|
+
tesollo_sdk_python/constants.py
|
|
12
|
+
tesollo_sdk_python/controller.py
|
|
13
|
+
tesollo_sdk_python/delto.py
|
|
14
|
+
tesollo_sdk_python/visualize.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tesollo_sdk_python
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="joong925-sdk-python",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
author="cjo",
|
|
7
|
+
author_email="cjo@tesollo.com",
|
|
8
|
+
description="Python SDK for Gripper",
|
|
9
|
+
long_description=open("README.md", encoding="utf-8").read(),
|
|
10
|
+
long_description_content_type="text/markdown",
|
|
11
|
+
packages=find_packages(),
|
|
12
|
+
install_requires=[
|
|
13
|
+
"numpy",
|
|
14
|
+
"opencv-python"
|
|
15
|
+
],
|
|
16
|
+
classifiers=[
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
],
|
|
21
|
+
python_requires='>=3.11',
|
|
22
|
+
)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# DG_RESULT
|
|
2
|
+
DG_RESULT_NONE = 0
|
|
3
|
+
DG_RESULT_ERROR = 1
|
|
4
|
+
|
|
5
|
+
# DG_MODEL
|
|
6
|
+
DG_MODEL_NONE = 0x0000
|
|
7
|
+
DG_MODEL_DG_5F_L = 0x5F12
|
|
8
|
+
DG_MODEL_DG_5F_R = 0x5F22
|
|
9
|
+
|
|
10
|
+
# BLEND_MOTION_STATUS
|
|
11
|
+
BLEND_MOTION_STATUS_STOP = 0
|
|
12
|
+
BLEND_MOTION_STATUS_RUN = 1
|
|
13
|
+
BLEND_MOTION_STATUS_COMPLETE = 2
|
|
14
|
+
|
|
15
|
+
# COMMUNICATION_MODE
|
|
16
|
+
COMMUNICATION_MODE_ETHERNET = 0
|
|
17
|
+
COMMUNICATION_MODE_RS485 = 1
|
|
18
|
+
|
|
19
|
+
# CONTROL_MODE
|
|
20
|
+
CONTROL_MODE_OPERATOR = 0
|
|
21
|
+
CONTROL_MODE_DEVELOPER = 1
|
|
22
|
+
|
|
23
|
+
# GAIN_MODE
|
|
24
|
+
GAIN_MODE_PD = 0
|
|
25
|
+
GAIN_MODE_PID = 1
|
|
26
|
+
|
|
27
|
+
# DEVELOPER_MODE_COMMAND
|
|
28
|
+
DEVELOPER_MODE_COMMAND_GET_DATA = 0x01
|
|
29
|
+
DEVELOPER_MODE_COMMAND_SET_RECEIVED_DATA = 0x02
|
|
30
|
+
DEVELOPER_MODE_COMMAND_SET_DUTY = 0x05
|
|
31
|
+
DEVELOPER_MODE_COMMAND_SET_GPIO = 0x06
|
|
32
|
+
DEVELOPER_MODE_COMMAND_SET_IP_ADDRESS = 0x07
|
|
33
|
+
DEVELOPER_MODE_COMMAND_GET_ID_AND_VERSION = 0x08
|
|
34
|
+
DEVELOPER_MODE_COMMAND_GET_JOINT_ID = 0x09
|
|
35
|
+
DEVELOPER_MODE_COMMAND_SET_BOOT_MODE = 0x0A
|
|
36
|
+
DEVELOPER_MODE_COMMAND_SET_FT_OFFSET_ZERO = 0x0B
|
|
37
|
+
|
|
38
|
+
# DEVELOPER_MODE_RECEIVED_DATA_TYPE
|
|
39
|
+
DEVELOPER_MODE_RECEIVED_DATA_TYPE_JOINT = 0x01
|
|
40
|
+
DEVELOPER_MODE_RECEIVED_DATA_TYPE_CURRENT = 0x02
|
|
41
|
+
DEVELOPER_MODE_RECEIVED_DATA_TYPE_TEMPERATURE = 0x03
|
|
42
|
+
DEVELOPER_MODE_RECEIVED_DATA_TYPE_VELOCITY = 0x04
|
|
43
|
+
DEVELOPER_MODE_RECEIVED_DATA_TYPE_FINGER_FT_SENSOR = 0x05
|
|
44
|
+
DEVELOPER_MODE_RECEIVED_DATA_TYPE_GPIO = 0x06
|
|
45
|
+
DEVELOPER_MODE_RECEIVED_DATA_TYPE_FINGER_TACTILE_SENSOR = 0x05
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# [5.2.1 개발자 모드 명령어]
|
|
49
|
+
CMD_GET_DATA = 0x01
|
|
50
|
+
CMD_SET_DUTY = 0x05
|
|
51
|
+
CMD_SET_GPIO = 0x06
|
|
52
|
+
CMD_SET_IP_PORT = 0x07
|
|
53
|
+
CMD_GET_ID_VERSION = 0x08
|
|
54
|
+
CMD_GET_COMM_ERROR = 0x09
|
|
55
|
+
CMD_SET_BOOT_MODE = 0x0A
|
|
56
|
+
CMD_SET_FT_OFFSET = 0x0B
|
|
57
|
+
|
|
58
|
+
# [5.2.2 수신 데이터 종류 및 크기]
|
|
59
|
+
TYPE_POSITION = 0x01 # 2 Byte, 0.1 Degree
|
|
60
|
+
TYPE_CURRENT = 0x02 # 2 Byte, 1 mA
|
|
61
|
+
TYPE_TEMPERATURE = 0x03 # 2 Byte, 0.1 °C
|
|
62
|
+
TYPE_VELOCITY = 0x04 # 1 Byte, 1 RPM
|
|
63
|
+
TYPE_FT_SENSOR = 0x05 # 12 Byte, 0.1 N / 0.1 Nm
|
|
64
|
+
TYPE_GPIO = 0x06 # 4 Byte
|
|
65
|
+
TYPE_TACTILE_SENSOR = 0x05 # 15 Byte
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import socket
|
|
2
|
+
import struct
|
|
3
|
+
import time
|
|
4
|
+
from .constants import *
|
|
5
|
+
|
|
6
|
+
class PDControllerCfg:
|
|
7
|
+
def __init__(self, kp, kd, output_limit):
|
|
8
|
+
self.kp = kp
|
|
9
|
+
self.kd = kd
|
|
10
|
+
self.output_limit = output_limit
|
|
11
|
+
self.prev_error = {}
|
|
12
|
+
|
|
13
|
+
def update(self, current_positions, target_positions, dt, duty_limits=None):
|
|
14
|
+
if dt <= 0.0: dt = 1e-5
|
|
15
|
+
if duty_limits is None: duty_limits = {}
|
|
16
|
+
|
|
17
|
+
duties = {}
|
|
18
|
+
for joint_id, target_pos in target_positions.items():
|
|
19
|
+
if joint_id not in current_positions:
|
|
20
|
+
continue
|
|
21
|
+
|
|
22
|
+
current_pos = current_positions[joint_id]
|
|
23
|
+
error = target_pos - current_pos
|
|
24
|
+
|
|
25
|
+
if joint_id not in self.prev_error:
|
|
26
|
+
self.prev_error[joint_id] = 0.0
|
|
27
|
+
|
|
28
|
+
p_term = self.kp * error
|
|
29
|
+
d_error = (error - self.prev_error[joint_id]) / dt
|
|
30
|
+
d_term = self.kd * d_error
|
|
31
|
+
|
|
32
|
+
output = p_term + d_term
|
|
33
|
+
|
|
34
|
+
joint_duty_limit = duty_limits.get(joint_id, self.output_limit)
|
|
35
|
+
|
|
36
|
+
if output > joint_duty_limit:
|
|
37
|
+
output = joint_duty_limit
|
|
38
|
+
elif output < -joint_duty_limit:
|
|
39
|
+
output = -joint_duty_limit
|
|
40
|
+
|
|
41
|
+
duties[joint_id] = output
|
|
42
|
+
self.prev_error[joint_id] = error
|
|
43
|
+
|
|
44
|
+
return duties
|
|
45
|
+
|
|
46
|
+
class PDController:
|
|
47
|
+
def __init__(self, kp=20.0, kd=0.5, output_limit=450):
|
|
48
|
+
self.pd_controller = PDControllerCfg(kp, kd, output_limit)
|
|
49
|
+
|
|
50
|
+
self.final_targets = {i: 0.0 for i in range(1, 21)}
|
|
51
|
+
self.current_setpoints = {i: 0.0 for i in range(1, 21)}
|
|
52
|
+
self.desired_speeds = {i: 450 for i in range(1, 21)}
|
|
53
|
+
self.is_initialized = False
|
|
54
|
+
|
|
55
|
+
def set_positions(self, targets, speeds=None):
|
|
56
|
+
for jid, pos in targets.items():
|
|
57
|
+
if 1 <= jid <= 20:
|
|
58
|
+
self.final_targets[jid] = pos
|
|
59
|
+
|
|
60
|
+
if speeds is not None:
|
|
61
|
+
if isinstance(speeds, dict):
|
|
62
|
+
for jid, speed in speeds.items():
|
|
63
|
+
if 1 <= jid <= 20: self.desired_speeds[jid] = speed
|
|
64
|
+
else:
|
|
65
|
+
for jid in targets.keys():
|
|
66
|
+
self.desired_speeds[jid] = float(speeds)
|
|
67
|
+
|
|
68
|
+
def update(self, current_positions, dt):
|
|
69
|
+
if not self.is_initialized and current_positions:
|
|
70
|
+
for jid, pos in current_positions.items():
|
|
71
|
+
self.current_setpoints[jid] = pos
|
|
72
|
+
self.is_initialized = True
|
|
73
|
+
|
|
74
|
+
for jid in range(1, 21):
|
|
75
|
+
goal = self.final_targets[jid]
|
|
76
|
+
curr_set = self.current_setpoints[jid]
|
|
77
|
+
speed = self.desired_speeds[jid]
|
|
78
|
+
|
|
79
|
+
max_step = speed * dt
|
|
80
|
+
|
|
81
|
+
if curr_set < goal:
|
|
82
|
+
self.current_setpoints[jid] = min(curr_set + max_step, goal)
|
|
83
|
+
elif curr_set > goal:
|
|
84
|
+
self.current_setpoints[jid] = max(curr_set - max_step, goal)
|
|
85
|
+
|
|
86
|
+
return self.pd_controller.update(current_positions, self.current_setpoints, dt)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import socket
|
|
2
|
+
import struct
|
|
3
|
+
import time
|
|
4
|
+
from .constants import *
|
|
5
|
+
|
|
6
|
+
class DeltoController:
|
|
7
|
+
def __init__(self, ip="192.168.1.119", port=502):
|
|
8
|
+
self.ip = ip
|
|
9
|
+
self.port = port
|
|
10
|
+
self.client = None
|
|
11
|
+
self.fingers = 5
|
|
12
|
+
|
|
13
|
+
def connect(self):
|
|
14
|
+
try:
|
|
15
|
+
self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
16
|
+
self.client.settimeout(2.0)
|
|
17
|
+
self.client.connect((self.ip, self.port))
|
|
18
|
+
print(f"Connection success: {self.ip}")
|
|
19
|
+
return True
|
|
20
|
+
except Exception as e:
|
|
21
|
+
print(f"Connection failed: {e}")
|
|
22
|
+
return False
|
|
23
|
+
|
|
24
|
+
def disconnect(self):
|
|
25
|
+
if self.client:
|
|
26
|
+
self.client.close()
|
|
27
|
+
print("Disconnected.")
|
|
28
|
+
|
|
29
|
+
def _send_packet(self, cmd, data_bytes=None, expect_response=True):
|
|
30
|
+
if data_bytes is None:
|
|
31
|
+
data_bytes = b''
|
|
32
|
+
|
|
33
|
+
packet_len = 2 + 1 + len(data_bytes)
|
|
34
|
+
header = struct.pack('!HB', packet_len, cmd)
|
|
35
|
+
packet = header + data_bytes
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
self.client.send(packet)
|
|
39
|
+
if expect_response:
|
|
40
|
+
response = self.client.recv(1024)
|
|
41
|
+
return response
|
|
42
|
+
return None
|
|
43
|
+
|
|
44
|
+
except Exception as e:
|
|
45
|
+
print(f"Communication error: {e}")
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
def set_duty(self, duty_dict):
|
|
49
|
+
data_bytes = b""
|
|
50
|
+
for joint_id, duty_val in duty_dict.items():
|
|
51
|
+
raw_duty = (duty_val / 450.0) * 1000.0
|
|
52
|
+
|
|
53
|
+
target_duty = int(raw_duty)
|
|
54
|
+
target_duty = max(-1000, min(1000, target_duty))
|
|
55
|
+
|
|
56
|
+
data_bytes += struct.pack('!Bh', joint_id, target_duty)
|
|
57
|
+
|
|
58
|
+
self._send_packet(CMD_SET_DUTY, data_bytes, expect_response=False)
|
|
59
|
+
|
|
60
|
+
def get_data(self, data_types):
|
|
61
|
+
response = self._send_packet(CMD_GET_DATA, bytes(data_types))
|
|
62
|
+
if response:
|
|
63
|
+
return self.parse_response(response, data_types)
|
|
64
|
+
return None
|
|
65
|
+
|
|
66
|
+
def parse_response(self, data, requested_types):
|
|
67
|
+
if len(data) < 3: return None
|
|
68
|
+
|
|
69
|
+
total_len = struct.unpack('!H', data[0:2])[0]
|
|
70
|
+
cmd = data[2]
|
|
71
|
+
|
|
72
|
+
packet = data[:total_len]
|
|
73
|
+
|
|
74
|
+
results = {"joints": {}, "sensors": [None] * self.fingers, "gpio": None}
|
|
75
|
+
|
|
76
|
+
end_offset = total_len
|
|
77
|
+
|
|
78
|
+
if TYPE_GPIO in requested_types:
|
|
79
|
+
end_offset -= 4
|
|
80
|
+
results["gpio"] = packet[end_offset:end_offset+4].hex()
|
|
81
|
+
|
|
82
|
+
if TYPE_TACTILE_SENSOR in requested_types:
|
|
83
|
+
tactile_size = 15 * self.fingers
|
|
84
|
+
end_offset -= tactile_size
|
|
85
|
+
|
|
86
|
+
tactile_data = packet[end_offset:end_offset+tactile_size]
|
|
87
|
+
|
|
88
|
+
for i in range(self.fingers):
|
|
89
|
+
finger_bytes = tactile_data[i*15 : (i+1)*15]
|
|
90
|
+
finger_values = list(finger_bytes)
|
|
91
|
+
results["sensors"][i] = finger_values
|
|
92
|
+
|
|
93
|
+
joint_types = [t for t in requested_types if t in (TYPE_POSITION, TYPE_CURRENT, TYPE_TEMPERATURE, TYPE_VELOCITY)]
|
|
94
|
+
|
|
95
|
+
offset = 3
|
|
96
|
+
if joint_types:
|
|
97
|
+
while offset < end_offset:
|
|
98
|
+
joint_id = packet[offset]
|
|
99
|
+
offset += 1
|
|
100
|
+
joint_info = {}
|
|
101
|
+
|
|
102
|
+
for t in joint_types:
|
|
103
|
+
if t == TYPE_POSITION:
|
|
104
|
+
val = struct.unpack('!h', packet[offset:offset+2])[0]
|
|
105
|
+
joint_info['position'] = val * 0.1
|
|
106
|
+
offset += 2
|
|
107
|
+
elif t == TYPE_CURRENT:
|
|
108
|
+
val = struct.unpack('!h', packet[offset:offset+2])[0]
|
|
109
|
+
joint_info['current'] = val
|
|
110
|
+
offset += 2
|
|
111
|
+
elif t == TYPE_TEMPERATURE:
|
|
112
|
+
val = struct.unpack('!h', packet[offset:offset+2])[0]
|
|
113
|
+
joint_info['temperature'] = val * 0.1
|
|
114
|
+
offset += 2
|
|
115
|
+
elif t == TYPE_VELOCITY:
|
|
116
|
+
raw_val = packet[offset]
|
|
117
|
+
val = raw_val if raw_val < 128 else raw_val - 256
|
|
118
|
+
joint_info['velocity'] = val * 6.0
|
|
119
|
+
offset += 1
|
|
120
|
+
results["joints"][joint_id] = joint_info
|
|
121
|
+
|
|
122
|
+
return results
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
def init_window(window_name="Tesollo Tactile Sensor Viewer"):
|
|
5
|
+
cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)
|
|
6
|
+
cv2.resizeWindow(window_name, 1200, 600)
|
|
7
|
+
return window_name
|
|
8
|
+
|
|
9
|
+
def render_tactile_data(window_name, tactile_data_list):
|
|
10
|
+
num_fingers = 5
|
|
11
|
+
nrows, ncols = 5, 3
|
|
12
|
+
|
|
13
|
+
resolution = 30
|
|
14
|
+
padding = 50
|
|
15
|
+
|
|
16
|
+
img_h = (nrows * resolution) + (padding * 2)
|
|
17
|
+
img_w = (num_fingers * ncols * resolution) + ((num_fingers - 1) * padding) + (padding * 2)
|
|
18
|
+
|
|
19
|
+
vis_img = np.zeros((img_h, img_w, 3), dtype=np.uint8)
|
|
20
|
+
|
|
21
|
+
for f_idx in range(num_fingers):
|
|
22
|
+
finger_data = tactile_data_list[f_idx]
|
|
23
|
+
|
|
24
|
+
start_x = padding + f_idx * (ncols * resolution + padding)
|
|
25
|
+
start_y = padding
|
|
26
|
+
|
|
27
|
+
cv2.putText(vis_img, f"Finger {f_idx + 1}", (start_x, start_y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.3, (255, 255, 255), 0)
|
|
28
|
+
|
|
29
|
+
for r in range(nrows):
|
|
30
|
+
for c in range(ncols):
|
|
31
|
+
idx = r * ncols + c
|
|
32
|
+
val = finger_data[idx]
|
|
33
|
+
|
|
34
|
+
intensity = np.clip(val / 255.0, 0, 1)
|
|
35
|
+
|
|
36
|
+
color_r = int(intensity * 255)
|
|
37
|
+
color_g = int((1 - intensity) * 255)
|
|
38
|
+
color_b = 0
|
|
39
|
+
|
|
40
|
+
center_x = start_x + (c * resolution) + (resolution // 2)
|
|
41
|
+
center_y = start_y + (r * resolution) + (resolution // 2)
|
|
42
|
+
|
|
43
|
+
cv2.circle(vis_img, (center_x, center_y), radius=(resolution // 2) - 3, color=(color_b, color_g, color_r), thickness=-1)
|
|
44
|
+
|
|
45
|
+
text = str(val)
|
|
46
|
+
font = cv2.FONT_HERSHEY_SIMPLEX
|
|
47
|
+
font_scale = 0.3
|
|
48
|
+
thickness = 0
|
|
49
|
+
|
|
50
|
+
text_size, _ = cv2.getTextSize(text, font, font_scale, thickness)
|
|
51
|
+
text_x = center_x - (text_size[0] // 2)
|
|
52
|
+
text_y = center_y + (text_size[1] // 2)
|
|
53
|
+
|
|
54
|
+
cv2.putText(vis_img, text, (text_x, text_y), font, font_scale, (255, 255, 255), thickness)
|
|
55
|
+
|
|
56
|
+
cv2.imshow(window_name, vis_img)
|