ArtusAPI 0.3.0__tar.gz → 0.5.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.

Potentially problematic release.


This version of ArtusAPI might be problematic. Click here for more details.

Files changed (27) hide show
  1. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/ArtusAPI/artus_api.py +3 -3
  2. ArtusAPI-0.5.0/ArtusAPI/commands/__init__.py +1 -0
  3. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/ArtusAPI/commands/commands.py +27 -16
  4. ArtusAPI-0.5.0/ArtusAPI/communication/UART/__init__.py +1 -0
  5. ArtusAPI-0.5.0/ArtusAPI/communication/UART/uart.py +83 -0
  6. ArtusAPI-0.5.0/ArtusAPI/communication/WiFi/__init__.py +1 -0
  7. ArtusAPI-0.5.0/ArtusAPI/communication/WiFi/wifi_server.py +234 -0
  8. ArtusAPI-0.5.0/ArtusAPI/communication/__init__.py +1 -0
  9. ArtusAPI-0.5.0/ArtusAPI/communication/communication.py +154 -0
  10. ArtusAPI-0.5.0/ArtusAPI/robot/__init__.py +1 -0
  11. ArtusAPI-0.5.0/ArtusAPI/robot/artus_lite/__init__.py +3 -0
  12. ArtusAPI-0.5.0/ArtusAPI/robot/artus_lite/artus_lite.py +199 -0
  13. ArtusAPI-0.5.0/ArtusAPI/robot/artus_lite/artus_lite_left.py +16 -0
  14. ArtusAPI-0.5.0/ArtusAPI/robot/artus_lite/artus_lite_right.py +21 -0
  15. ArtusAPI-0.5.0/ArtusAPI/robot/robot.py +77 -0
  16. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/ArtusAPI.egg-info/PKG-INFO +1 -1
  17. ArtusAPI-0.5.0/ArtusAPI.egg-info/SOURCES.txt +23 -0
  18. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/PKG-INFO +1 -1
  19. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/setup.py +1 -1
  20. ArtusAPI-0.3.0/ArtusAPI/commands/__init__.py +0 -0
  21. ArtusAPI-0.3.0/ArtusAPI.egg-info/SOURCES.txt +0 -11
  22. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/ArtusAPI/__init__.py +0 -0
  23. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/ArtusAPI.egg-info/dependency_links.txt +0 -0
  24. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/ArtusAPI.egg-info/top_level.txt +0 -0
  25. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/README.md +0 -0
  26. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/setup.cfg +0 -0
  27. {ArtusAPI-0.3.0 → ArtusAPI-0.5.0}/test/test.py +0 -0
@@ -11,9 +11,9 @@ print(desired_path)
11
11
 
12
12
 
13
13
 
14
- from communication.communication import Communication
15
- from commands.commands import Commands
16
- from robot.robot import Robot
14
+ from .communication import Communication
15
+ from .commands import Commands
16
+ from .robot import Robot
17
17
  import time
18
18
 
19
19
  class ArtusAPI:
@@ -0,0 +1 @@
1
+ from .commands import Commands
@@ -1,23 +1,34 @@
1
-
2
- import time
3
- import json
4
- import sys
5
1
  import os
6
- from pathlib import Path
7
- # Current file's directory
8
- current_file_path = Path(__file__).resolve()
9
- # Add the desired path to the system path
10
- desired_path = current_file_path.parent.parent
11
- sys.path.append(str(desired_path))
12
- print(desired_path)
13
-
2
+ import json
3
+ import time
14
4
  class Commands:
15
5
 
16
- def __init__(self):
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,
12
+
13
+ target_command = 102,
14
+ get_feedback_command = 104,
15
+
16
+ save_grasp_onboard_command = 200,
17
+ return_grasps_command = 210,
18
+ execute_grasp_command = 224):
17
19
 
18
- # commands
19
- with open(os.path.join(desired_path,'commands',"commands.json")) as file:
20
- self.commands = json.load(file)
20
+ self.commands = {
21
+ 'start_command': start_command,
22
+ 'calibrate_command': calibrate_command,
23
+ 'sleep_command': sleep_command,
24
+ 'firmware_update_command': firmware_update_command,
25
+ 'reset_command': reset_command,
26
+ 'target_command': target_command,
27
+ 'get_feedback_command': get_feedback_command,
28
+ 'save_grasp_onboard_command': save_grasp_onboard_command,
29
+ 'return_grasps_command': return_grasps_command,
30
+ 'execute_grasp_command': execute_grasp_command
31
+ }
21
32
 
22
33
  def get_robot_start_command(self,stream:bool,freq:int) -> list:
23
34
  """
@@ -0,0 +1 @@
1
+ from .uart import UART
@@ -0,0 +1,83 @@
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()
@@ -0,0 +1 @@
1
+ from .wifi_server import WiFiServer
@@ -0,0 +1,234 @@
1
+ import socket
2
+ import time
3
+ import os
4
+ import subprocess
5
+ import platform
6
+ import psutil
7
+ import logging
8
+
9
+ class WiFiServer:
10
+
11
+ def __init__(self,
12
+ HEADER = 64,# Header size
13
+ FORMAT = "utf-8", # Format of the message
14
+ DISCONNECT_MESSAGE = "!DISCONNECT", # Disconnection message from the client
15
+ port= 5050,
16
+ target_ssid="Artus3DTester",
17
+ password = None, # possibility to take in password
18
+ logger = None):
19
+
20
+ self.HEADER = HEADER
21
+ self.FORMAT = FORMAT
22
+ self.DISCONNECT_MESSAGE = DISCONNECT_MESSAGE
23
+ self.password = password
24
+
25
+ self.target_ssid = target_ssid
26
+ ip = None
27
+
28
+ # Looking for IP 192.168.4.2
29
+ # Port Number
30
+ self.port = port
31
+
32
+ self.server_socket = None
33
+ self.conn = None
34
+ self.addr = None
35
+
36
+ self.maximum_freq = None
37
+ if not logger:
38
+ self.logger = logging.getLogger(__name__)
39
+ else:
40
+ self.logger = logger
41
+
42
+ def _get_available_ip(self):
43
+ gateway_ip = None
44
+
45
+ # Get all network interfaces
46
+ interfaces = psutil.net_if_addrs()
47
+
48
+ for interface,addresses in interfaces.items():
49
+ for address in addresses:
50
+ if address.family == socket.AF_INET:
51
+ if "192.168.4" in address.address:
52
+ try:
53
+ return address.address
54
+ except KeyError:
55
+ #TODO logging
56
+ self.logger.error(f"No gateway information available")
57
+ None
58
+
59
+ return None
60
+
61
+ """ Start server and listen for connections """
62
+ def open(self):
63
+ try:
64
+
65
+ # look for wifi
66
+ self._find_ssid()
67
+
68
+ # get IP addresses associated with local machine
69
+ source_ip = self._get_available_ip()
70
+ # TCP tuple
71
+ self.esp = (source_ip,self.port)
72
+
73
+ # create server socket
74
+ self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
75
+ self.server_socket.settimeout(8) # blocking timeout to connect
76
+ self.server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
77
+ self.server_socket.bind(self.esp)
78
+
79
+ # listen for connections
80
+ self.server_socket.listen()
81
+ # TODO logging
82
+ self.logger.info(f"Listening for connection")
83
+ except Exception as e:
84
+ self.logger.error(f"No Network named {self.target_ssid}")
85
+
86
+ # Accept the connection
87
+ try:
88
+ self.conn, self.addr = self.server_socket.accept()
89
+ self.conn.settimeout(0.1) # 1 ms timeout for recv and send methods
90
+ # TODO logging
91
+ self.logger.info(f"New Connection: {self.addr} connected.")
92
+ except TimeoutError as e:
93
+ self.logger.error('Connection Timeout')
94
+ # TODO logging
95
+ time.sleep(1)
96
+
97
+ def _find_ssid(self):
98
+ sys = platform.system()
99
+
100
+ if sys == "Windows":
101
+ # set profile location
102
+ self.wifi_profile = os.getcwd()+self.target_ssid+".xml"
103
+
104
+ # prompt user if first time
105
+ if not os.path.isfile(os.getcwd()+'\\Wi-Fi-'+self.target_ssid+'.xml'):
106
+ # wait for connecting first time
107
+ input("First time Connection, Please connect to Artus Hand and enter Y when done")
108
+
109
+ time.sleep(1)
110
+
111
+ # save profile
112
+ save_profile_cmd = f'netsh wlan export profile {self.target_ssid} key=clear folder={os.getcwd()}'
113
+ subprocess.run(save_profile_cmd,shell=True)
114
+
115
+ time.sleep(1)
116
+
117
+ if not os.path.isfile(os.getcwd()+'\\Wi-Fi-'+self.target_ssid+'.xml'):
118
+ # TODO logging
119
+ self.logger.warning(f"Unable to create wifi profile")
120
+
121
+ else:
122
+ # connect to profile
123
+ connect_command = f'netsh wlan connect ssid={self.target_ssid} name={self.target_ssid} interface=Wi-Fi'
124
+ subprocess.run(connect_command, shell=True)
125
+
126
+ elif sys == "Linux":
127
+ # Linux uses the "nmcli" command to connect to Wi-Fi networks
128
+ connect_command = f'nmcli dev wifi connect "{self.target_ssid}"'
129
+
130
+ # input password
131
+ if not self.password:
132
+ self.password = input('type ssid password:')
133
+ if self.password:
134
+ connect_command += f' password "{self.password}"'
135
+
136
+ subprocess.run(connect_command, shell=True)
137
+
138
+ # clear password
139
+ self.password = None
140
+
141
+ else:
142
+ # TODO logging
143
+ self.logger.error("Unsupported operating system")
144
+
145
+ # wait X seconds to connect
146
+ for i in range(10):
147
+ time.sleep(0.01)
148
+
149
+ def close(self):
150
+ self.server_socket.close()
151
+ system = platform.system()
152
+
153
+ if system == "Windows":
154
+ # Windows uses the "netsh" command to disconnect from Wi-Fi networks
155
+ disconnect_command = f'netsh wlan disconnect interface="Wi-Fi" ssid="{self.target_ssid}"'
156
+ subprocess.run(disconnect_command, shell=True)
157
+
158
+ elif system == "Linux":
159
+ # Linux uses the "nmcli" command to disconnect from Wi-Fi networks
160
+ disconnect_command = f'nmcli dev disconnect iface "wlp2s0" ssid "{self.target_ssid}"'
161
+ subprocess.run(disconnect_command, shell=True)
162
+
163
+ else:
164
+ # TODO logging
165
+ self.logger.error("Unsupported operating system")
166
+ return
167
+
168
+ # TODO logging
169
+ self.logger.info(f"Disconnected from {self.target_ssid}")
170
+ time.sleep(2) # Wait for a few seconds for the disconnect to take effect
171
+
172
+ return
173
+
174
+ def receive(self):
175
+ try:
176
+ byte_msg = self.conn.recv(65) # receive bytes
177
+
178
+ if len(byte_msg) == 65: # receive the first 65 bytes
179
+ return byte_msg
180
+
181
+ else:
182
+ self.logger.warning(f"Incomplete data received - package size = {len(byte_msg)}")
183
+ return None
184
+ except Exception as e:
185
+ # TODO logging
186
+ self.logger.warning(f"No data available to receive")
187
+ return None
188
+
189
+
190
+ def send(self, data:bytearray):
191
+ try:
192
+ self.conn.sendall(data)
193
+ except Exception as e:
194
+ # TODO insert error logging
195
+ 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
@@ -0,0 +1 @@
1
+ from .communication import Communication
@@ -0,0 +1,154 @@
1
+
2
+ import logging
3
+ import time
4
+
5
+
6
+
7
+ # import sys
8
+ # from pathlib import Path
9
+ # # Current file's directory
10
+ # current_file_path = Path(__file__).resolve()
11
+ # # Add the desired path to the system path
12
+ # desired_path = current_file_path.parent.parent.parent
13
+ # sys.path.append(str(desired_path))
14
+ # print(desired_path)
15
+
16
+ # # Communication methodss
17
+ # from ArtusAPI.communication.WiFi.wifi_server import WiFiServer
18
+ # from ArtusAPI.communication.UART.uart import UART
19
+ # from ArtusAPI.ArtusAPI.communication.can import CAN
20
+
21
+ from .UART.uart import UART
22
+ from .WiFi.wifi_server import WiFiServer
23
+
24
+ class Communication:
25
+ """
26
+ This communication class contains two communication methods:
27
+ - UART
28
+ - WiFi
29
+ """
30
+ def __init__(self,
31
+ communication_method='UART',
32
+ communication_channel_identifier='COM9',logger = None):
33
+ # initialize communication
34
+ self.communication_method = communication_method
35
+ self.communication_channel_identifier = communication_channel_identifier
36
+ self.communicator = None
37
+ # setup communication
38
+ self._setup_communication()
39
+ # params
40
+ self.command_len = 33
41
+ self.recv_len = 65
42
+
43
+ if not logger:
44
+ self.logger = logging.getLogger(__name__)
45
+ else:
46
+ self.logger = logger
47
+
48
+
49
+ ################# Communication: _Initialization ##################
50
+ def _setup_communication(self):
51
+ """
52
+ Initialize communication based on the desired method; UART or WiFi
53
+ """
54
+ # setup communication based on the method
55
+ if self.communication_method == 'UART':
56
+ self.communicator = UART(port=self.communication_channel_identifier)
57
+ elif self.communication_method == 'WiFi':
58
+ self.communicator = WiFiServer(target_ssid=self.communication_channel_identifier)
59
+ else:
60
+ raise ValueError("Unknown communication method")
61
+
62
+ ################# Communication: Private Methods ##################
63
+ def _list_to_byte_encode(self,package:list) -> bytearray:
64
+ # data to send
65
+ send_data = bytearray(self.command_len+1)
66
+
67
+ # append command first
68
+ send_data[0:1] = package[0].to_bytes(1,byteorder='little')
69
+
70
+ for i in range(len(package)-1):
71
+ send_data[i+1:i+2] = int(package[i+1]).to_bytes(1,byteorder='little')
72
+
73
+ # set last value to '\n'
74
+ send_data[-1:] = '\n'.encode('ascii')
75
+
76
+ # return byte array to send
77
+ return send_data
78
+
79
+ def _byte_to_list_decode(self,package:bytearray) -> tuple:
80
+ recv_data = []
81
+ i = 0
82
+ while i < 65:
83
+ if 17 <= i <= 45: # 16 bit signed integer to int
84
+ recv_data.append(int.from_bytes(package[i:i+2],byteorder='big',signed=True))
85
+ i+=2
86
+ else: # 8 bit signed integer to int
87
+ recv_data.append(package[i].from_bytes(package[i:i+1],byteorder='little',signed=True))
88
+ i+=1
89
+
90
+ # extract acknowledge value
91
+ ack = recv_data[0]
92
+ del recv_data[0] # delete 0th value from array
93
+
94
+ return ack,recv_data
95
+
96
+
97
+ ################# Communication: Public Methods ##################
98
+ def open_connection(self):
99
+ """
100
+ start the communication
101
+ """
102
+ self.communicator.open()
103
+
104
+ def send_data(self, message:list):
105
+ """
106
+ send message
107
+ """
108
+ try:
109
+ byte_msg = self._list_to_byte_encode(message)
110
+ self.communicator.send(byte_msg)
111
+ return True
112
+ except Exception as e:
113
+ self.logger.warning("unable to send command")
114
+ print(e)
115
+ pass
116
+ return False
117
+
118
+ def receive_data(self) -> list:
119
+ """
120
+ receive message
121
+ """
122
+ try:
123
+ byte_msg_recv = self.communicator.receive()
124
+ if not byte_msg_recv:
125
+ self.logger.warning("No data received")
126
+ return None
127
+ ack,message_received = self._byte_to_list_decode(byte_msg_recv)
128
+ except Exception as e:
129
+ self.logger.warning("unable to receive message")
130
+ print(e)
131
+ return message_received
132
+ def close_connection(self):
133
+ self.communicator.close()
134
+
135
+
136
+ ##################################################################
137
+ ############################## TESTS #############################
138
+ ##################################################################
139
+ def test_wifi():
140
+ communication = Communication(communication_method='WiFi', communication_channel_identifier='Artus3D')
141
+ communication.open_connection()
142
+
143
+ def test_uart():
144
+ communication = Communication(communication_method='UART', communication_channel_identifier='COM9')
145
+ communication.open_connection()
146
+
147
+
148
+ if __name__ == "__main__":
149
+ # test_wifi()
150
+ test_uart()
151
+
152
+
153
+
154
+
@@ -0,0 +1 @@
1
+ from .robot import Robot
@@ -0,0 +1,3 @@
1
+ from .artus_lite import ArtusLite
2
+ from .artus_lite_left import ArtusLite_LeftHand
3
+ from .artus_lite_right import ArtusLite_RightHand
@@ -0,0 +1,199 @@
1
+
2
+ class ArtusLite:
3
+
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
15
+
16
+ joint_default_angles=[0, 0, 0, 0, # thumb
17
+ 0, 0, 0, # index
18
+ 0, 0, 0, # middle
19
+ 0, 0, 0, # ring
20
+ 0, 0, 0], # pinky
21
+
22
+ joint_rotation_directions=[1, 1, 1, 1, # thumb
23
+ 1, 1, 1, # index
24
+ 1, 1, 1, # middle
25
+ 1, 1, 1, # ring
26
+ 1, 1, 1], # pinky
27
+
28
+ joint_velocities=[80, 80, 80, 80, # thumb
29
+ 80, 80, 80, # index
30
+ 80, 80, 80, # middle
31
+ 80, 80, 80, # ring
32
+ 80, 80, 80], # pinky
33
+ joint_names=['thumb_spread', 'thumb_flex', 'thumb_d2', 'thumb_d1', # thumb
34
+ 'index_spread', 'index_flex', 'index_d2', # index
35
+ 'middle_spread', 'middle_flex', 'middle_d2', # middle
36
+ 'ring_spread', 'ring_flex', 'ring_d2', # ring
37
+ 'pinky_spread', 'pinky_flex', 'pinky_d2'], # pinky,
38
+
39
+ number_of_joints=16
40
+ ):
41
+
42
+ self.joint_max_angles = joint_max_angles
43
+ self.joint_min_angles = joint_min_angles
44
+ self.joint_default_angles = joint_default_angles
45
+ self.joint_rotation_directions = joint_rotation_directions
46
+ self.joint_velocities = joint_velocities
47
+ self.number_of_joints = number_of_joints
48
+ self.joint_names = joint_names
49
+
50
+ class Joint:
51
+ def __init__(self, index, min_angle, max_angle, default_angle, target_angle, rotation_direction, velocity, temperature):
52
+ self.index = index
53
+ self.min_angle = min_angle
54
+ self.max_angle = max_angle
55
+ self.default_angle = default_angle
56
+ self.target_angle = target_angle
57
+ self.rotation_direction = rotation_direction
58
+ self.velocity = velocity
59
+ self.feedback_angle = 0
60
+ self.feedback_current = 0
61
+ self.feedback_temperature = temperature
62
+ self.Joint = Joint
63
+
64
+ self._create_hand()
65
+
66
+
67
+
68
+ def _create_hand(self):
69
+ """
70
+ Creates the hand with all its fingers and joints into a dict
71
+ """
72
+ self.hand_joints = {}
73
+ for joint_index,joint_name in enumerate(self.joint_names):
74
+ joint = self.Joint(index=joint_index,
75
+ min_angle=self.joint_min_angles[joint_index],
76
+ max_angle=self.joint_max_angles[joint_index],
77
+ default_angle=self.joint_default_angles[joint_index],
78
+ target_angle=self.joint_default_angles[joint_index],
79
+ rotation_direction=self.joint_rotation_directions[joint_index],
80
+ velocity=self.joint_velocities[joint_index],
81
+ temperature=0)
82
+ self.hand_joints[joint_name] = joint
83
+
84
+ # free up mem
85
+ del self.joint_max_angles
86
+ del self.joint_min_angles
87
+ del self.joint_rotation_directions
88
+ del self.joint_velocities
89
+ del self.number_of_joints
90
+
91
+ def __str__(self):
92
+ return str(self.hand_joints)
93
+
94
+ """
95
+ @param joint_angles dict requires at least one joint struct with 3 fields in item, __don't care__ about key:
96
+ 1. index : [ 0 <-> 15 ] -- REQUIRED
97
+ 2. target_angle: [ -30 <-> 90 ] depending on joint -- REQUIRED
98
+ 3. velocity: [60 <-> 100]
99
+ """
100
+ def set_joint_angles(self, joint_angles:dict):
101
+ """
102
+ Set the joint angles of the hand by index
103
+ """
104
+ # verify that items are in order of index
105
+ sorted_items = sorted(joint_angles.items(), key=lambda x:x[1]['index'])
106
+ ordered_joint_angles = {key:value for key,value in sorted_items}
107
+ # set values based on index
108
+ for name,target_data in ordered_joint_angles.items():
109
+ self.hand_joints[self.joint_names[target_data['index']]].target_angle = target_data['target_angle'] * self.hand_joints[self.joint_names[target_data['index']]].rotation_direction
110
+
111
+ if 'velocity' in target_data:
112
+ self.hand_joints[self.joint_names[target_data['index']]].velocity = target_data['velocity']
113
+ else: # fill default velocity
114
+ self.hand_joints[self.joint_names[target_data['index']]].velocity = self.joint_velocities[target_data['index']]
115
+ self._check_joint_limits(self.hand_joints)
116
+
117
+ """
118
+ @param joint_angles dict requires at least one joint struct with 2 fields in item, with __correct__ key:
119
+ 1. key: joint_name from self.joint_names -- REQUIRED
120
+ 2. target_angle: [ -30 <-> 90 ] depending on joint -- REQUIRED
121
+ 3. velocity: [60 <-> 100]
122
+ """
123
+ def set_joint_angles_by_name(self, joint_angles:dict):
124
+ """
125
+ Set the joint angles of the hand by name
126
+ """
127
+ # set values based on names
128
+ for name,target_data in joint_angles.items():
129
+ self.hand_joints[name].target_angle = target_data.target_angle*self.hand_joints[name].rotation_direction
130
+
131
+ if 'velocity' in target_data:
132
+ self.hand_joints[name].velocity = target_data.velocity
133
+ else: # fill default velocity
134
+ self.hand_joints[name].velocity = self.joint_velocities[self.hand_joints[name].index]
135
+ self._check_joint_limits(self.hand_joints)
136
+
137
+
138
+ def _check_joint_limits(self, joint_angles):
139
+ """
140
+ Check if the joint angles are within the limits
141
+ """
142
+ for name,joint in self.hand_joints.items():
143
+ if joint_angles[name].target_angle > joint.max_angle:
144
+ joint_angles[name].target_angle = joint.max_angle
145
+ # TODO logging
146
+ if joint_angles[name].target_angle < joint.min_angle:
147
+ joint_angles[name].target_angle = joint.min_angle
148
+ # TODO logging
149
+ return joint_angles
150
+
151
+ def _check_joint_velocities(self, joint_angles):
152
+ """
153
+ Check if the joint velocities are within limits
154
+ """
155
+ for joint in self.hand_joints:
156
+ if joint_angles[joint.index] > 100:
157
+ joint_angles[joint.index] = 100
158
+ # TODO logging
159
+ if joint_angles[joint.index] < 60:
160
+ joint_angles[joint.index] = 60
161
+ # TODO logging
162
+ return joint_angles
163
+
164
+ def set_home_position(self):
165
+ """
166
+ Set the hand to the home position at default velocity
167
+ """
168
+ # 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)
172
+
173
+ def get_joint_angles(self, feedback_package:list):
174
+ """
175
+ Get the joint angles and feedback list data
176
+ and populate the feedback fields in the hand_joints dictionary
177
+ """
178
+ 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]
182
+
183
+ return feedback_package
184
+
185
+
186
+ def main():
187
+ artus_lite = ArtusLite()
188
+ print(artus_lite)
189
+ print(artus_lite.hand_joints)
190
+ print(len(artus_lite.hand_joints))
191
+
192
+
193
+ def print_finger_joint_limits():
194
+ artus_lite = ArtusLite()
195
+ for joint in artus_lite.hand_joints:
196
+ print(joint.index, joint.min_angle, joint.max_angle)
197
+ if __name__ == "__main__":
198
+ # main()
199
+ print_finger_joint_limits()
@@ -0,0 +1,16 @@
1
+
2
+ # import sys
3
+ # from pathlib import Path
4
+ # # Current file's directory
5
+ # current_file_path = Path(__file__).resolve()
6
+ # # Add the desired path to the system path
7
+ # desired_path = current_file_path.parent.parent.parent.parent.parent
8
+ # sys.path.append(str(desired_path))
9
+ # # print(desired_path)
10
+
11
+ # from ArtusAPI.robot.artus_lite.artus_lite import ArtusLite
12
+ from .artus_lite import ArtusLite
13
+
14
+ class ArtusLite_LeftHand(ArtusLite): # change any properties for the left hand
15
+ def __init__(self):
16
+ super().__init__()
@@ -0,0 +1,21 @@
1
+
2
+ # import sys
3
+ # from pathlib import Path
4
+ # # Current file's directory
5
+ # current_file_path = Path(__file__).resolve()
6
+ # # Add the desired path to the system path
7
+ # desired_path = current_file_path.parent.parent.parent.parent.parent
8
+ # sys.path.append(str(desired_path))
9
+ # # print(desired_path)
10
+
11
+ # from ArtusAPI.robot.artus_lite.artus_lite import ArtusLite
12
+ from .artus_lite import ArtusLite
13
+
14
+ class ArtusLite_RightHand(ArtusLite): # change any properties for the right hand
15
+ def __init__(self):
16
+ super().__init__( joint_rotation_directions=[-1, 1, 1, 1, # thumb
17
+ -1, 1, 1, # index
18
+ -1, 1, 1, # middle
19
+ -1, 1, 1, # ring
20
+ -1, 1, 1], # pinky
21
+ )
@@ -0,0 +1,77 @@
1
+
2
+
3
+ # import sys
4
+ # from pathlib import Path
5
+ # # Current file's directory
6
+ # current_file_path = Path(__file__).resolve()
7
+ # # Add the desired path to the system path
8
+ # desired_path = current_file_path.parent.parent.parent.parent
9
+ # sys.path.append(str(desired_path))
10
+ # print(desired_path)
11
+
12
+ # # Artus Lite Robots
13
+ # from ArtusAPI.robot.artus_lite.artus_lite_left import ArtusLite_LeftHand
14
+ # from ArtusAPI.robot.artus_lite.artus_lite_right import ArtusLite_RightHand
15
+
16
+ from .artus_lite.artus_lite_left import ArtusLite_LeftHand
17
+ from .artus_lite.artus_lite_right import ArtusLite_RightHand
18
+
19
+ # Artus 3D Robots
20
+
21
+
22
+ class Robot:
23
+ def __init__(self,
24
+ robot_type='artus_lite',
25
+ hand_type='left'):
26
+
27
+ # initialize robot
28
+ self.robot_type = robot_type
29
+ self.hand_type = hand_type
30
+ # setup robot
31
+ self.robot = None
32
+ self._setup_robot()
33
+
34
+ def _setup_robot(self):
35
+ """
36
+ Initialize robot based on the robot type and hand type
37
+ """
38
+ # setup robot based on the hand
39
+ if self.robot_type == 'artus_lite':
40
+ if self.hand_type == 'left':
41
+ self.robot = ArtusLite_LeftHand()
42
+ elif self.hand_type == 'right':
43
+ self.robot = ArtusLite_RightHand()
44
+ else:
45
+ raise ValueError("Unknown hand")
46
+ else:
47
+ raise ValueError("Unknown robot type")
48
+
49
+
50
+ def set_joint_angles(self, joint_angles:dict,name:bool):
51
+ """
52
+ Set the joint angles of the hand
53
+ """
54
+ if name:
55
+ return self.robot.set_joint_angles_by_name(joint_angles)
56
+ else:
57
+ return self.robot.set_joint_angles(joint_angles)
58
+
59
+
60
+ def set_home_position(self):
61
+ """
62
+ Set the hand to the home position
63
+ """
64
+ return self.robot.set_home_position()
65
+
66
+ def get_joint_angles(self, joint_angles):
67
+ """
68
+ Get the joint angles of the hand
69
+ """
70
+ return self.robot.get_joint_angles(joint_angles)
71
+
72
+
73
+ def main():
74
+ artus_robot = Robot(hand_type='left')
75
+
76
+ if __name__ == "__main__":
77
+ main()
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ArtusAPI
3
- Version: 0.3.0
3
+ Version: 0.5.0
4
4
  Summary: API to control Artus Family of Robots
@@ -0,0 +1,23 @@
1
+ README.md
2
+ setup.py
3
+ ArtusAPI/__init__.py
4
+ ArtusAPI/artus_api.py
5
+ ArtusAPI.egg-info/PKG-INFO
6
+ ArtusAPI.egg-info/SOURCES.txt
7
+ ArtusAPI.egg-info/dependency_links.txt
8
+ ArtusAPI.egg-info/top_level.txt
9
+ ArtusAPI/commands/__init__.py
10
+ ArtusAPI/commands/commands.py
11
+ ArtusAPI/communication/__init__.py
12
+ ArtusAPI/communication/communication.py
13
+ ArtusAPI/communication/UART/__init__.py
14
+ ArtusAPI/communication/UART/uart.py
15
+ ArtusAPI/communication/WiFi/__init__.py
16
+ ArtusAPI/communication/WiFi/wifi_server.py
17
+ ArtusAPI/robot/__init__.py
18
+ ArtusAPI/robot/robot.py
19
+ ArtusAPI/robot/artus_lite/__init__.py
20
+ ArtusAPI/robot/artus_lite/artus_lite.py
21
+ ArtusAPI/robot/artus_lite/artus_lite_left.py
22
+ ArtusAPI/robot/artus_lite/artus_lite_right.py
23
+ test/test.py
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ArtusAPI
3
- Version: 0.3.0
3
+ Version: 0.5.0
4
4
  Summary: API to control Artus Family of Robots
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='ArtusAPI',
5
- version='0.3.0',
5
+ version='0.5.0',
6
6
  description='API to control Artus Family of Robots',
7
7
  # package_dir={'': '/'}, # tells setuptools that your packages are under src
8
8
  packages=find_packages(exclude=['data*', 'examples*', 'tests*','venv*'])
File without changes
@@ -1,11 +0,0 @@
1
- README.md
2
- setup.py
3
- ArtusAPI/__init__.py
4
- ArtusAPI/artus_api.py
5
- ArtusAPI.egg-info/PKG-INFO
6
- ArtusAPI.egg-info/SOURCES.txt
7
- ArtusAPI.egg-info/dependency_links.txt
8
- ArtusAPI.egg-info/top_level.txt
9
- ArtusAPI/commands/__init__.py
10
- ArtusAPI/commands/commands.py
11
- test/test.py
File without changes
File without changes
File without changes
File without changes