ArtusAPI 0.1.0__tar.gz → 0.2.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.

@@ -0,0 +1,136 @@
1
+
2
+ import sys
3
+ import logging
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
9
+ sys.path.append(str(desired_path))
10
+ print(desired_path)
11
+
12
+
13
+
14
+ from ArtusAPI.communication.communication import Communication
15
+ from ArtusAPI.commands.commands import Commands
16
+ from ArtusAPI.robot.robot import Robot
17
+ import time
18
+
19
+ class ArtusAPI:
20
+
21
+ def __init__(self,
22
+ # communication
23
+ communication_method='UART',
24
+ communication_channel_identifier='COM9',
25
+ # robot
26
+ robot_type='artus_lite',
27
+ hand_type ='left',
28
+ stream = False,
29
+ communication_frequency = 400, # hz
30
+ logger = None
31
+ ):
32
+
33
+ self._communication_handler = Communication(communication_method=communication_method,
34
+ communication_channel_identifier=communication_channel_identifier)
35
+ self._command_handler = Commands()
36
+ self._robot_handler = Robot(robot_type = robot_type,
37
+ hand_type = hand_type)
38
+
39
+ self._last_command_sent_time = time.perf_counter()
40
+ self._communication_frequency = 1 / communication_frequency
41
+ self._communication_frequency_us = int(self._communication_frequency * 1000000)
42
+ self.stream = stream
43
+
44
+ if not logger:
45
+ self.logger = logging.getLogger(__name__)
46
+ else:
47
+ self.logger = logger
48
+
49
+ # communication setup
50
+ def connect(self):
51
+ return self._communication_handler.open_connection()
52
+ def disconnect(self):
53
+ return self._communication_handler.close_connection()
54
+
55
+
56
+
57
+
58
+ # robot states
59
+ def wake_up(self):
60
+ print(f"communication frequency in useconds = {self._communication_frequency_us}")
61
+ 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)
63
+ def sleep(self):
64
+ robot_sleep_command = self._command_handler.get_sleep_command()
65
+ return self._communication_handler.send_data(robot_sleep_command)
66
+ def calibrate(self):
67
+ robot_calibrate_command = self._command_handler.get_calibration_command()
68
+ return self._communication_handler.send_data(robot_calibrate_command)
69
+
70
+
71
+ # robot control
72
+ def set_joint_angles(self, joint_angles:dict):
73
+ self._robot_handler.set_joint_angles(joint_angles=joint_angles,name=False)
74
+ robot_set_joint_angles_command = self._command_handler.get_target_position_command(self._robot_handler.robot.hand_joints)
75
+ # check communication frequency
76
+ if not self._check_communication_frequency():
77
+ return False
78
+ return self._communication_handler.send_data(robot_set_joint_angles_command)
79
+
80
+ def set_home_position(self):
81
+ self._robot_handler.set_home_position()
82
+ robot_set_home_position_command = self._command_handler.get_target_position_command()
83
+ # check communication frequency
84
+ if not self._check_communication_frequency():
85
+ return False
86
+ return self._communication_handler.send_data(robot_set_home_position_command)
87
+
88
+ def _check_communication_frequency(self):
89
+ """
90
+ check if the communication frequency is too high
91
+ """
92
+ current_time = time.perf_counter()
93
+ if current_time - self._last_command_sent_time < self._communication_frequency:
94
+ self.logger.warning("Command not sent. Communication frequency is too high.")
95
+ return False
96
+ self._last_command_sent_time = current_time
97
+ return True
98
+
99
+
100
+
101
+ # robot feedback
102
+ def _receive_feedback(self):
103
+ feedback_command = self._command_handler.get_states_command()
104
+ self._communication_handler.send_data(feedback_command)
105
+ return self._communication_handler.receive_data()
106
+
107
+ def get_joint_angles(self):
108
+ feedback_command = self._receive_feedback()
109
+ joint_angles = self._robot_handler.get_joint_angles(feedback_command)
110
+ return joint_angles
111
+
112
+ # robot feedback stream
113
+ def get_streamed_joint_angles(self):
114
+ if not self._check_communication_frequency():
115
+ return False
116
+ feedback_command = self._communication_handler.receive_data()
117
+ if not feedback_command:
118
+ return None
119
+ joint_angles = self._robot_handler.get_joint_angles(feedback_command)
120
+ return joint_angles
121
+
122
+
123
+
124
+
125
+
126
+ def test_artus_api():
127
+ artus_api = ArtusAPI()
128
+ artus_api.connect()
129
+ artus_api.wake_up()
130
+ artus_api.calibrate()
131
+ artus_api.set_home_position()
132
+ time.sleep(2)
133
+ artus_api.disconnect()
134
+
135
+ if __name__ == "__main__":
136
+ test_artus_api()
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ArtusAPI
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: API to control Artus Family of Robots
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
1
+ ArtusAPI
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ArtusAPI
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: API to control Artus Family of Robots
@@ -0,0 +1,11 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='ArtusAPI',
5
+ version='0.2.0',
6
+ description='API to control Artus Family of Robots',
7
+ # package_dir={'': '/'}, # tells setuptools that your packages are under src
8
+ packages=find_packages(exclude=['data*', 'examples*', 'tests*','venv*'])
9
+ # packages=find_packages(where='/'),
10
+ # other setup configurations
11
+ )
File without changes
@@ -1,9 +0,0 @@
1
- README.md
2
- setup.py
3
- ArtusAPI/ArtusAPI.egg-info/PKG-INFO
4
- ArtusAPI/ArtusAPI.egg-info/SOURCES.txt
5
- ArtusAPI/ArtusAPI.egg-info/dependency_links.txt
6
- ArtusAPI/ArtusAPI.egg-info/top_level.txt
7
- ArtusAPI/commands/__init__.py
8
- ArtusAPI/commands/commands.py
9
- test/test.py
@@ -1 +0,0 @@
1
- commands
ArtusAPI-0.1.0/setup.py DELETED
@@ -1,10 +0,0 @@
1
- from setuptools import setup, find_packages
2
-
3
- setup(
4
- name='ArtusAPI',
5
- version='0.1.0',
6
- description='API to control Artus Family of Robots',
7
- package_dir={'': 'ArtusAPI'}, # tells setuptools that your packages are under src
8
- packages=find_packages(where='ArtusAPI'),
9
- # other setup configurations
10
- )
File without changes
File without changes