Skip to content

Commit 7ccb5d2

Browse files
author
Mike Lambeta
committed
added new sensors interface for gelsight mini and digit, technical preview
1 parent 6159b8f commit 7ccb5d2

13 files changed

+710
-0
lines changed

sensors/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# PyTouch Sensors
2+
3+
Python interface for the tactile sensors
4+
This will become a generic interface for connecting with numerous tactile sensors
5+
6+
## Installation
7+
8+
Clone the repository and install the package using:
9+
10+
```bash
11+
git clone https://github.com/facebookresearch/pytouch.git
12+
cd pytouch/sensors
13+
pip install -r requirements.txt
14+
python setup.py install
15+
```
16+
17+
If you cannot access the device by serial number on your system follow [adding udev Rule](#adding-udev-rule)
18+
19+
### Adding udev Rule
20+
Add your user to the ```plugdev``` group,
21+
22+
```
23+
sudo adduser username plugdev
24+
```
25+
26+
Copy udev rule,
27+
28+
```
29+
sudo cp ./udev-rules/*.rules /lib/udev/rules.d/
30+
```
31+
32+
Reload rules,
33+
34+
```
35+
sudo udevadm control --reload
36+
sudo udevadm trigger
37+
```
38+
39+
Replug the tactile sensor into host.

sensors/examples/demo_digit.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
2+
# This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
3+
4+
import logging
5+
import pprint
6+
import time
7+
8+
from pytouch_sensors import digit
9+
from pytouch_sensors.digit import Digit
10+
11+
logging.basicConfig(level=logging.DEBUG)
12+
13+
# Print a list of connected DIGIT's
14+
digits = digit.find()
15+
print("Connected DIGIT's to Host:")
16+
pprint.pprint(digits)
17+
18+
# Connect to a Digit device with serial number with friendly name
19+
digit = Digit("D01001", "Left Gripper")
20+
digit.connect()
21+
22+
# Print device info
23+
print(digit.info())
24+
25+
# Change LED illumination intensity
26+
digit.set_intensity(Digit.LIGHTING_MIN)
27+
time.sleep(1)
28+
digit.set_intensity(Digit.LIGHTING_MAX)
29+
30+
# Change DIGIT resolution to QVGA
31+
qvga_res = Digit.STREAMS["QVGA"]
32+
digit.set_resolution(qvga_res)
33+
34+
# Change DIGIT FPS to 15fps
35+
fps_30 = Digit.STREAMS["QVGA"]["fps"]["30fps"]
36+
digit.set_fps(fps_30)
37+
38+
# Grab single frame from DIGIT
39+
frame = digit.get_frame()
40+
print(f"Frame WxH: {frame.shape[0]}{frame.shape[1]}")
41+
42+
# Display stream obtained from DIGIT
43+
digit.show_view()
44+
45+
# Disconnect DIGIT stream
46+
digit.disconnect()
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
2+
# This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
3+
4+
import logging
5+
import pprint
6+
import time
7+
8+
from pytouch_sensors import gelsight
9+
from pytouch_sensors.gelsight import GelsightMini
10+
11+
logging.basicConfig(level=logging.DEBUG)
12+
13+
print("Connected Gelsight sensors to host:")
14+
gelsight_sensors = gelsight.find()
15+
pprint.pprint(gelsight_sensors)
16+
17+
gs_mini = GelsightMini("28CF-95MN", "Thumb")
18+
gs_mini.connect()
19+
20+
# Print device info
21+
print(gs_mini.info())
22+
23+
frame = gs_mini.get_frame()
24+
print(f"Frame WxH: {frame.shape[0]}{frame.shape[1]}")
25+
26+
gs_mini.show_view()
27+
28+
gs_mini.disconnect()
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
2+
3+
# This source code is licensed under the license found in the LICENSE file in the root directory of this source tree.
4+
5+
import logging
6+
import pprint
7+
import time
8+
import random
9+
10+
from pytouch_sensors import digit
11+
from pytouch_sensors.digit import Digit
12+
13+
logging.basicConfig(level=logging.DEBUG)
14+
15+
# Print a list of connected DIGIT's
16+
digits = digit.find()
17+
print("Connected DIGIT's to Host:")
18+
pprint.pprint(digits)
19+
20+
# Connect to a Digit device with serial number with friendly name
21+
digit = Digit("D01001", "Left Gripper")
22+
digit.connect()
23+
24+
# Maximum value for each channel is 15
25+
rgb_list = [(15, 0, 0), (0, 15, 0), (0, 0, 15)]
26+
27+
# digit.show_view()
28+
import cv2
29+
30+
# Cycle through colors R, G, B
31+
while True:
32+
rgb = (random.randint(0, 15), random.randint(0, 15), random.randint(0, 15))
33+
digit.set_intensity_rgb(*rgb)
34+
frame = digit.get_frame()
35+
cv2.imshow(f"Digit View {digit.serial}", frame)
36+
if cv2.waitKey(1) == 27:
37+
break
38+
time.sleep(1)
39+
40+
cv2.destroyAllWindows()
41+
42+
# Set all LEDs to same intensity
43+
digit.set_intensity(15)
44+
45+
digit.disconnect()

sensors/pytouch_sensors/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pytouch_sensors import digit
2+
from pytouch_sensors import gelsight
3+
4+
__version__ = "0.1.0"
5+
__all__ = ["digit", "gelsight"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .digit import Digit, DigitStreams, find
2+
3+
4+
__all__ = ["Digit", "DigitStreams", "find"]

0 commit comments

Comments
 (0)