Skip to content

Commit fbe9668

Browse files
committed
修复l20压感数据
1 parent d3eef5a commit fbe9668

File tree

3 files changed

+96
-9
lines changed

3 files changed

+96
-9
lines changed
-20 Bytes
Binary file not shown.

LinkerHand/core/can/linker_hand_l20_can.py

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import can
44
import threading
55
from enum import Enum
6+
import numpy as np
67

78
class FrameProperty(Enum):
89
INVALID_FRAME_PROPERTY = 0x00 # Invalid CAN frame property | No return
@@ -33,6 +34,28 @@ def __init__(self, can_channel='can0', baudrate=1000000, can_id=0x28):
3334
self.can_id = can_id
3435
self.running = True
3536
self.x05, self.x06, self.x07 = [],[],[]
37+
# New pressure sensors
38+
self.xb0,self.xb1,self.xb2,self.xb3,self.xb4,self.xb5 = [-1] * 5,[-1] * 5,[-1] * 5,[-1] * 5,[-1] * 5,[-1] * 5
39+
40+
self.thumb_matrix = np.full((12, 6), -1)
41+
self.index_matrix = np.full((12, 6), -1)
42+
self.middle_matrix = np.full((12, 6), -1)
43+
self.ring_matrix = np.full((12, 6), -1)
44+
self.little_matrix = np.full((12, 6), -1)
45+
self.matrix_map = {
46+
0: 0,
47+
16: 1,
48+
32: 2,
49+
48: 3,
50+
64: 4,
51+
80: 5,
52+
96: 6,
53+
112: 7,
54+
128: 8,
55+
144: 9,
56+
160: 10,
57+
176: 11,
58+
}
3659

3760
# Initialize CAN bus according to operating system
3861
if sys.platform == "linux":
@@ -186,6 +209,48 @@ def process_response(self, msg):
186209
elif frame_type == 0x23:
187210
d = list(response_data)
188211
self.approach_inc = [float(i) for i in d]
212+
elif frame_type == 0xb0:
213+
self.xb0 = list(response_data)
214+
elif frame_type == 0xb1:
215+
d = list(response_data)
216+
if len(d) == 2:
217+
self.xb1 = d
218+
elif len(d) == 7:
219+
index = self.matrix_map.get(d[0])
220+
if index is not None:
221+
self.thumb_matrix[index] = d[1:] # Remove the first flag bit
222+
elif frame_type == 0xb2:
223+
d = list(response_data)
224+
if len(d) == 2:
225+
self.xb2 = d
226+
elif len(d) == 7:
227+
index = self.matrix_map.get(d[0])
228+
if index is not None:
229+
self.index_matrix[index] = d[1:] # Remove the first flag bit
230+
elif frame_type == 0xb3:
231+
d = list(response_data)
232+
if len(d) == 2:
233+
self.xb3 = d
234+
elif len(d) == 7:
235+
index = self.matrix_map.get(d[0])
236+
if index is not None:
237+
self.middle_matrix[index] = d[1:] # Remove the first flag bit
238+
elif frame_type == 0xb4:
239+
d = list(response_data)
240+
if len(d) == 2:
241+
self.xb4 = d
242+
elif len(d) == 7:
243+
index = self.matrix_map.get(d[0])
244+
if index is not None:
245+
self.ring_matrix[index] = d[1:] # Remove the first flag bit
246+
elif frame_type == 0xb5:
247+
d = list(response_data)
248+
if len(d) == 2:
249+
self.xb5 = d
250+
elif len(d) == 7:
251+
index = self.matrix_map.get(d[0])
252+
if index is not None:
253+
self.little_matrix[index] = d[1:] # Remove the first flag bit
189254
def pose_slice(self, p):
190255
"""Slice the joint array into finger action arrays"""
191256
try:
@@ -243,14 +308,36 @@ def get_temperature(self):
243308
def clear_faults(self):
244309
'''Clear motor faults'''
245310
self.send_command(0x07, [1, 1, 1, 1, 1])
246-
247311
def get_touch_type(self):
248-
'''Get touch type, not supported'''
249-
return [-1] * 5
312+
'''Get touch type'''
313+
self.send_command(0xb0,[],sleep=0.03)
314+
self.send_command(0xb1,[],sleep=0.03)
315+
t = []
316+
for i in range(3):
317+
t = self.xb1
318+
time.sleep(0.01)
319+
if len(t) == 2:
320+
return 2
321+
else:
322+
return -1
250323

251324
def get_touch(self):
252-
'''Get touch data, not supported'''
253-
return [-1] * 6
325+
'''Get touch data'''
326+
self.send_command(0xb1,[],sleep=0.03)
327+
self.send_command(0xb2,[],sleep=0.03)
328+
self.send_command(0xb3,[],sleep=0.03)
329+
self.send_command(0xb4,[],sleep=0.03)
330+
self.send_command(0xb5,[],sleep=0.03)
331+
return [self.xb1[1],self.xb2[1],self.xb3[1],self.xb4[1],self.xb5[1],0] # The last digit is palm, currently not available
332+
333+
def get_matrix_touch(self):
334+
self.send_command(0xb1,[0xc6],sleep=0.04)
335+
self.send_command(0xb2,[0xc6],sleep=0.04)
336+
self.send_command(0xb3,[0xc6],sleep=0.04)
337+
self.send_command(0xb4,[0xc6],sleep=0.04)
338+
self.send_command(0xb5,[0xc6],sleep=0.04)
339+
return self.thumb_matrix , self.index_matrix , self.middle_matrix , self.ring_matrix , self.little_matrix
340+
254341

255342
def get_faults(self):
256343
'''Get motor fault codes'''

LinkerHand/linker_hand_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from utils.open_can import OpenCan
99

1010
class LinkerHandApi:
11-
def __init__(self, hand_type="left", hand_joint="L10", modbus = "None",can="can0"): # Ubuntu:can0 win:PCAN_USBBUS1
11+
def __init__(self, hand_type="left", hand_joint="L10", modbus = "None",can="can0"):
1212
self.last_position = []
1313
self.yaml = LoadWriteYaml()
1414
self.config = self.yaml.load_setting_yaml()
@@ -53,9 +53,9 @@ def __init__(self, hand_type="left", hand_joint="L10", modbus = "None",can="can0
5353
if sys.platform == "linux":
5454
self.open_can = OpenCan(load_yaml=self.yaml)
5555
self.open_can.open_can(self.can)
56-
self.is_can = self.open_can.is_can_up_sysfs()
56+
self.is_can = self.open_can.is_can_up_sysfs(interface=self.can)
5757
if not self.is_can:
58-
ColorMsg(msg="CAN0 interface is not open", color="red")
58+
ColorMsg(msg=f"{self.can} interface is not open", color="red")
5959
sys.exit(1)
6060

6161
# Five-finger movement
@@ -226,4 +226,4 @@ def close_can(self):
226226
self.open_can.close_can0()
227227

228228
if __name__ == "__main__":
229-
hand = LinkerHandApi(hand_type="right", hand_joint="L10")
229+
hand = LinkerHandApi(hand_type="right", hand_joint="L10")

0 commit comments

Comments
 (0)