ArtusAPI 0.5.0__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/artus_api.py +107 -9
  2. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/commands/commands.py +51 -18
  3. ArtusAPI-1.0.0/ArtusAPI/communication/UART/uart.py +104 -0
  4. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/communication/WiFi/wifi_server.py +12 -47
  5. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/communication/communication.py +53 -13
  6. ArtusAPI-1.0.0/ArtusAPI/firmware_update/__init__.py +1 -0
  7. ArtusAPI-1.0.0/ArtusAPI/firmware_update/firmware_updater.py +129 -0
  8. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/robot/artus_lite/artus_lite.py +25 -19
  9. ArtusAPI-1.0.0/ArtusAPI.egg-info/PKG-INFO +11 -0
  10. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI.egg-info/SOURCES.txt +2 -0
  11. ArtusAPI-1.0.0/PKG-INFO +11 -0
  12. ArtusAPI-1.0.0/README.md +145 -0
  13. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/setup.py +4 -3
  14. ArtusAPI-0.5.0/ArtusAPI/communication/UART/uart.py +0 -83
  15. ArtusAPI-0.5.0/ArtusAPI.egg-info/PKG-INFO +0 -4
  16. ArtusAPI-0.5.0/PKG-INFO +0 -4
  17. ArtusAPI-0.5.0/README.md +0 -34
  18. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/__init__.py +0 -0
  19. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/commands/__init__.py +0 -0
  20. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/communication/UART/__init__.py +0 -0
  21. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/communication/WiFi/__init__.py +0 -0
  22. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/communication/__init__.py +0 -0
  23. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/robot/__init__.py +0 -0
  24. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/robot/artus_lite/__init__.py +0 -0
  25. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/robot/artus_lite/artus_lite_left.py +0 -0
  26. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/robot/artus_lite/artus_lite_right.py +0 -0
  27. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI/robot/robot.py +0 -0
  28. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI.egg-info/dependency_links.txt +0 -0
  29. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/ArtusAPI.egg-info/top_level.txt +0 -0
  30. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/setup.cfg +0 -0
  31. {ArtusAPI-0.5.0 → ArtusAPI-1.0.0}/test/test.py +0 -0
@@ -14,6 +14,7 @@ print(desired_path)
14
14
  from .communication import Communication
15
15
  from .commands import Commands
16
16
  from .robot import Robot
17
+ from .firmware_update import FirmwareUpdater
17
18
  import time
18
19
 
19
20
  class ArtusAPI:
@@ -27,12 +28,24 @@ class ArtusAPI:
27
28
  hand_type ='left',
28
29
  stream = False,
29
30
  communication_frequency = 400, # hz
30
- logger = None
31
+ logger = None,
32
+ reset_on_start = 0,
33
+ baudrate = 921600
31
34
  ):
35
+ """
36
+ ArtusAPI class controls the communication and control of between a system and an Artus Hand by Sarcomere Dynamics Inc.
37
+ :communication_method: communication method that is supported on the Artus Hand
38
+ :communication_channel_identifier: channel identifier for the communication method
39
+ :robot_type: name of the series of robot hand
40
+ :hand_type: left or right
41
+ :stream: streaming feedback data
42
+ :communication_frequency: maximum frequency to stream data
43
+ :logger: python logger settings to inherit
44
+ """
32
45
 
33
46
  self._communication_handler = Communication(communication_method=communication_method,
34
- communication_channel_identifier=communication_channel_identifier)
35
- self._command_handler = Commands()
47
+ communication_channel_identifier=communication_channel_identifier,baudrate=baudrate)
48
+ self._command_handler = Commands(reset_on_start=reset_on_start)
36
49
  self._robot_handler = Robot(robot_type = robot_type,
37
50
  hand_type = hand_type)
38
51
 
@@ -48,8 +61,14 @@ class ArtusAPI:
48
61
 
49
62
  # communication setup
50
63
  def connect(self):
64
+ """
65
+ Open a connection to the Artus Hand
66
+ """
51
67
  return self._communication_handler.open_connection()
52
68
  def disconnect(self):
69
+ """
70
+ Close a connection to the Artus Hand
71
+ """
53
72
  return self._communication_handler.close_connection()
54
73
 
55
74
 
@@ -57,19 +76,45 @@ class ArtusAPI:
57
76
 
58
77
  # robot states
59
78
  def wake_up(self):
79
+ """
80
+ Wake-up the Artus Hand
81
+ """
60
82
  print(f"communication frequency in useconds = {self._communication_frequency_us}")
61
83
  robot_wake_up_command = self._command_handler.get_robot_start_command(self.stream,self._communication_frequency_us) # to ms for masterboard
62
- return self._communication_handler.send_data(robot_wake_up_command)
84
+ self._communication_handler.send_data(robot_wake_up_command)
85
+
86
+ # wait for data back
87
+ if self._communication_handler.wait_for_ack():
88
+ self.logger.info(f'Finished calibration')
89
+ else:
90
+ self.logger.warn(f'Error in calibration')
91
+
63
92
  def sleep(self):
93
+ """
94
+ Sleep the Artus Hand
95
+ """
64
96
  robot_sleep_command = self._command_handler.get_sleep_command()
65
97
  return self._communication_handler.send_data(robot_sleep_command)
66
98
  def calibrate(self):
99
+ """
100
+ Calibrate the Artus Hand
101
+ """
67
102
  robot_calibrate_command = self._command_handler.get_calibration_command()
68
- return self._communication_handler.send_data(robot_calibrate_command)
103
+ self._communication_handler.send_data(robot_calibrate_command)
104
+
105
+ # wait for data back
106
+ if self._communication_handler.wait_for_ack():
107
+ self.logger.info(f'Finished calibration')
108
+ else:
109
+ self.logger.warn(f'Error in calibration')
69
110
 
70
111
 
71
112
  # robot control
72
113
  def set_joint_angles(self, joint_angles:dict):
114
+ """
115
+ Set joint angle targets and speed values to the Artus Hand
116
+ :joint_angles: dictionary of input angles and input speeds
117
+ """
73
118
  self._robot_handler.set_joint_angles(joint_angles=joint_angles,name=False)
74
119
  robot_set_joint_angles_command = self._command_handler.get_target_position_command(self._robot_handler.robot.hand_joints)
75
120
  # check communication frequency
@@ -78,8 +123,11 @@ class ArtusAPI:
78
123
  return self._communication_handler.send_data(robot_set_joint_angles_command)
79
124
 
80
125
  def set_home_position(self):
126
+ """
127
+ sends the joints to home positions (0) which opens the Artus Hand
128
+ """
81
129
  self._robot_handler.set_home_position()
82
- robot_set_home_position_command = self._command_handler.get_target_position_command()
130
+ robot_set_home_position_command = self._command_handler.get_target_position_command(hand_joints=self._robot_handler.robot.hand_joints)
83
131
  # check communication frequency
84
132
  if not self._check_communication_frequency():
85
133
  return False
@@ -96,21 +144,28 @@ class ArtusAPI:
96
144
  self._last_command_sent_time = current_time
97
145
  return True
98
146
 
99
-
100
-
101
147
  # robot feedback
102
148
  def _receive_feedback(self):
103
149
  feedback_command = self._command_handler.get_states_command()
104
150
  self._communication_handler.send_data(feedback_command)
151
+ # test
152
+ time.sleep(0.005)
105
153
  return self._communication_handler.receive_data()
106
154
 
107
155
  def get_joint_angles(self):
156
+ """
157
+ Populate feedback fields in self._robot_handler.hand_joints dict
158
+ """
108
159
  feedback_command = self._receive_feedback()
109
160
  joint_angles = self._robot_handler.get_joint_angles(feedback_command)
161
+ print(joint_angles)
110
162
  return joint_angles
111
163
 
112
164
  # robot feedback stream
113
165
  def get_streamed_joint_angles(self):
166
+ """
167
+ Populate feedback fields in self._robot_handler.hand_joints dict
168
+ """
114
169
  if not self._check_communication_frequency():
115
170
  return False
116
171
  feedback_command = self._communication_handler.receive_data()
@@ -119,9 +174,52 @@ class ArtusAPI:
119
174
  joint_angles = self._robot_handler.get_joint_angles(feedback_command)
120
175
  return joint_angles
121
176
 
177
+ def update_firmware(self):
178
+ file_path = None
179
+ fw_size = 0
180
+ # input to upload a new file
181
+ upload_flag = input(f'Uploading a new BIN file? (y/n) : ')
182
+ upload = True
183
+
184
+
185
+ self._firmware_updater = FirmwareUpdater(self._communication_handler,
186
+ self._command_handler)
122
187
 
123
-
188
+ if upload_flag == 'n' or upload_flag == 'N':
189
+ self._firmware_updater.file_location = 'not empty'
190
+ upload = False
191
+ else:
192
+
193
+ self._firmware_updater.file_location = input('Please enter binfile absolute path: ')
124
194
 
195
+ fw_size = self._firmware_updater.get_bin_file_info()
196
+
197
+ # set which drivers to flash should be 1-8
198
+ drivers_to_flash = int(input(f'Which drivers would you like to flash? \n0:ALL\nor 1-8\n: '))
199
+ if not drivers_to_flash:
200
+ drivers_to_flash = 0
201
+
202
+ firmware_command = self._command_handler.get_firmware_command(fw_size,upload,drivers_to_flash)
203
+ self._communication_handler.send_data(firmware_command)
204
+ if upload:
205
+ self._firmware_updater.update_firmware(fw_size)
206
+
207
+ print(f'File size = {fw_size}')
208
+ print(f'flashing...')
209
+ self._communication_handler.wait_for_ack()
210
+ print(f'Power Cycle the device to take effect')
211
+
212
+ def reset(self):
213
+ j = int(input(f'Enter Joint to reset: '))
214
+ m = int(input(f'Enter Motor to reset: '))
215
+ reset_command = self._command_handler.get_locked_reset_low_command(j,m)
216
+ self._communication_handler.send_data(reset_command)
217
+
218
+ def hard_close(self):
219
+ j = int(input(f'Enter Joint to reset: '))
220
+ m = int(input(f'Enter Motor to reset: '))
221
+ hard_close = self._command_handler.get_hard_close_command(j,m)
222
+ self._communication_handler.send_data(hard_close)
125
223
 
126
224
  def test_artus_api():
127
225
  artus_api = ArtusAPI()
@@ -4,18 +4,20 @@ import time
4
4
  class Commands:
5
5
 
6
6
  def __init__(self,
7
- start_command= 11,
8
- calibrate_command = 13,
9
- sleep_command = 15,
10
- firmware_update_command = 17,
11
- reset_command = 19,
7
+ start_command= 0x0B,
8
+ calibrate_command = 0x0D,
9
+ sleep_command = 0x0F,
10
+ firmware_update_command = 0x11,
11
+ reset_command = 0x13,
12
+ hard_close = 0x38,
12
13
 
13
- target_command = 102,
14
- get_feedback_command = 104,
14
+ target_command = 0x66,
15
+ get_feedback_command = 0x68,
15
16
 
16
- save_grasp_onboard_command = 200,
17
- return_grasps_command = 210,
18
- execute_grasp_command = 224):
17
+ save_grasp_onboard_command = 0xC8,
18
+ return_grasps_command = 0xD2,
19
+ execute_grasp_command = 0xE0,
20
+ reset_on_start = 0):
19
21
 
20
22
  self.commands = {
21
23
  'start_command': start_command,
@@ -23,12 +25,14 @@ class Commands:
23
25
  'sleep_command': sleep_command,
24
26
  'firmware_update_command': firmware_update_command,
25
27
  'reset_command': reset_command,
28
+ 'hard_close_command' : hard_close,
26
29
  'target_command': target_command,
27
30
  'get_feedback_command': get_feedback_command,
28
31
  'save_grasp_onboard_command': save_grasp_onboard_command,
29
32
  'return_grasps_command': return_grasps_command,
30
33
  'execute_grasp_command': execute_grasp_command
31
34
  }
35
+ self.reset_on_start = reset_on_start
32
36
 
33
37
  def get_robot_start_command(self,stream:bool,freq:int) -> list:
34
38
  """
@@ -43,25 +47,36 @@ class Commands:
43
47
  second = int(time.localtime().tm_sec)
44
48
 
45
49
  if stream:
46
- return [self.commands['start_command'],20,year,month,day,hour,minute,second,1,(freq>>16)&0xff,(freq>>8)&0xff,freq&0xff]
50
+ return [self.commands['start_command'],20,year,month,day,hour,minute,second,1,(freq>>16)&0xff,(freq>>8)&0xff,freq&0xff,self.reset_on_start]
47
51
  else:
48
- return [self.commands['start_command'],20,year,month,day,hour,minute,second]
52
+ return [self.commands['start_command'],20,year,month,day,hour,minute,second,0,0,0,0,self.reset_on_start]
49
53
 
50
54
 
51
55
  def get_target_position_command(self,hand_joints:dict) -> list:
52
56
  command_list = [0]*32 # create empty buffer
53
57
  # fill command list with data
54
58
  for name,joint_data in hand_joints.items():
55
- command_list[joint_data.index] = joint_data.target_angle
56
- command_list[joint_data.index+16] = joint_data.velocity
59
+ command_list[joint_data.index] = int(joint_data.target_angle)
60
+ command_list[joint_data.index+16] = int(joint_data.velocity)
57
61
  # insert the command
58
62
  command_list.insert(0,self.commands['target_command'])
59
63
 
60
64
  return command_list
61
65
 
66
+ def get_firmware_command(self,fw_size,upload,drivers):
67
+ command_list = [0]*32
68
+ command_list.insert(0,self.commands['firmware_update_command'])
69
+ command_list[1] = (fw_size >> 24) & 0xFF
70
+ command_list[2] = (fw_size >> 16) & 0xff
71
+ command_list[3] = (fw_size >> 8) & 0xff
72
+ command_list[4] = (fw_size) & 0xff
73
+ command_list[5] = upload
74
+ command_list[6] = drivers
75
+ return command_list
76
+
62
77
  def get_calibration_command(self):
63
78
  command_list = [0]*32
64
- command_list.insert(0,self.commands['calibration_command'])
79
+ command_list.insert(0,self.commands['calibrate_command'])
65
80
  return command_list
66
81
 
67
82
  def get_sleep_command(self):
@@ -79,18 +94,36 @@ class Commands:
79
94
  command_list.insert(0,self.commands['firmware_update_command'])
80
95
  return command_list
81
96
 
97
+ def get_hard_close_command(self,joint=None,motor=None):
98
+ command_list = [0]*32
99
+ command_list.insert(0,self.commands['hard_close_command'])
100
+
101
+ # constraint checker
102
+ if 0 <= joint <= 15:
103
+ command_list[1] = joint
104
+ else:
105
+ # TODO logging
106
+ None
107
+ if 0 <= motor <= 2:
108
+ command_list[2] = motor
109
+ else:
110
+ # TODO logging
111
+ None
112
+
113
+ return command_list
114
+
82
115
  def get_locked_reset_low_command(self, joint=None, motor=None):
83
116
  command_list = [0]*32
84
117
  command_list.insert(0,self.commands['reset_command'])
85
118
 
86
119
  # constraint checker
87
120
  if 0 <= joint <= 15:
88
- command_list[0] = joint
121
+ command_list[1] = joint
89
122
  else:
90
123
  # TODO logging
91
124
  None
92
125
  if 0 <= motor <= 2:
93
- command_list[1] = motor
126
+ command_list[2] = motor
94
127
  else:
95
128
  # TODO logging
96
129
  None
@@ -99,4 +132,4 @@ class Commands:
99
132
 
100
133
 
101
134
  if __name__ == "__main__":
102
- None
135
+ None
@@ -0,0 +1,104 @@
1
+ import serial
2
+ import logging
3
+ import time
4
+
5
+ class UART:
6
+ def __init__(self,
7
+ port='COM9',
8
+ baudrate=921600, #115200,
9
+ timeout=0.5,
10
+ logger = None):
11
+
12
+ # automatically connect to the first available port
13
+ self.port = port
14
+ self.baudrate = baudrate
15
+ self.timeout = timeout
16
+
17
+ self.esp32 = serial.Serial(baudrate=self.baudrate, timeout= self.timeout)
18
+
19
+ # required delays for sending message
20
+ self.timer_send = 0.003
21
+ self.timer_recv = self.timer_send*4
22
+ self.maximum_freq = 700 # hz
23
+
24
+ if not logger:
25
+ self.logger = logging.getLogger(__name__)
26
+ else:
27
+ self.logger = logger
28
+
29
+ def open(self):
30
+ try:
31
+ self.esp32.port=self.port
32
+ self.esp32.close()
33
+ self.esp32.open()
34
+ self.logger.info(f"Opening {self.port} @ {self.baudrate} baudrate")
35
+ self.esp32.flush()
36
+ except Exception as e:
37
+ self.logger.error(f'Error opening port {self.port}')
38
+ self.logger.error(e)
39
+
40
+ def send(self, data:bytearray):
41
+ # print(data)
42
+ try:
43
+ self.esp32.write(data)
44
+
45
+ # required delay
46
+ t = time.perf_counter()
47
+ while time.perf_counter() - t < self.timer_send:
48
+ pass
49
+ except Exception as e:
50
+ self.logger.error(f'Unable to send command through {self.port}')
51
+ self.logger.error(e)
52
+
53
+ def receive(self):
54
+
55
+ # required delay
56
+ # t = time.perf_counter()
57
+ # while time.perf_counter() - t < self.timer_recv:
58
+ # pass
59
+ try:
60
+ x = time.perf_counter()
61
+ # print(f'time start: {x}')
62
+ while self.esp32.in_waiting < 65:
63
+ if time.perf_counter() - x > 0.02:
64
+ break
65
+ # print(f'elapsed time: {time.perf_counter() - x}')
66
+ # time.sleep(0.03)
67
+ # check data
68
+ if self.esp32.in_waiting >= 65: # get data if greater or equal to 65
69
+ msg_bytes = self.esp32.read(65)
70
+ print(msg_bytes)
71
+ return msg_bytes
72
+ elif self.esp32.in_waiting > 0: # clear buffer if not correct amount of data
73
+ msg_bytes = self.esp32.read_all()
74
+ self.logger.warning(f"Incomplete data received - package size = {(self.esp32.in_waiting)}")
75
+ return None
76
+ else: # non blocking
77
+ return None
78
+ except Exception as e:
79
+ self.logger.warning(f"No data available to receive {e}")
80
+ self.logger.error(e)
81
+
82
+ def close(self):
83
+ self.esp32.close()
84
+
85
+
86
+ def test_serial_receive():
87
+ esp32_communication = UART()
88
+ esp32_communication.start()
89
+ while True:
90
+ msg = esp32_communication.receive()
91
+ if msg != "":
92
+ print(msg)
93
+
94
+ def test_serial_send():
95
+ esp32_communication = UART()
96
+ esp32_communication.start()
97
+ while True:
98
+ esp32_communication.send("hello\n")
99
+ time.sleep(1)
100
+
101
+
102
+ if __name__ == "__main__":
103
+ test_serial_receive()
104
+ # test_serial_send()
@@ -41,7 +41,7 @@ class WiFiServer:
41
41
 
42
42
  def _get_available_ip(self):
43
43
  gateway_ip = None
44
-
44
+
45
45
  # Get all network interfaces
46
46
  interfaces = psutil.net_if_addrs()
47
47
 
@@ -69,10 +69,10 @@ class WiFiServer:
69
69
  source_ip = self._get_available_ip()
70
70
  # TCP tuple
71
71
  self.esp = (source_ip,self.port)
72
-
72
+ print(self.esp)
73
73
  # create server socket
74
74
  self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
75
- self.server_socket.settimeout(8) # blocking timeout to connect
75
+ self.server_socket.settimeout(10) # blocking timeout to connect
76
76
  self.server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
77
77
  self.server_socket.bind(self.esp)
78
78
 
@@ -82,11 +82,12 @@ class WiFiServer:
82
82
  self.logger.info(f"Listening for connection")
83
83
  except Exception as e:
84
84
  self.logger.error(f"No Network named {self.target_ssid}")
85
+ print(e)
85
86
 
86
87
  # Accept the connection
87
88
  try:
88
89
  self.conn, self.addr = self.server_socket.accept()
89
- self.conn.settimeout(0.1) # 1 ms timeout for recv and send methods
90
+ self.conn.settimeout(0.5) # 1 ms timeout for recv and send methods
90
91
  # TODO logging
91
92
  self.logger.info(f"New Connection: {self.addr} connected.")
92
93
  except TimeoutError as e:
@@ -119,6 +120,8 @@ class WiFiServer:
119
120
  self.logger.warning(f"Unable to create wifi profile")
120
121
 
121
122
  else:
123
+ # refresh wifi scan
124
+
122
125
  # connect to profile
123
126
  connect_command = f'netsh wlan connect ssid={self.target_ssid} name={self.target_ssid} interface=Wi-Fi'
124
127
  subprocess.run(connect_command, shell=True)
@@ -130,13 +133,13 @@ class WiFiServer:
130
133
  # input password
131
134
  if not self.password:
132
135
  self.password = input('type ssid password:')
133
- if self.password:
136
+ elif self.password:
134
137
  connect_command += f' password "{self.password}"'
135
138
 
136
139
  subprocess.run(connect_command, shell=True)
137
140
 
138
141
  # clear password
139
- self.password = None
142
+ # self.password = None
140
143
 
141
144
  else:
142
145
  # TODO logging
@@ -157,7 +160,7 @@ class WiFiServer:
157
160
 
158
161
  elif system == "Linux":
159
162
  # Linux uses the "nmcli" command to disconnect from Wi-Fi networks
160
- disconnect_command = f'nmcli dev disconnect iface "wlp2s0" ssid "{self.target_ssid}"'
163
+ disconnect_command = f'nmcli con down id "{self.target_ssid}"'
161
164
  subprocess.run(disconnect_command, shell=True)
162
165
 
163
166
  else:
@@ -183,7 +186,7 @@ class WiFiServer:
183
186
  return None
184
187
  except Exception as e:
185
188
  # TODO logging
186
- self.logger.warning(f"No data available to receive")
189
+ self.logger.warning(f"No data available to receive {e}")
187
190
  return None
188
191
 
189
192
 
@@ -193,42 +196,4 @@ class WiFiServer:
193
196
  except Exception as e:
194
197
  # TODO insert error logging
195
198
  self.logger.error(f"Unable to send data")
196
- None
197
-
198
- def flash_wifi(self):
199
- acknowledged = False
200
-
201
- file_location = input("Enter file path: ")
202
- # file_location = "C:\\Users\\RyanLee\\Documents\\GitHub\\Artus-3D-actuators-fw\\Debug\\actuator_m0.bin"
203
- file_size = os.path.getsize(file_location)
204
-
205
- self.conn.send("file ready\n".encode())
206
- self.conn.send((str(file_size)+"\n").encode())
207
- file = open(file_location, "rb")
208
- file_data = file.read()
209
- file.close
210
- self.conn.sendall(file_data)
211
-
212
- while not acknowledged:
213
- message = self.conn.recv(1024).decode()
214
- if message == "failed":
215
- print("File upload failed\n")
216
- acknowledged = True
217
- elif message == "success":
218
- print("File upload successful\n")
219
- acknowledged = True
220
-
221
- print("Flashing...")
222
-
223
- while True:
224
- message = self.conn.recv(1024).decode()
225
- if message == "FLASHED":
226
- print("Firmware update complete")
227
- break
228
-
229
- def upload_logs_wifi():
230
- while True:
231
- # receive here
232
- if """ finishing condition""":
233
- break
234
- return
199
+ None
@@ -29,11 +29,12 @@ class Communication:
29
29
  """
30
30
  def __init__(self,
31
31
  communication_method='UART',
32
- communication_channel_identifier='COM9',logger = None):
32
+ communication_channel_identifier='COM9',logger = None,baudrate = 921600):
33
33
  # initialize communication
34
34
  self.communication_method = communication_method
35
35
  self.communication_channel_identifier = communication_channel_identifier
36
36
  self.communicator = None
37
+ self.baudrate = baudrate
37
38
  # setup communication
38
39
  self._setup_communication()
39
40
  # params
@@ -53,9 +54,11 @@ class Communication:
53
54
  """
54
55
  # setup communication based on the method
55
56
  if self.communication_method == 'UART':
56
- self.communicator = UART(port=self.communication_channel_identifier)
57
+ self.communicator = UART(port=self.communication_channel_identifier,baudrate=self.baudrate)
57
58
  elif self.communication_method == 'WiFi':
58
59
  self.communicator = WiFiServer(target_ssid=self.communication_channel_identifier)
60
+ elif self.communication_method == 'None':
61
+ pass
59
62
  else:
60
63
  raise ValueError("Unknown communication method")
61
64
 
@@ -68,11 +71,16 @@ class Communication:
68
71
  send_data[0:1] = package[0].to_bytes(1,byteorder='little')
69
72
 
70
73
  for i in range(len(package)-1):
71
- send_data[i+1:i+2] = int(package[i+1]).to_bytes(1,byteorder='little')
74
+ try:
75
+ send_data[i+1:i+2] = int(package[i+1]).to_bytes(1,byteorder='little',signed=True)
76
+ except OverflowError as e:
77
+ send_data[i+1:i+2] = int(package[i+1]).to_bytes(1,byteorder='little',signed=False)
78
+
72
79
 
73
80
  # set last value to '\n'
74
- send_data[-1:] = '\n'.encode('ascii')
81
+ send_data[-1:] = '\0'.encode('ascii')
75
82
 
83
+ # print(send_data)
76
84
  # return byte array to send
77
85
  return send_data
78
86
 
@@ -80,7 +88,7 @@ class Communication:
80
88
  recv_data = []
81
89
  i = 0
82
90
  while i < 65:
83
- if 17 <= i <= 45: # 16 bit signed integer to int
91
+ if 17 <= i <= 49: # 16 bit signed integer to int
84
92
  recv_data.append(int.from_bytes(package[i:i+2],byteorder='big',signed=True))
85
93
  i+=2
86
94
  else: # 8 bit signed integer to int
@@ -99,13 +107,20 @@ class Communication:
99
107
  """
100
108
  start the communication
101
109
  """
102
- self.communicator.open()
110
+ try:
111
+ self.communicator.open()
112
+ except Exception as e:
113
+ self.logger.error("unable to connect to Robot")
114
+ print(e)
103
115
 
104
116
  def send_data(self, message:list):
105
117
  """
106
118
  send message
107
119
  """
108
120
  try:
121
+ # Test
122
+ self.logger.info(f'data sent to hand {message}')
123
+ print(f'data sent to hand = {message}')
109
124
  byte_msg = self._list_to_byte_encode(message)
110
125
  self.communicator.send(byte_msg)
111
126
  return True
@@ -119,20 +134,33 @@ class Communication:
119
134
  """
120
135
  receive message
121
136
  """
137
+ byte_msg_recv = None
122
138
  try:
123
- byte_msg_recv = self.communicator.receive()
124
- if not byte_msg_recv:
125
- self.logger.warning("No data received")
126
- return None
139
+ while byte_msg_recv is None:
140
+ byte_msg_recv = self.communicator.receive()
141
+ if not byte_msg_recv:
142
+ # self.logger.warning("No data received")
143
+ return None,None
127
144
  ack,message_received = self._byte_to_list_decode(byte_msg_recv)
145
+ # print(ack)
128
146
  except Exception as e:
129
147
  self.logger.warning("unable to receive message")
130
148
  print(e)
131
- return message_received
149
+ return None
150
+ return ack,message_received
151
+
132
152
  def close_connection(self):
133
153
  self.communicator.close()
134
154
 
135
155
 
156
+ def wait_for_ack(self):
157
+ while 1:
158
+ tmp,rc_csum = self.receive_data()
159
+ if tmp is not None:
160
+ return 1
161
+ time.sleep(0.001)
162
+
163
+
136
164
  ##################################################################
137
165
  ############################## TESTS #############################
138
166
  ##################################################################
@@ -141,9 +169,21 @@ def test_wifi():
141
169
  communication.open_connection()
142
170
 
143
171
  def test_uart():
144
- communication = Communication(communication_method='UART', communication_channel_identifier='COM9')
172
+ communication = Communication(communication_method='UART', communication_channel_identifier='/dev/ttyUSB0')
145
173
  communication.open_connection()
146
-
174
+ time.sleep(1)
175
+ x = [0]*33
176
+ x[0] = 210
177
+ while True:
178
+ communication.send_data(x)
179
+ i=0
180
+ while i < 6:
181
+
182
+ # time.sleep(0.002)
183
+ # print(communication.receive_data()[0])
184
+ if communication.receive_data() is not None:
185
+ i+=1
186
+ time.sleep(0.5)
147
187
 
148
188
  if __name__ == "__main__":
149
189
  # test_wifi()
@@ -0,0 +1 @@
1
+ from .firmware_updater import FirmwareUpdater
@@ -0,0 +1,129 @@
1
+ import os
2
+ import time
3
+ import logging
4
+
5
+ BYTES_CHUNK = 32
6
+ UPLOAD_CHUNKS_COMMAND = 0x30
7
+ FINISH_CHUNKS_COMMAND = 0x32
8
+
9
+ class FirmwareUpdater:
10
+
11
+ def __init__(self,
12
+ communication_handler = None,
13
+ command_handler = None,
14
+ file_location = None,
15
+ logger = None
16
+ ):
17
+
18
+ self._communication_handler = communication_handler
19
+ self._command_handler = command_handler
20
+ self.file_location = file_location
21
+
22
+ if not logger:
23
+ self.logger = logging.getLogger(__name__)
24
+ else:
25
+ self.logger = logger
26
+
27
+ def get_bin_file_info(self):
28
+ # get the file location and size for comparison later
29
+ file_size = int(os.path.getsize(self.file_location))
30
+
31
+ print(f'Bin file size = {file_size}')
32
+
33
+ # open file and get data
34
+ return file_size
35
+
36
+
37
+ def update_firmware(self,file_size):
38
+
39
+ time.sleep(0.1)
40
+
41
+ # wait for ACK back before sending data
42
+ self.wait_for_ack()
43
+
44
+ # load File Data
45
+ file = open(self.file_location,'rb')
46
+ file_data = file.read()
47
+ file.close()
48
+
49
+ # number of 32B chunks needed
50
+ chunks_required = int(file_size/BYTES_CHUNK) + 1
51
+ print((f'Num of chunks to send: {chunks_required}'))
52
+
53
+ # send actual binary data - note 32bytes because length of command is 34
54
+ # init counter
55
+ i = 0
56
+ ret = False
57
+ while i < len(file_data):
58
+
59
+ # if not enough file data for 32B, fill with 0xFFs
60
+ if i+BYTES_CHUNK > file_size:
61
+ chunk = list(file_data[i:])
62
+ while len(chunk) < BYTES_CHUNK: # Always make sure 32B of valid data
63
+ chunk.append(0xFF)
64
+
65
+ else:
66
+ chunk = list(file_data[i:i+BYTES_CHUNK])
67
+
68
+
69
+ # checksum last value
70
+ csum = self.calc_check_sum(chunk)
71
+ # set 33rd byte as checksum value
72
+ chunk.append(csum)
73
+
74
+ # print(f'{chunk} {len(chunk)}')
75
+
76
+ # send data
77
+ self._communication_handler.send_data(chunk)
78
+
79
+ # sleep
80
+ time.sleep(0.008)
81
+
82
+ # print([hex(x) for x in chunk])
83
+
84
+ # wait for ack
85
+ ret = self.wait_for_ack()
86
+ # debug print
87
+ # print(f'CHUNKS LEFT {chunks_required} {csum}')
88
+
89
+ if ret:
90
+ chunks_required -= 1
91
+ i += BYTES_CHUNK
92
+ csum = 0
93
+ ret = 0
94
+
95
+
96
+ time.sleep(0.01)
97
+
98
+ print(f'Firmware update in progress..')
99
+
100
+ def calc_check_sum(self,data:list)->int:
101
+ checksum = 0
102
+ for i in data:
103
+ checksum ^= i
104
+ return checksum
105
+
106
+ def wait_for_ack(self):
107
+ while 1:
108
+ tmp,rc_csum = self._communication_handler.receive_data()
109
+ if tmp == 2:
110
+ # print(f'{tmp} {rc_csum[0]}')
111
+ if rc_csum[0] == 1:
112
+ return True
113
+ else:
114
+ self.logger.warn(f'firmware flash checksum error')
115
+ return False
116
+ elif tmp == 9:
117
+ self.logger.error(f'firmware flash failed')
118
+ return False
119
+ time.sleep(0.001)
120
+
121
+
122
+
123
+ def test_firmware_updater():
124
+ my_fp = "/home/ryan/Documents/Artus-3D-actuator-fw-F3/build/actuator_mx_build.bin"
125
+ firmware_updater = FirmwareUpdater(communication_channel_identifier='ArtusLite000',communication_method='WiFi',file_location=my_fp)
126
+ firmware_updater.update_firmware()
127
+
128
+ if __name__ == "__main__":
129
+ test_firmware_updater()
@@ -2,16 +2,16 @@
2
2
  class ArtusLite:
3
3
 
4
4
  def __init__(self,
5
- joint_max_angles=[35, 90, 90, 90, # thumb
6
- 20, 90, 90, # index
7
- 20, 90, 90, # middle
8
- 20, 90, 90, # ring
9
- 20, 90, 90], # pinky
10
- joint_min_angles=[-35, 0, 0, 0, # thumb
11
- -20, 0, 0, # index
12
- -20, 0, 0, # middle
13
- -20, 0, 0, # ring
14
- -20, 0, 0], # pinky
5
+ joint_max_angles=[25, 90, 90, 90, # thumb
6
+ 12, 90, 90, # index
7
+ 12, 90, 90, # middle
8
+ 12, 90, 90, # ring
9
+ 12, 90, 90], # pinky
10
+ joint_min_angles=[-25, 0, 0, 0, # thumb
11
+ -12, 0, 0, # index
12
+ -12, 0, 0, # middle
13
+ -12, 0, 0, # ring
14
+ -12, 0, 0], # pinky
15
15
 
16
16
  joint_default_angles=[0, 0, 0, 0, # thumb
17
17
  0, 0, 0, # index
@@ -59,6 +59,10 @@ class ArtusLite:
59
59
  self.feedback_angle = 0
60
60
  self.feedback_current = 0
61
61
  self.feedback_temperature = temperature
62
+
63
+ def __str__(self):
64
+ return "Index: " + str(self.index)+"Target Angle: " +str(self.target_angle)
65
+
62
66
  self.Joint = Joint
63
67
 
64
68
  self._create_hand()
@@ -85,7 +89,7 @@ class ArtusLite:
85
89
  del self.joint_max_angles
86
90
  del self.joint_min_angles
87
91
  del self.joint_rotation_directions
88
- del self.joint_velocities
92
+ # self.joint_velocities
89
93
  del self.number_of_joints
90
94
 
91
95
  def __str__(self):
@@ -156,8 +160,8 @@ class ArtusLite:
156
160
  if joint_angles[joint.index] > 100:
157
161
  joint_angles[joint.index] = 100
158
162
  # TODO logging
159
- if joint_angles[joint.index] < 60:
160
- joint_angles[joint.index] = 60
163
+ if joint_angles[joint.index] < 0:
164
+ joint_angles[joint.index] = 0
161
165
  # TODO logging
162
166
  return joint_angles
163
167
 
@@ -166,19 +170,21 @@ class ArtusLite:
166
170
  Set the hand to the home position at default velocity
167
171
  """
168
172
  # create new target dictionary with default velocity and default angle
169
- joint_angles = {key: {'target_angle':value.default_angle,'velocity':self.joint_velocities[value.index]} for key,value in self.hand_joints.items()}
170
-
171
- return self.set_joint_angles_by_name(joint_angles)
173
+
174
+ joint_angles = {key: {'index': value.index, 'target_angle':value.default_angle,'velocity':self.joint_velocities[value.index]} for key,value in self.hand_joints.items()}
175
+ print(self.hand_joints['thumb_spread'])
176
+ return self.set_joint_angles(joint_angles)
172
177
 
173
178
  def get_joint_angles(self, feedback_package:list):
174
179
  """
175
180
  Get the joint angles and feedback list data
176
181
  and populate the feedback fields in the hand_joints dictionary
177
182
  """
183
+ print(f'FB PACKAGE = {feedback_package}')
178
184
  for name,joint_data in self.hand_joints.items():
179
- joint_data.feedback_angle = feedback_package[joint_data.index]
180
- joint_data.feedback_current = feedback_package[joint_data.index+16]
181
- joint_data.feedback_temperature = feedback_package[joint_data.index+32]
185
+ joint_data.feedback_angle = feedback_package[1][joint_data.index]
186
+ joint_data.feedback_current = feedback_package[1][joint_data.index+15]
187
+ joint_data.feedback_temperature = feedback_package[1][joint_data.index+31]
182
188
 
183
189
  return feedback_package
184
190
 
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.1
2
+ Name: ArtusAPI
3
+ Version: 1.0.0
4
+ Summary: API to control Artus Family of Robots by Sarcomere Dynamics Inc
5
+ Home-page: UNKNOWN
6
+ Author: Sarcomere Dynamics Inc.
7
+ License: UNKNOWN
8
+ Platform: UNKNOWN
9
+
10
+ UNKNOWN
11
+
@@ -14,6 +14,8 @@ ArtusAPI/communication/UART/__init__.py
14
14
  ArtusAPI/communication/UART/uart.py
15
15
  ArtusAPI/communication/WiFi/__init__.py
16
16
  ArtusAPI/communication/WiFi/wifi_server.py
17
+ ArtusAPI/firmware_update/__init__.py
18
+ ArtusAPI/firmware_update/firmware_updater.py
17
19
  ArtusAPI/robot/__init__.py
18
20
  ArtusAPI/robot/robot.py
19
21
  ArtusAPI/robot/artus_lite/__init__.py
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.1
2
+ Name: ArtusAPI
3
+ Version: 1.0.0
4
+ Summary: API to control Artus Family of Robots by Sarcomere Dynamics Inc
5
+ Home-page: UNKNOWN
6
+ Author: Sarcomere Dynamics Inc.
7
+ License: UNKNOWN
8
+ Platform: UNKNOWN
9
+
10
+ UNKNOWN
11
+
@@ -0,0 +1,145 @@
1
+ <img src='data/images/SarcomereLogoHorizontal.svg'>
2
+
3
+ # Python Artus Robotic Hand API
4
+ This repository contains a Python API for controlling the Artus robotic hands by Sarcomere Dynamics Inc.
5
+
6
+ Please contact the team if there are any issues that arise through the use of the API.
7
+
8
+ ## Table of Contents
9
+ * [Getting Started](#getting-started)
10
+ * [Video Introduction](#video-introduction)
11
+ * [Requirements](#requirements)
12
+ * [USB Driver](#usb-driver)
13
+ * [Installation](#installation)
14
+ * [Usage](#usage)
15
+ * [Running example.py](#running-examplepy)
16
+ * [Creating an ArtusAPI Class Object](#creating-an-artusapi-class-object)
17
+ * [Serial Example](#serial-example)
18
+ * [Normal Startup Procedure](#normal-startup-procedure)
19
+ * [Interacting with the API](#interacting-with-the-api)
20
+ * [Setting Joints](#setting-joints)
21
+ * [Getting Feedback](#getting-feedback)
22
+ * [Directory Structure](#directory-structure)
23
+
24
+ ## Getting Started
25
+ ### Video Introduction
26
+ [![Getting Started Video](/data/images/thumbnail.png)](https://www.youtube.com/watch?v=30BkuA0EkP4)
27
+
28
+ ### Requirements
29
+ Requires Python version >= 3.10 installed on the host system. Please visit the [Python website](https://www.python.org/downloads/) to install Python.
30
+
31
+ #### USB Driver
32
+ If the host system cannot find the Artus Lite as a USB device once it is connected over USBC, go to [FTDI Driver Download](https://ftdichip.com/drivers/vcp-drivers/) to install the virtual COM port driver (usually only required for Windows).
33
+
34
+ ### Installation
35
+ Using pip:
36
+ ```bash
37
+ pip install psutil
38
+ pip install pyserial
39
+ pip install ArtusAPI
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ### Running example.py
45
+ Before running the example script, determine whether your Artus Lite is running USB Serial or WiFi, and edit the following line with the name of the port over UART or target SSID for WiFi
46
+
47
+ * On Windows, find the port name by navigating to "Device Manager">"Ports". It should show up as a COM port. (e.g. COM3)
48
+ * On Linux, use the command `dmesg | grep ttyUSB` to find the usb device. (e.g. /dev/ttyUSB1)
49
+ * If a permission error is encountered, use the command `sudo chmod 777 /dev/ttyUSB1`
50
+
51
+ ```python
52
+ artusapi = ArtusAPI(communication_method='UART',hand_type='right',communication_channel_identifier='/dev/ttyUSB1')
53
+ ```
54
+
55
+ ### Creating an ArtusAPI Class Object
56
+ Below are some examples of instantiating the ArtusAPI class to control a single hand. Below is a description of the parameters and what they mean.
57
+
58
+ * `__communication_method__` : The communication method between the host system and the Artus hand
59
+ * `__communication_channel_identifier__` : The identifying parameter of the communication method such as COM port over Serial or network name over WiFi
60
+ * `__robot_type__` : The Artus robot hand name
61
+ * `__hand_type__` : left or right hand
62
+ * `__stream__` : whether streaming feedback data is required or not. Default: `False`
63
+ * `__communication_frequency__` : The frequency of the feedback and command communication. Default: `400` Hz
64
+ * `__logger__` : If integrating the API into control code, you may already have a logger. THis will allow for homogeneous logging to the same files as what you currently have. Default: `None`
65
+ * `__reset_on_start__` : If the hand is not in a closed state when last powered off, setting to `1` will open the hand before ready to receive commands. This _MUST_ be set if powered off in a closed state, or a calibrate must be run before sending target commands
66
+ * `__baudrate__` : required to differentiate between Serial over USB-C and Serial over RS485, default `921600` for SUBC, `115200` for RS485
67
+
68
+ #### Serial Example
69
+ ```python
70
+ from ArtusAPI.artus_api import ArtusAPI
71
+ artus_lite = ArtusAPI(robot_type='artus_lite', communication_type='UART',hand_type='right',communication_channel_identifier='COM7')
72
+
73
+ artus_lite.connect()
74
+ ```
75
+
76
+ ### Normal Startup Procedure
77
+ There is a standard series of commands that need to be followed before sending target commands or receiving feedback data is possible.
78
+
79
+ Before any software, ensure that the power connector is secured and connected to the Artus hand and if using a wired connection (Serial or CANbus), ensure the connection/cable is good.
80
+
81
+ First, to create a communication connection between the API and the Artus hand, `ArtusAPI.connect()` must be run to confirm communication is open on the selected communication type.
82
+
83
+ Second, the `ArtusAPI.wake_up()` function must be run to allow the hand to load it's necessary configurations.
84
+
85
+ Once these two steps are complete, optionally, you can run `ArtusAPI.calibrate()` to calibrate the finger joints. Otherwise, the system is now ready to start sending and receiving data!
86
+
87
+ ## Interacting with the API
88
+ To get the most out of the Artus hands, the functions that will likely be most interacted with are `set_joint_angles(self, joint_angles:dict)` and `get_joint_angles(self)`. The `set_joint_angles` function allows the user to set 16 independent joint values with a desired velocity/force value in the form of a dictionary. See the [grasp_close file](data/hand_poses/grasp_close.json) for an example of a full 16 joint dictionary for the Artus Lite. See the [Artus Lite README](ArtusAPI/robot/artus_lite/README.md) for joint mapping.
89
+
90
+ ### Setting Joints
91
+ As mentioned above, there are 16 independent degrees of freedom for the Artus Lite, which can be set simultaneously or independently. If, for example, a user need only curl the pinky, a shorter dictionary like the following could be used as a parameter to the function:
92
+ ```
93
+ pinky_dict = {"pinky_flex" :
94
+ {
95
+ "index": 14,
96
+ "input_angle" : 90
97
+ },
98
+ "pinky_d2" :
99
+ {
100
+ "index":15,
101
+ "input_angle" : 90
102
+ }
103
+ }
104
+
105
+ ArtusAPI.set_joint_angles(pinky_dict)
106
+ ```
107
+
108
+ Notice that the above example does not include the `"input_speed"` field that the json file has. The `"input_speed"` field is optional and will default to the nominal speed.
109
+
110
+ ### Getting Feedback
111
+ There are two ways to get feedback data depending on how the class is instantiated.
112
+
113
+ 1. In streaming mode (`stream = True`), after sending the `wake_up()` command, the system will start streaming feedback data which will populate the `ArtusAPI._robot_handler.robot.hand_joints` dictionary. Fields that hold feedback data are named with `feedback_X` where _X_ could be angle, current or temperature.
114
+ 2. In Request mode (`stream = False`), sending a `get_joint_angles()` command will request the feedback data before anything is sent from the Artus hand. This communication setting is slower than the streaming mode, but for testing purposes and getting familiar with the Artus hand, we recommend starting with this setting.
115
+
116
+
117
+ ## Directory Structure
118
+ ```bash
119
+ ├── ArtusAPI
120
+ │   ├── commnands
121
+ │   │   ├── commands.py # Command strings for the Robot Hand
122
+ │   ├── communication
123
+ │   │   ├── WiFi
124
+ │   │   │   ├── WiFi.py # WiFi communication class
125
+ │   │   ├── UART
126
+ │   │   │   ├── UART.py # UART communication class
127
+ │   │   ├── communication.py # Communication class for the API
128
+ │   ├── robot
129
+ │   │   ├── artus_lite
130
+ │   │   │   ├── artus_lite.py # Artus Lite Hand class
131
+ │   │   ├── robot.py # Robot Hand class for the API
132
+ │   ├── artus_api.py # API Core
133
+
134
+ ├── data
135
+ │   ├── grasp_poses
136
+ │   ├── images
137
+
138
+ ├── examples
139
+ │   ├── example.py # Example usage of the API
140
+ ```
141
+
142
+ ## API Core
143
+ ```python
144
+ class ArtusAPI()
145
+ ```
@@ -2,10 +2,11 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='ArtusAPI',
5
- version='0.5.0',
6
- description='API to control Artus Family of Robots',
5
+ version='1.0.0',
6
+ description='API to control Artus Family of Robots by Sarcomere Dynamics Inc',
7
7
  # package_dir={'': '/'}, # tells setuptools that your packages are under src
8
- packages=find_packages(exclude=['data*', 'examples*', 'tests*','venv*'])
8
+ packages=find_packages(exclude=['data*', 'examples*', 'tests*','venv*']),
9
+ author='Sarcomere Dynamics Inc.'
9
10
  # packages=find_packages(where='/'),
10
11
  # other setup configurations
11
12
  )
@@ -1,83 +0,0 @@
1
- import serial
2
- import logging
3
- import time
4
-
5
- class UART:
6
- def __init__(self,
7
- port='COM9',
8
- baudrate=115200, #115200,
9
- timeout=0.5,
10
- logger = None):
11
-
12
- # automatically connect to the first available port
13
- self.port = port
14
- self.baudrate = baudrate
15
- self.timeout = timeout
16
-
17
- self.esp32 = serial.Serial(baudrate=self.baudrate, timeout= self.timeout)
18
-
19
- # required delays for sending message
20
- self.timer_send = 0.003
21
- self.timer_recv = self.timer_send*2
22
- self.maximum_freq = 700 # hz
23
-
24
- if not logger:
25
- self.logger = logging.getLogger(__name__)
26
- else:
27
- self.logger = logger
28
-
29
- def open(self):
30
- self.esp32.port=self.port
31
- self.esp32.close()
32
- self.esp32.open()
33
- self.logger.info(f"Opening {self.port} @ {self.baudrate} baudrate")
34
-
35
- def send(self, data:bytearray):
36
- self.esp32.write(data)
37
-
38
- # required delay
39
- t = time.perf_counter()
40
- while time.perf_counter() - t < self.timer_send:
41
- pass
42
-
43
- def receive(self):
44
-
45
- # required delay
46
- t = time.perf_counter()
47
- while time.perf_counter() - t < self.timer_recv:
48
- pass
49
-
50
- # check data
51
- if self.esp32.in_waiting == 65:
52
- msg_bytes = self.esp32.read(65)
53
- return msg_bytes
54
- elif self.esp32.in_waiting > 0: # clear buffer if not correct amount of data
55
- msg_bytes = self.esp32.read_all()
56
- self.logger.warning(f"Incorrect amount of data:{len(msg_bytes)} - clearing buffer")
57
- return None
58
- else: # non blocking
59
- return None
60
-
61
- def close(self):
62
- self.esp32.close()
63
-
64
-
65
- def test_serial_receive():
66
- esp32_communication = UART()
67
- esp32_communication.start()
68
- while True:
69
- msg = esp32_communication.receive()
70
- if msg != "":
71
- print(msg)
72
-
73
- def test_serial_send():
74
- esp32_communication = UART()
75
- esp32_communication.start()
76
- while True:
77
- esp32_communication.send("hello\n")
78
- time.sleep(1)
79
-
80
-
81
- if __name__ == "__main__":
82
- test_serial_receive()
83
- # test_serial_send()
@@ -1,4 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: ArtusAPI
3
- Version: 0.5.0
4
- Summary: API to control Artus Family of Robots
ArtusAPI-0.5.0/PKG-INFO DELETED
@@ -1,4 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: ArtusAPI
3
- Version: 0.5.0
4
- Summary: API to control Artus Family of Robots
ArtusAPI-0.5.0/README.md DELETED
@@ -1,34 +0,0 @@
1
- # Python Artus Robotic Hand API
2
- This repository contains a Python API for controlling the Artus robotic hands.
3
-
4
- ## Directory Structure
5
- ```bash
6
- ├── ArtusAPI
7
- │   ├── commnands
8
- │   │   ├── commands.py # Command strings for the Robot Hand
9
- │   ├── communication
10
- │   │   ├── WiFi
11
- │   │   │   ├── WiFi.py # WiFi communication class
12
- │   │   ├── UART
13
- │   │   │   ├── UART.py # UART communication class
14
- │   │   ├── communication.py # Communication class for the API
15
- │   ├── robot
16
- │   │   ├── artus_3d
17
- │   │   │   ├── artus_3d.py # Artus 3D Hand class
18
- │   │   ├── artus_lite
19
- │   │   │   ├── artus_lite.py # Artus Lite Hand class
20
- │   │   ├── robot.py # Robot Hand class for the API
21
- │   ├── artus_api.py # API Core
22
-
23
- ├── data
24
- │   ├── grasp_poses
25
- │   ├── images
26
-
27
- ├── examples
28
- │   ├── example.py # Example usage of the API
29
- ```
30
-
31
- ## API Core
32
- ```python
33
- class ArtusAPI()
34
- ```
File without changes
File without changes
File without changes