-
-
Save yenchenlin/3458989221431b620c6dbd917f04dc24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if something is in between gripper fingers by measuring grasp width | |
# def check_grasp_robotiq(self): | |
# self._gripper_data = None | |
# tcp_msg = 'def process():\n' | |
# tcp_msg += ' socket_open("127.0.0.1",63352,"gripper_socket")\n' | |
# tcp_msg += ' rq_pos = socket_get_var("POS","gripper_socket")\n' | |
# tcp_msg += ' sync()\n' | |
# tcp_msg += ' textmsg("value = ",rq_pos)\n' | |
# tcp_msg += ' socket_open("100.107.146.22",50201,"desktop_socket")\n' | |
# tcp_msg += ' socket_send_int(rq_pos,"desktop_socket")\n' | |
# tcp_msg += ' sync()\n' | |
# tcp_msg += ' socket_close("desktop_socket")\n' | |
# tcp_msg += 'end\n' | |
# self._tcp_sock.send(str.encode(tcp_msg)) | |
# time.sleep(0.1) | |
# while not self._gripper_data: | |
# time.sleep(0.01) | |
# print(self._gripper_data) | |
# # exit() | |
# return self._gripper_data < 225 | |
I forgot if this worked or not | |
Oh and then there’s a thread that continually parses for _gripper_data | |
self._gripper_data = None | |
gripper_thread = threading.Thread(target=self.get_gripper_data) | |
gripper_thread.daemon = True | |
gripper_thread.start() | |
def get_gripper_data(self): | |
hostName = socket.gethostbyname('0.0.0.0') | |
TCP_PORT = 50201 | |
BUFFER_SIZE = 1024 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((hostName, TCP_PORT)) | |
while 1: | |
time.sleep(0.01) | |
s.listen(1) | |
conn, addr = s.accept() | |
# print 'Connection address:', addr | |
data = conn.recv(BUFFER_SIZE) | |
if not data: continue | |
# message_type = int(struct.unpack('!i',state_data[0:4])[0]) | |
self._gripper_data = int(struct.unpack('!i',data[0:4])[0]) | |
# Parse TCP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment