ソースを参照

Hand controller (for state tracking)

dk 1 年間 前
コミット
eb7ee269ab
1 ファイル変更17 行追加9 行削除
  1. 17 9
      backend/device/fubo_pneumatic_finger.py

+ 17 - 9
backend/device/fubo_pneumatic_finger.py

@@ -1,13 +1,4 @@
-'''
-@Author  :   liujunshen
-@Ide     :   vscode
-@File    :   fubo_pneumatic_finger.py
-@Time    :   2023/04/03 16:49:11
-'''
-
-
 import logging
-import time
 
 import serial
 from serial.tools.list_ports import comports
@@ -23,6 +14,23 @@ def get_serial_ports():
     return available_ports_list
 
 
+class FingerController:
+    def __init__(self, init_params):
+        self.hand = FuboPneumaticFingerClient(init_params)
+        self.current_state = 'rest'
+
+    def move(self, action='flex'):
+        if self.current_state == 'extend':
+            self.hand.start(action)
+            self.current_state = action
+        elif self.current_state == action:
+            self.hand.start('extend')
+            self.current_state = 'extend'
+        else:  # rest or any other
+            self.hand.start(action)
+            self.current_state = action
+
+
 class FuboPneumaticFingerClient:
     """富伯客户端"""