ArtusAPI 1.1.2__tar.gz → 1.3__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 (37) hide show
  1. ArtusAPI-1.3/ArtusAPI/__init__.py +1 -0
  2. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/artus_api.py +244 -34
  3. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/communication/UART/uart.py +4 -4
  4. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/communication/WiFi/wifi_server.py +3 -3
  5. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/communication/communication.py +50 -15
  6. ArtusAPI-1.3/ArtusAPI/robot/artus_lite/__init__.py +5 -0
  7. ArtusAPI-1.3/ArtusAPI/robot/artus_lite/artus_lite_plus.py +63 -0
  8. ArtusAPI-1.3/ArtusAPI/robot/artus_lite/artus_lite_plus_right.py +10 -0
  9. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/robot/robot.py +9 -0
  10. ArtusAPI-1.3/ArtusAPI/sensors/ForceSensor.py +12 -0
  11. ArtusAPI-1.3/ArtusAPI/sensors/__init__.py +1 -0
  12. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI.egg-info/PKG-INFO +3 -2
  13. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI.egg-info/SOURCES.txt +6 -1
  14. ArtusAPI-1.3/ArtusAPI.egg-info/entry_points.txt +3 -0
  15. ArtusAPI-1.3/ArtusAPI.egg-info/requires.txt +6 -0
  16. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/PKG-INFO +3 -2
  17. ArtusAPI-1.3/README.md +176 -0
  18. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/setup.py +14 -6
  19. ArtusAPI-1.1.2/ArtusAPI/__init__.py +0 -0
  20. ArtusAPI-1.1.2/ArtusAPI/robot/artus_lite/__init__.py +0 -3
  21. ArtusAPI-1.1.2/ArtusAPI.egg-info/requires.txt +0 -5
  22. ArtusAPI-1.1.2/README.md +0 -277
  23. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/commands/__init__.py +0 -0
  24. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/commands/commands.py +0 -0
  25. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/communication/UART/__init__.py +0 -0
  26. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/communication/WiFi/__init__.py +0 -0
  27. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/communication/__init__.py +0 -0
  28. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/firmware_update/__init__.py +0 -0
  29. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/firmware_update/firmware_updater.py +0 -0
  30. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/firmware_update/run_full_firmware_update.py +0 -0
  31. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/robot/__init__.py +0 -0
  32. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/robot/artus_lite/artus_lite.py +0 -0
  33. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/robot/artus_lite/artus_lite_left.py +0 -0
  34. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI/robot/artus_lite/artus_lite_right.py +0 -0
  35. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI.egg-info/dependency_links.txt +0 -0
  36. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/ArtusAPI.egg-info/top_level.txt +0 -0
  37. {ArtusAPI-1.1.2 → ArtusAPI-1.3}/setup.cfg +0 -0
@@ -0,0 +1 @@
1
+ from .artus_api import ArtusAPI, main_flash
@@ -37,15 +37,17 @@ class ArtusAPI:
37
37
  robot_type='artus_lite',
38
38
  hand_type ='left',
39
39
  stream = False,
40
- communication_frequency = 200, # hz
40
+ communication_frequency = 50, # hz
41
41
  logger = None,
42
42
  reset_on_start = 0,
43
43
  baudrate = 921600,
44
44
  awake = False
45
45
  ):
46
46
  """
47
- ArtusAPI class controls the communication and control of between a system and an Artus Hand by Sarcomere Dynamics Inc.
47
+ ArtusAPI class controls the communication and control of between a system and an Artus Hand by Sarcomere Dynamics Inc. This file contains the high-level calls that
48
+ are used to control the hand. The low-level calls are separated by robot, command and communication classes.
48
49
  :communication_method: communication method that is supported on the Artus Hand, see Robot folder for supported methods. Default is UART over USBC
50
+ - UART (USBC or RS485), CAN
49
51
  :communication_channel_identifier: channel identifier for the communication method. Usually a COM Port
50
52
  :robot_type: name of the series of robot hand. See Robot folder for list of robots
51
53
  :hand_type: left or right
@@ -53,12 +55,12 @@ class ArtusAPI:
53
55
  :communication_frequency: maximum frequency to stream data to the device and feedback data from the device
54
56
  :logger: python logger settings to inherit
55
57
  :reset_on_start: If hand is powered off in a non-opened state, or software is stopped in a non-opened state, this value should be set to `1` to reduce risk of jamming. May require a calibration.
56
- :baudrate: Required for difference between serial over USBC (921600) and serial over RS485 (115200)
58
+ :baudrate: Required for difference between serial over USBC (921600) and serial over RS485 (115200) when connected to a UR arm
57
59
  :awake: False by default - if the hand is already in a ready state (LED is green) when starting or restarting a control script, set awake to `True` to bypass resending the `wake_up` function. Sending the `wake_up` function when the hand IS NOT in an open state will cause it to lose calibration
58
60
  """
59
61
 
60
62
  self._communication_handler = Communication(communication_method=communication_method,
61
- communication_channel_identifier=communication_channel_identifier,baudrate=baudrate)
63
+ communication_channel_identifier=communication_channel_identifier,baudrate=baudrate,robot_type=robot_type)
62
64
  self._command_handler = Commands(reset_on_start=reset_on_start)
63
65
  self._robot_handler = Robot(robot_type = robot_type,
64
66
  hand_type = hand_type)
@@ -81,7 +83,7 @@ class ArtusAPI:
81
83
  # communication setup
82
84
  def connect(self):
83
85
  """
84
- Open a connection to the Artus Hand
86
+ Open a connection to the Artus Hand and send a wake command to initiate communication
85
87
  """
86
88
  self._communication_handler.open_connection()
87
89
 
@@ -100,7 +102,7 @@ class ArtusAPI:
100
102
  # robot states
101
103
  def wake_up(self):
102
104
  """
103
- Wake-up the Artus Hand
105
+ Wake-up the Artus Hand by sending an initialization command to the hand
104
106
  """
105
107
  print(f"communication period = {self._communication_period_ms} ms")
106
108
  robot_wake_up_command = self._command_handler.get_robot_start_command(self.stream,int(self._communication_period_ms)) # to ms for masterboard
@@ -113,19 +115,12 @@ class ArtusAPI:
113
115
  self.logger.warning(f'Error in calibration')
114
116
  self.awake = True
115
117
 
116
- # get current position of the hand and set the last target positions to this value
117
- # while True:
118
- # joint_angles = self.get_joint_angles()
119
- # time.sleep(1)
120
- # if joint_angles is not None:
121
- # break
122
-
123
- # for joint,data in self._robot_handler.robot.hand_joints.items():
124
- # data.target_angle = data.feedback_angle
125
-
126
118
  def sleep(self):
127
119
  """
128
- Sleep the Artus Hand
120
+ Put the Artus Hand to sleep by sending a sleep command to the hand which
121
+ initiates a shutdown sequence. This command will tell the hand to save it's current
122
+ positions to non-volatile memory and shut down the motors. The LED will turn yellow and
123
+ now be able to be powered off.
129
124
  """
130
125
  robot_sleep_command = self._command_handler.get_sleep_command()
131
126
  return self._communication_handler.send_data(robot_sleep_command)
@@ -133,7 +128,12 @@ class ArtusAPI:
133
128
  def calibrate(self,joint=0,calibration_type=0):
134
129
  """
135
130
  Calibrate the Artus Hand
136
- :joint: joint to calibrate, 0 for all joints
131
+
132
+ Parameters:
133
+ joint (int): Joint to calibrate. 0 for all joints, 1-16 for specific joints mapping to joint map
134
+ calibration_type (int): Type of calibration.
135
+ 0 for a soft reset (i.e. fingers will go to open endstop)
136
+ 1 for a hard reset, finding both open and close endstops
137
137
  """
138
138
  if not self.awake:
139
139
  self.logger.warning(f'Hand not ready, send `wake_up` command')
@@ -154,7 +154,9 @@ class ArtusAPI:
154
154
  def set_joint_angles(self, joint_angles:dict):
155
155
  """
156
156
  Set joint angle targets and speed values to the Artus Hand
157
- :joint_angles: dictionary of input angles and input speeds
157
+
158
+ Parameters:
159
+ :joint_angles: dictionary of input angles and input speeds. See the grasps in the hand_data folder for accepted structure
158
160
  """
159
161
  if not self.awake:
160
162
  self.logger.warning(f'Hand not ready, send `wake_up` command')
@@ -168,17 +170,24 @@ class ArtusAPI:
168
170
 
169
171
  def set_zero_manual_calibration(self):
170
172
  """
171
- Set the zero position of the joints used in internal calibration
173
+ Set the zero position of the joints used in manual calibration
174
+ This is important to have the fingers look centered in an open/neutral position as we are working
175
+ on the calibration process
176
+
177
+ The hand will need to be power cycled after this function is called to take effect
172
178
  """
173
179
  if not self.awake:
174
180
  self.logger.warning(f'Hand not ready, send `wake_up` command')
175
181
  return
176
182
  robot_set_zero_command = self._command_handler.get_set_zero_command()
177
183
  self._communication_handler.send_data(robot_set_zero_command)
184
+
185
+ time.sleep(1)
186
+
178
187
 
179
188
  def set_home_position(self):
180
189
  """
181
- sends the joints to home positions (0) which opens the Artus Hand
190
+ sends the joints to home positions (0) which opens all the joints of the Artus Hand
182
191
  """
183
192
  if not self.awake:
184
193
  self.logger.warning(f'Hand not ready, send `wake_up` command')
@@ -193,7 +202,15 @@ class ArtusAPI:
193
202
 
194
203
  def _check_communication_frequency(self,last_command_time):
195
204
  """
196
- check if the communication frequency is too high
205
+ checks if the time between the last command and the current command is less than the communication period
206
+ Necessary so that the messages stay in sync
207
+
208
+ Parameters:
209
+ :last_command_time: time of the last command
210
+
211
+ Returns:
212
+ :True if the time between the last command and the current command is greater than the communication period
213
+ :False if the time between the last command and the current command is less than the communication period
197
214
  """
198
215
  current_time = time.perf_counter()
199
216
  if current_time - last_command_time < self._communication_period:
@@ -206,6 +223,9 @@ class ArtusAPI:
206
223
  def _receive_feedback(self):
207
224
  """
208
225
  Send a request for feedback data and receive feedback data
226
+
227
+ Returns:
228
+ :feedback_command: feedback data list from the hand
209
229
  """
210
230
  if not self.awake:
211
231
  self.logger.warning(f'Hand not ready, send `wake_up` command')
@@ -220,6 +240,13 @@ class ArtusAPI:
220
240
  def get_joint_angles(self):
221
241
  """
222
242
  Populate feedback fields in self._robot_handler.hand_joints dict
243
+
244
+ Returns:
245
+ :tuple: (ack, angles, velocities, temperatures)
246
+ ack: acknowledgement from the hand
247
+ angles: list of joint angles
248
+ velocities: list of joint velocities
249
+ temperatures: list of joint temperatures
223
250
  """
224
251
  if not self.awake:
225
252
  self.logger.warning(f'Hand not ready, send `wake_up` command')
@@ -229,17 +256,31 @@ class ArtusAPI:
229
256
  joint_angles = self._robot_handler.get_joint_angles(feedback_command)
230
257
  if joint_angles is None:
231
258
  return None
232
- # separate joint angles into 3 lists
259
+
233
260
  angles = joint_angles[1][0:16]
234
- velocities = joint_angles[1][16:32]
235
- temperatures = joint_angles[1][32:48]
236
- # print(joint_angles)
237
- return joint_angles[0],angles,velocities,temperatures
261
+
262
+ if self._robot_handler.robot_type == 'artus_lite':
263
+ # separate joint angles into 3 lists
264
+ velocities = joint_angles[1][16:32]
265
+ temperatures = joint_angles[1][32:48]
266
+ # print(joint_angles)
267
+ return joint_angles[0],angles,velocities,temperatures
268
+
269
+ elif self._robot_handler.robot_type == 'artus_lite_plus':
270
+ # separate into lists and concat decimals
271
+ # angles = joint_angles[1][0:16]
272
+ forces = [round(force, 4) for force in joint_angles[1][16:]]
273
+ return joint_angles[0],angles,forces
238
274
 
239
275
  # robot feedback stream
240
276
  def get_streamed_joint_angles(self):
241
277
  """
242
- Populate feedback fields in self._robot_handler.hand_joints dict
278
+ Populate feedback fields in self._robot_handler.hand_joints dict without sending a request for feedback data
279
+ This is used for real-time streaming of data for the Artus Hand
280
+ Returns:
281
+ :tuple: (ack, feedback list)
282
+ ack: acknowledgement from the hand
283
+ feedback list: list of joint angles, velocities, and temperatures
243
284
  """
244
285
  if not self.awake:
245
286
  self.logger.warning(f'Hand not ready, send `wake_up` command')
@@ -257,7 +298,15 @@ class ArtusAPI:
257
298
 
258
299
  def update_firmware(self,upload_flag='y',file_location=None,drivers_to_flash=0):
259
300
  """
260
- send firmware update to the actuators
301
+ send a firmware update to the actuators
302
+
303
+ Parameters:
304
+ :upload_flag: whether to upload a new firmware file or not. Default is 'y'
305
+ :file_location: location of the firmware file. Default is None
306
+ :drivers_to_flash: which drivers to flash. Default is 0 (all motor drivers)
307
+ 0 - all motor drivers
308
+ 1-8 - specific motor driver
309
+ 9 - peripheral controller
261
310
  """
262
311
  file_path = None
263
312
  fw_size = 0
@@ -311,12 +360,18 @@ class ArtusAPI:
311
360
  def update_firmware_single_driver(self,actuator_number,fw_size,upload):
312
361
  """
313
362
  update firmware for a single driver
363
+
364
+ Parameters:
365
+ :actuator_number: which actuator to update
366
+ :fw_size: size of the firmware file
367
+ :upload: whether to upload a new firmware file or not
314
368
  """
315
369
  self._communication_handler.send_data(self._command_handler.get_firmware_command(fw_size,upload,actuator_number))
316
370
 
317
371
  def request_joint_and_motor(self):
318
372
  """
319
- request joint and motor from user
373
+ user facing request for joint and motor used in reset and hard close functions
374
+ :return: joint and motor number
320
375
  """
321
376
  j,m = None,None
322
377
  while True:
@@ -336,7 +391,11 @@ class ArtusAPI:
336
391
 
337
392
  def reset(self,j=None,m=None):
338
393
  """
339
- Reset a joint back to it's open state, used if finger is "jammed" in close state
394
+ Pulse the motor open, used if finger is "jammed" in close state
395
+
396
+ Parameters:
397
+ :j: joint number to reset
398
+ :m: motor number to reset
340
399
  """
341
400
  if not self.awake:
342
401
  self.logger.warning(f'Hand not ready, send `wake_up` command')
@@ -349,7 +408,11 @@ class ArtusAPI:
349
408
 
350
409
  def hard_close(self,j=None,m=None):
351
410
  """
352
- drive a joint partially closed - used if finger is "jammed" in open state
411
+ Pulse the motor open - used if finger is "jammed" in open state
412
+
413
+ Parameters:
414
+ :j: joint number to reset
415
+ :m: motor number to reset
353
416
  """
354
417
  if not self.awake:
355
418
  self.logger.warning(f'Hand not ready, send `wake_up` command')
@@ -362,7 +425,9 @@ class ArtusAPI:
362
425
 
363
426
  def update_param(self):
364
427
  """
365
- Parameter update, used to change the communication method
428
+ Parameter update, used to change the communication method which must be within the available options.
429
+ Hand will require a power cycle to take effect
430
+ :return: None
366
431
  """
367
432
  com = None
368
433
  while com not in ['UART','CAN','RS485']:
@@ -385,7 +450,10 @@ class ArtusAPI:
385
450
  def save_grasp_onhand(self,index=1):
386
451
  """
387
452
  function to save a grasp on the Artus Hand in non-volatile memory to be called.
388
- Defeault index is 1, value can be 1-6
453
+ Uses the last set joint angles and velocities to save the grasp that are in the robot.hand_joints dict
454
+
455
+ Parameters:
456
+ Default index is 1, value can be 1-6
389
457
  """
390
458
  command = [0]*32
391
459
  for joint,data in self._robot_handler.robot.hand_joints.items():
@@ -430,6 +498,7 @@ class ArtusAPI:
430
498
  def wipe_sd(self):
431
499
  """
432
500
  wipe sd card and reset with factory default settings
501
+ Requires a power cycle to take effect
433
502
  """
434
503
  self._communication_handler.send_data(self._command_handler.get_wipe_sd_command())
435
504
  feedback = None
@@ -446,5 +515,146 @@ def test_artus_api():
446
515
  time.sleep(2)
447
516
  artus_api.disconnect()
448
517
 
518
+ # script entry points
519
+
520
+ def main_flash():
521
+ # import specific to the cli entry point
522
+ import argparse
523
+ import requests
524
+ import os
525
+ import json
526
+ import base64
527
+ import esptool
528
+
529
+ bin_paths = {
530
+ "actuator_64": "https://gist.githubusercontent.com/SDRyanLee/ad8bbe17164c74e6417d1e2d4d0843d2/raw/actuator_64.txt",
531
+ "peripheral_64": "https://gist.githubusercontent.com/SDRyanLee/ad8bbe17164c74e6417d1e2d4d0843d2/raw/peripheral_64.txt",
532
+ "peripheral_plus_64": "https://gist.githubusercontent.com/SDRyanLee/ad8bbe17164c74e6417d1e2d4d0843d2/raw/peripheral_plus_64.txt",
533
+ "master_64": "https://gist.githubusercontent.com/SDRyanLee/ad8bbe17164c74e6417d1e2d4d0843d2/raw/master_64.txt",
534
+ "master_plus_64": "https://gist.githubusercontent.com/SDRyanLee/ad8bbe17164c74e6417d1e2d4d0843d2/raw/master_plus_64.txt",
535
+ "master_bootapp0_64": "https://gist.githubusercontent.com/SDRyanLee/ad8bbe17164c74e6417d1e2d4d0843d2/raw/master_bootapp0_64.txt",
536
+ "master_partitions_64": "https://gist.githubusercontent.com/SDRyanLee/ad8bbe17164c74e6417d1e2d4d0843d2/raw/master_partitions_64.txt",
537
+ "master_bootloader_64": "https://gist.githubusercontent.com/SDRyanLee/ad8bbe17164c74e6417d1e2d4d0843d2/raw/master_bootloader_64.txt"
538
+ }
539
+
540
+ parser = argparse.ArgumentParser(
541
+ description="Artus API CLI Tool"
542
+ )
543
+
544
+ # add required arguments
545
+ parser.add_argument('-p','--port',required=True,help="required com port (COMx) or (/dev/ttyUSBx)")
546
+ parser.add_argument('-r','--robot',default='artus_lite',help="Robot type",choices=['artus_lite','artus_lite_plus'])
547
+ parser.add_argument('-s','--side',default='right',choices=['left','right'],help='specify hand side, left or right')
548
+
549
+ args = parser.parse_args()
550
+
551
+ type_flash = None
552
+ driver_to_flash = None
553
+ bootapp_path = None
554
+ partitions_path = None
555
+ bootloader_path = None
556
+ file_location = None
557
+
558
+ # get type of flash
559
+ while type_flash not in ['actuator','peripheral','master']:
560
+ type_flash = input('Enter subsystem to flash (actuator, peripheral, master): ')
561
+
562
+ if type_flash == 'actuator':
563
+ file_location = bin_paths['actuator_64']
564
+ driver_to_flash = 0
565
+ elif type_flash == 'peripheral':
566
+ if args.robot == 'artus_lite':
567
+ file_location = bin_paths['peripheral_64']
568
+ elif args.robot == 'artus_lite_plus':
569
+ file_location = bin_paths['peripheral_plus_64']
570
+ driver_to_flash = 9
571
+ elif type_flash == 'master':
572
+ if args.robot == 'artus_lite':
573
+ file_location = bin_paths['master_64']
574
+ elif args.robot == 'artus_lite_plus':
575
+ file_location = bin_paths['master_plus_64']
576
+
577
+ bootapp_path = bin_paths['master_bootapp0_64']
578
+ partitions_path = bin_paths['master_partitions_64']
579
+ bootloader_path = bin_paths['master_bootloader_64']
580
+
581
+ # write files
582
+ # Download and decode base64 firmware file
583
+ response = requests.get(file_location)
584
+ decoded_firmware = base64.b64decode(response.text)
585
+
586
+ # Write decoded firmware to flash.bin
587
+ with open('flash.bin', 'wb') as f:
588
+ f.write(decoded_firmware)
589
+
590
+ # For master firmware, also download and decode bootloader files
591
+ if type_flash == 'master':
592
+ # Download and decode bootapp
593
+ response = requests.get(bootapp_path)
594
+ decoded_bootapp = base64.b64decode(response.text)
595
+ with open('bootapp0.bin', 'wb') as f:
596
+ f.write(decoded_bootapp)
597
+
598
+ # Download and decode partitions
599
+ response = requests.get(partitions_path)
600
+ decoded_partitions = base64.b64decode(response.text)
601
+ with open('partitions.bin', 'wb') as f:
602
+ f.write(decoded_partitions)
603
+
604
+ # Download and decode bootloader
605
+ response = requests.get(bootloader_path)
606
+ decoded_bootloader = base64.b64decode(response.text)
607
+ with open('bootloader.bin', 'wb') as f:
608
+ f.write(decoded_bootloader)
609
+
610
+
611
+ # flash through api
612
+ if type_flash != 'master':
613
+ myrobot = ArtusAPI(robot_type=args.robot, hand_type=args.side, communication_channel_identifier=args.port)
614
+ myrobot.connect()
615
+ print('Connected to robot')
616
+
617
+ file_location = 'flash.bin'
618
+ myrobot.update_firmware(upload_flag='y',file_location=file_location,drivers_to_flash=driver_to_flash)
619
+
620
+ myrobot.disconnect()
621
+ print('Disconnected from robot')
622
+
623
+ else:
624
+
625
+ # Build esptool command arguments
626
+ cmd_args = [
627
+ '--chip', 'esp32s3',
628
+ '--port', args.port,
629
+ '--baud', '921600',
630
+ '--before', 'default_reset',
631
+ '--after', 'hard_reset',
632
+ 'write_flash',
633
+ '-z',
634
+ '--flash_mode', 'keep',
635
+ '--flash_freq', 'keep',
636
+ '--flash_size', 'keep',
637
+ '0x0', 'bootloader.bin',
638
+ '0x8000', 'partitions.bin',
639
+ '0xe000', 'bootapp0.bin',
640
+ '0x10000', 'flash.bin'
641
+ ]
642
+
643
+ # Run esptool flash command
644
+ esptool.main(cmd_args)
645
+
646
+ # Clean up temporary bootloader files
647
+ os.remove('bootloader.bin')
648
+ os.remove('partitions.bin')
649
+ os.remove('bootapp0.bin')
650
+
651
+ # delete bin file
652
+ time.sleep(1)
653
+ os.remove('flash.bin')
654
+ print('Flash complete')
655
+
656
+ print('Done')
657
+
658
+
449
659
  if __name__ == "__main__":
450
660
  test_artus_api()
@@ -69,7 +69,7 @@ class UART:
69
69
  self.logger.error(f'Unable to send command through {self.port}')
70
70
  self.logger.error(e)
71
71
 
72
- def receive(self):
72
+ def receive(self,size=65):
73
73
 
74
74
  # required delay
75
75
  # t = time.perf_counter()
@@ -78,14 +78,14 @@ class UART:
78
78
  try:
79
79
  x = time.perf_counter()
80
80
  # # print(f'time start: {x}')
81
- while self.esp32.in_waiting < 65:
81
+ while self.esp32.in_waiting < size:
82
82
  if time.perf_counter() - x > 0.001:
83
83
  break
84
84
  # print(f'elapsed time: {time.perf_counter() - x}')
85
85
  # time.sleep(0.03)
86
86
  # check data
87
- if self.esp32.in_waiting >= 65: # get data if greater or equal to 65
88
- msg_bytes = self.esp32.read(65)
87
+ if self.esp32.in_waiting >= size: # get data if greater or equal to 65
88
+ msg_bytes = self.esp32.read(size)
89
89
  # print(msg_bytes)
90
90
  return msg_bytes
91
91
  elif self.esp32.in_waiting > 0:
@@ -186,11 +186,11 @@ class WiFiServer:
186
186
 
187
187
  return
188
188
 
189
- def receive(self):
189
+ def receive(self,size=65):
190
190
  try:
191
- byte_msg = self.conn.recv(65) # receive bytes
191
+ byte_msg = self.conn.recv(size) # receive bytes
192
192
 
193
- if len(byte_msg) == 65: # receive the first 65 bytes
193
+ if len(byte_msg) == size: # receive the first 65 bytes
194
194
  return byte_msg
195
195
 
196
196
  else:
@@ -12,12 +12,16 @@ See the LICENSE file in the repository for full details.
12
12
 
13
13
  import logging
14
14
  import time
15
+ import struct
15
16
  from tqdm import tqdm
16
17
 
17
18
 
18
19
  from .UART.uart import UART
19
20
  from .WiFi.wifi_server import WiFiServer
20
21
 
22
+ STARTUP_ACK = 0xaa
23
+ NORMAL_ACK = 0x2
24
+
21
25
  class Communication:
22
26
  """
23
27
  This communication class contains two communication methods:
@@ -26,17 +30,21 @@ class Communication:
26
30
  """
27
31
  def __init__(self,
28
32
  communication_method='UART',
29
- communication_channel_identifier='COM9',logger = None,baudrate = 921600):
33
+ communication_channel_identifier='COM9',logger = None,baudrate = 921600,robot_type='artus_lite'):
30
34
  # initialize communication
31
35
  self.communication_method = communication_method
32
36
  self.communication_channel_identifier = communication_channel_identifier
33
37
  self.communicator = None
34
38
  self.baudrate = baudrate
39
+ self.robot_type = robot_type
35
40
  # setup communication
36
41
  self._setup_communication()
37
42
  # params
38
43
  self.command_len = 33
39
- self.recv_len = 65
44
+ if robot_type == 'artus_lite':
45
+ self.recv_len = 65
46
+ elif robot_type == 'artus_lite_plus':
47
+ self.recv_len = 77
40
48
 
41
49
  if not logger:
42
50
  self.logger = logging.getLogger(__name__)
@@ -84,17 +92,40 @@ class Communication:
84
92
  def _byte_to_list_decode(self,package:bytearray) -> tuple:
85
93
  recv_data = []
86
94
  i = 0
87
- # BYTE 0 : ACK
88
- # BYTE 1 - 16 : 8 BIT POSITION
89
- # BYTE 17 - 49 : 16 BIT POSITION
90
- while i < 65:
91
- if 17 <= i <= 47: # 16 bit signed integer to int
92
- recv_data.append(package[i].from_bytes(package[i:i+2], byteorder='big', signed=True))
93
- i+=2
94
- else: # 8 bit signed integer to int
95
- recv_data.append(package[i].from_bytes(package[i:i+1],byteorder='little',signed=True))
96
- i+=1
95
+
96
+ if self.robot_type == 'artus_lite':
97
+ # BYTE 0 : ACK
98
+ # BYTE 1 - 16 : 8 BIT POSITION
99
+ # BYTE 17 - 49 : 16 BIT POSITION
100
+ # BYTE 50 - 65 : 8 BIT POSITION
101
+ while i < 65:
102
+ if 17 <= i <= 47: # 16 bit signed integer to int
103
+ recv_data.append(package[i].from_bytes(package[i:i+2], byteorder='big', signed=True))
104
+ i+=2
105
+ else: # 8 bit signed integer to int
106
+ recv_data.append(package[i].from_bytes(package[i:i+1],byteorder='little',signed=True))
107
+ i+=1
108
+
109
+
110
+ if len(recv_data) != 49:
111
+ raise ValueError(f"Artus Lite data length mismatch: {len(recv_data)}, expected 49")
97
112
 
113
+ elif self.robot_type == 'artus_lite_plus':
114
+ # BYTE 0 : ACK
115
+ # BYTE 1 - 16 : 8 BIT POSITION
116
+ # BYTE 17 - 76 : 4 byte force feedback (x,y,z)
117
+ while i < 76:
118
+ if 17 <= i <= 75: # 4-byte signed integer to int (force feedback x, y, z)
119
+ recv_data.append(float(struct.unpack('<f', package[i:i+4])[0]))
120
+ i += 4
121
+ else: # 8-bit signed integer to int
122
+ recv_data.append(int.from_bytes(package[i:i+1], byteorder='little', signed=True))
123
+ i += 1
124
+
125
+ if len(recv_data) != 32:
126
+ raise ValueError(f"Artus Lite Plus data length mismatch: {len(recv_data)}, expected 32")
127
+
128
+
98
129
  # extract acknowledge value
99
130
  ack = recv_data[0]
100
131
  del recv_data[0] # delete 0th value from array
@@ -139,7 +170,7 @@ class Communication:
139
170
  """
140
171
  byte_msg_recv = None
141
172
  try:
142
- byte_msg_recv = self.communicator.receive()
173
+ byte_msg_recv = self.communicator.receive(self.recv_len)
143
174
  if not byte_msg_recv:
144
175
  # self.logger.warning("No data received")
145
176
  return None,None
@@ -157,13 +188,17 @@ class Communication:
157
188
  self.communicator.close()
158
189
 
159
190
 
160
- def wait_for_ack(self,timeout=144,visual=False):
191
+ def wait_for_ack(self,timeout=144,visual=False,value=NORMAL_ACK):
161
192
  start_time = time.perf_counter()
162
193
  if visual:
163
194
  with tqdm(total=timeout, unit="s", desc="Waiting for ack") as pbar:
164
195
  while 1:
165
196
  tmp,rc_csum = self.receive_data()
166
- if tmp is not None:
197
+ if value == NORMAL_ACK:
198
+ if tmp is not None:
199
+ self.logger.info(f'ack received in {time.perf_counter() - start_time} seconds')
200
+ return 1
201
+ elif tmp == value:
167
202
  self.logger.info(f'ack received in {time.perf_counter() - start_time} seconds')
168
203
  return 1
169
204
  time.sleep(0.01)
@@ -0,0 +1,5 @@
1
+ from .artus_lite import ArtusLite
2
+ from .artus_lite_left import ArtusLite_LeftHand
3
+ from .artus_lite_right import ArtusLite_RightHand
4
+ from .artus_lite_plus import ArtusLite_Plus
5
+ from .artus_lite_plus_right import ArtusLite_Plus_RightHand