-
Notifications
You must be signed in to change notification settings - Fork 1
/
cd.py
38 lines (35 loc) · 1.59 KB
/
cd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Author: Quan Khanh Luu (JAIST)
Contact: [email protected]
Descriptions:
- Contact detection for ViTac devices (e.g., TacLink)
It is important that the soft artificial skin is represeted by a mesh (graph).
"""
import numpy as np
from utils import simtacls_utils
skin_mesh_vtk = './resources/skin.vtk'
tactile_skin = simtacls_utils.TactileSkin(skin_path=skin_mesh_vtk)
# extract fixed inward radial vectors
radial_vectors = tactile_skin.get_radial_vectors()
def contact_detection(nodal_displacements, threshold):
"""
Contact detection for ViTac devices based on nodal displacements
Parameters:
- nodal_displacements (N,3): 3D predicted nodal displacement vectors for N nodes
- threshold: deformed region threshold
Returns:
- no_of_contacts: the number of contacts detected
- contact_positions: 3-D contact positions
"""
# compute directional similarity at every nodes on the skin surface
dir_sim = simtacls_utils.compute_directional_similarity(nodal_displacements, radial_vectors)
nodal_displacement_magnitude = np.linalg.norm(nodal_displacements, axis=1)
# directional signals
dir_signals = dir_sim > 0.
# assign True to the deformed nodes, whose intensities > threshold
contact_signals = nodal_displacement_magnitude > threshold
# obtain nodal contact signals
nodal_contact_signals = contact_signals & dir_signals
# extract the number of deformed nodes
num_of_deformed_nodes = len(nodal_displacement_magnitude[nodal_contact_signals])
return True if num_of_deformed_nodes > 0 else False