franky-control 1.0.2__cp38-cp38-manylinux_2_28_x86_64.whl
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.
- franky/__init__.py +12 -0
- franky/_franky.cpython-38-x86_64-linux-gnu.so +0 -0
- franky/_franky.pyi +1736 -0
- franky/motion.py +12 -0
- franky/reaction.py +43 -0
- franky/robot.py +8 -0
- franky/robot_web_session.py +183 -0
- franky_control-1.0.2.dist-info/LICENSE +165 -0
- franky_control-1.0.2.dist-info/METADATA +869 -0
- franky_control-1.0.2.dist-info/RECORD +27 -0
- franky_control-1.0.2.dist-info/WHEEL +5 -0
- franky_control-1.0.2.dist-info/top_level.txt +2 -0
- franky_control.libs/libPocoFoundation-7333b9fc.so.95 +0 -0
- franky_control.libs/libPocoNet-007a41b7.so.95 +0 -0
- franky_control.libs/libboost_filesystem-38deced9.so.1.66.0 +0 -0
- franky_control.libs/libboost_serialization-3aa46b41.so.1.66.0 +0 -0
- franky_control.libs/libboost_system-69a6c43e.so.1.66.0 +0 -0
- franky_control.libs/libconsole_bridge-def124d9.so.0.3 +0 -0
- franky_control.libs/libfmt-8375f6bf.so.6.2.1 +0 -0
- franky_control.libs/libfranka-92ddaf43.so.0.15.0 +0 -0
- franky_control.libs/libpinocchio_default-7b0164b0.so.3.1.0 +0 -0
- franky_control.libs/libpinocchio_parsers-50abb87c.so.3.1.0 +0 -0
- franky_control.libs/libtinyxml-435d1f53.so.0.2.6.2 +0 -0
- franky_control.libs/liburdfdom_model-9e7b5a88.so.1.0 +0 -0
- franky_control.libs/liburdfdom_model_state-741cbb83.so.1.0 +0 -0
- franky_control.libs/liburdfdom_sensor-5dbb5bb4.so.1.0 +0 -0
- franky_control.libs/liburdfdom_world-bd943329.so.1.0 +0 -0
franky/motion.py
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
from typing import Union
|
2
|
+
|
3
|
+
from ._franky import BaseCartesianPoseMotion, BaseCartesianVelocityMotion, BaseJointPositionMotion, \
|
4
|
+
BaseJointVelocityMotion, BaseTorqueMotion
|
5
|
+
|
6
|
+
Motion = Union[
|
7
|
+
BaseCartesianPoseMotion,
|
8
|
+
BaseCartesianVelocityMotion,
|
9
|
+
BaseJointPositionMotion,
|
10
|
+
BaseJointVelocityMotion,
|
11
|
+
BaseTorqueMotion
|
12
|
+
]
|
franky/reaction.py
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
from ._franky import Condition, BaseCartesianPoseMotion, BaseCartesianVelocityMotion, BaseJointPositionMotion, \
|
2
|
+
BaseJointVelocityMotion, BaseTorqueMotion, \
|
3
|
+
CartesianPoseReaction as _CartesianPoseReaction, \
|
4
|
+
CartesianVelocityReaction as _CartesianVelocityReaction, \
|
5
|
+
JointPositionReaction as _JointPositionReaction, \
|
6
|
+
JointVelocityReaction as _JointVelocityReaction, \
|
7
|
+
TorqueReaction as _TorqueReaction
|
8
|
+
|
9
|
+
from .motion import Motion
|
10
|
+
|
11
|
+
|
12
|
+
class Reaction:
|
13
|
+
_control_signal_type = None
|
14
|
+
|
15
|
+
def __new__(cls, condition: Condition, motion: Motion):
|
16
|
+
for reaction_type in _REACTION_TYPES:
|
17
|
+
if isinstance(motion, reaction_type._motion_type):
|
18
|
+
return reaction_type.__new__(reaction_type, condition, motion)
|
19
|
+
raise TypeError(f"Unknown motion type {type(motion)}.")
|
20
|
+
|
21
|
+
|
22
|
+
class CartesianPoseReaction(_CartesianPoseReaction, Reaction):
|
23
|
+
_motion_type = BaseCartesianPoseMotion
|
24
|
+
|
25
|
+
|
26
|
+
class CartesianVelocityReaction(_CartesianVelocityReaction, Reaction):
|
27
|
+
_motion_type = BaseCartesianVelocityMotion
|
28
|
+
|
29
|
+
|
30
|
+
class JointPositionReaction(_JointPositionReaction, Reaction):
|
31
|
+
_motion_type = BaseJointPositionMotion
|
32
|
+
|
33
|
+
|
34
|
+
class JointVelocityReaction(_JointVelocityReaction, Reaction):
|
35
|
+
_motion_type = BaseJointVelocityMotion
|
36
|
+
|
37
|
+
|
38
|
+
class TorqueReaction(_TorqueReaction, Reaction):
|
39
|
+
_motion_type = BaseTorqueMotion
|
40
|
+
|
41
|
+
|
42
|
+
_REACTION_TYPES = [
|
43
|
+
CartesianPoseReaction, CartesianVelocityReaction, JointPositionReaction, JointVelocityReaction, TorqueReaction]
|
franky/robot.py
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
import base64
|
2
|
+
import hashlib
|
3
|
+
import http.client
|
4
|
+
import json
|
5
|
+
import ssl
|
6
|
+
import time
|
7
|
+
import urllib.parse
|
8
|
+
from http.client import HTTPSConnection, HTTPResponse
|
9
|
+
from typing import Dict, Optional, Any, Literal
|
10
|
+
from urllib.error import HTTPError
|
11
|
+
|
12
|
+
|
13
|
+
class FrankaAPIError(Exception):
|
14
|
+
def __init__(self, target: str, http_code: int, http_reason: str, headers: Dict[str, str], message: str):
|
15
|
+
super().__init__(
|
16
|
+
f"Franka API returned error {http_code} ({http_reason}) when accessing end-point {target}: {message}")
|
17
|
+
self.target = target
|
18
|
+
self.http_code = http_code
|
19
|
+
self.headers = headers
|
20
|
+
self.message = message
|
21
|
+
|
22
|
+
|
23
|
+
class RobotWebSession:
|
24
|
+
def __init__(self, fci_hostname: str, username: str, password: str):
|
25
|
+
self.__fci_hostname = fci_hostname
|
26
|
+
self.__username = username
|
27
|
+
self.__password = password
|
28
|
+
|
29
|
+
self.__client = None
|
30
|
+
self.__token = None
|
31
|
+
self.__control_token = None
|
32
|
+
self.__control_token_id = None
|
33
|
+
|
34
|
+
@staticmethod
|
35
|
+
def __encode_password(user: str, password: str) -> str:
|
36
|
+
bs = ",".join([str(b) for b in hashlib.sha256((password + "#" + user + "@franka").encode("utf-8")).digest()])
|
37
|
+
return base64.encodebytes(bs.encode("utf-8")).decode("utf-8")
|
38
|
+
|
39
|
+
def _send_api_request(self, target: str, headers: Optional[Dict[str, str]] = None, body: Optional[Any] = None,
|
40
|
+
method: Literal["GET", "POST", "DELETE"] = "POST"):
|
41
|
+
_headers = {
|
42
|
+
"Cookie": f"authorization={self.__token}"
|
43
|
+
}
|
44
|
+
if headers is not None:
|
45
|
+
_headers.update(headers)
|
46
|
+
self.__client.request(method, target, headers=_headers, body=body)
|
47
|
+
res: HTTPResponse = self.__client.getresponse()
|
48
|
+
if res.getcode() != 200:
|
49
|
+
raise FrankaAPIError(target, res.getcode(), res.reason, dict(res.headers), res.read().decode("utf-8"))
|
50
|
+
return res.read()
|
51
|
+
|
52
|
+
def send_api_request(self, target: str, headers: Optional[Dict[str, str]] = None, body: Optional[Any] = None,
|
53
|
+
method: Literal["GET", "POST", "DELETE"] = "POST"):
|
54
|
+
last_error = None
|
55
|
+
for i in range(3):
|
56
|
+
try:
|
57
|
+
return self._send_api_request(target, headers, body, method)
|
58
|
+
except http.client.RemoteDisconnected as ex:
|
59
|
+
last_error = ex
|
60
|
+
raise last_error
|
61
|
+
|
62
|
+
def send_control_api_request(self, target: str, headers: Optional[Dict[str, str]] = None,
|
63
|
+
body: Optional[Any] = None,
|
64
|
+
method: Literal["GET", "POST", "DELETE"] = "POST"):
|
65
|
+
if headers is None:
|
66
|
+
headers = {}
|
67
|
+
self.__check_control_token()
|
68
|
+
_headers = {
|
69
|
+
"X-Control-Token": self.__control_token
|
70
|
+
}
|
71
|
+
_headers.update(headers)
|
72
|
+
return self.send_api_request(target, headers=_headers, method=method, body=body)
|
73
|
+
|
74
|
+
def open(self):
|
75
|
+
if self.is_open:
|
76
|
+
raise RuntimeError("Session is already open.")
|
77
|
+
self.__client = HTTPSConnection(self.__fci_hostname, timeout=12, context=ssl._create_unverified_context())
|
78
|
+
self.__client.connect()
|
79
|
+
payload = json.dumps(
|
80
|
+
{"login": self.__username, "password": self.__encode_password(self.__username, self.__password)})
|
81
|
+
self.__token = self.send_api_request(
|
82
|
+
"/admin/api/login", headers={"content-type": "application/json"},
|
83
|
+
body=payload).decode("utf-8")
|
84
|
+
return self
|
85
|
+
|
86
|
+
def close(self):
|
87
|
+
if not self.is_open:
|
88
|
+
raise RuntimeError("Session is not open.")
|
89
|
+
if self.__control_token is not None:
|
90
|
+
self.release_control()
|
91
|
+
self.__token = None
|
92
|
+
self.__client.close()
|
93
|
+
|
94
|
+
def __enter__(self):
|
95
|
+
self.open()
|
96
|
+
|
97
|
+
def __exit__(self, type, value, traceback):
|
98
|
+
self.close()
|
99
|
+
|
100
|
+
def __check_control_token(self):
|
101
|
+
if self.__control_token is None:
|
102
|
+
raise RuntimeError("Client does not have control. Call take_control() first.")
|
103
|
+
|
104
|
+
def take_control(self, wait_timeout: float = 10.0):
|
105
|
+
if self.__control_token is None:
|
106
|
+
res = self.send_api_request(
|
107
|
+
"/admin/api/control-token/request", headers={"content-type": "application/json"},
|
108
|
+
body=json.dumps({"requestedBy": self.__username}))
|
109
|
+
response_dict = json.loads(res)
|
110
|
+
self.__control_token = response_dict["token"]
|
111
|
+
self.__control_token_id = response_dict["id"]
|
112
|
+
# One should probably use websockets here but that would introduce another dependency
|
113
|
+
start = time.time()
|
114
|
+
while time.time() - start < wait_timeout and not self.has_control():
|
115
|
+
time.sleep(1.0)
|
116
|
+
return self.has_control()
|
117
|
+
|
118
|
+
def release_control(self):
|
119
|
+
if self.__control_token is not None:
|
120
|
+
self.send_control_api_request(
|
121
|
+
"/admin/api/control-token", headers={"content-type": "application/json"}, method="DELETE",
|
122
|
+
body=json.dumps({"token": self.__control_token}))
|
123
|
+
self.__control_token = None
|
124
|
+
self.__control_token_id = None
|
125
|
+
|
126
|
+
def enable_fci(self):
|
127
|
+
self.send_control_api_request(
|
128
|
+
"/desk/api/system/fci", headers={"content-type": "application/x-www-form-urlencoded"},
|
129
|
+
body=f"token={urllib.parse.quote(base64.b64encode(self.__control_token.encode('ascii')))}")
|
130
|
+
|
131
|
+
def has_control(self):
|
132
|
+
if self.__control_token_id is not None:
|
133
|
+
status = self.get_system_status()
|
134
|
+
active_token = status["controlToken"]["activeToken"]
|
135
|
+
return active_token is not None and active_token["id"] == self.__control_token_id
|
136
|
+
return False
|
137
|
+
|
138
|
+
def start_task(self, task: str):
|
139
|
+
self.send_api_request(
|
140
|
+
"/desk/api/execution", headers={"content-type": "application/x-www-form-urlencoded"},
|
141
|
+
body=f"id={task}")
|
142
|
+
|
143
|
+
def unlock_brakes(self):
|
144
|
+
self.send_control_api_request(
|
145
|
+
"/desk/api/joints/unlock", headers={"content-type": "application/x-www-form-urlencoded"})
|
146
|
+
|
147
|
+
def lock_brakes(self):
|
148
|
+
self.send_control_api_request(
|
149
|
+
"/desk/api/joints/lock", headers={"content-type": "application/x-www-form-urlencoded"})
|
150
|
+
|
151
|
+
def set_mode_programming(self):
|
152
|
+
self.send_control_api_request(
|
153
|
+
"/desk/api/operating-mode/programming", headers={"content-type": "application/x-www-form-urlencoded"})
|
154
|
+
|
155
|
+
def set_mode_execution(self):
|
156
|
+
self.send_control_api_request(
|
157
|
+
"/desk/api/operating-mode/execution", headers={"content-type": "application/x-www-form-urlencoded"})
|
158
|
+
|
159
|
+
def get_system_status(self):
|
160
|
+
return json.loads(self.send_api_request("/admin/api/system-status", method="GET").decode("utf-8"))
|
161
|
+
|
162
|
+
def execute_self_test(self):
|
163
|
+
if self.get_system_status()["safety"]["recoverableErrors"]["td2Timeout"]:
|
164
|
+
self.send_control_api_request(
|
165
|
+
"/admin/api/safety/recoverable-safety-errors/acknowledge?error_id=TD2Timeout")
|
166
|
+
response = json.loads(self.send_control_api_request(
|
167
|
+
"/admin/api/safety/td2-tests/execute", headers={"content-type": "application/json"}).decode("utf-8"))
|
168
|
+
assert response["code"] == "SuccessResponse"
|
169
|
+
time.sleep(0.5)
|
170
|
+
while self.get_system_status()["safety"]["safetyControllerStatus"] == "SelfTest":
|
171
|
+
time.sleep(0.5)
|
172
|
+
|
173
|
+
@property
|
174
|
+
def client(self) -> HTTPSConnection:
|
175
|
+
return self.__client
|
176
|
+
|
177
|
+
@property
|
178
|
+
def token(self) -> str:
|
179
|
+
return self.__token
|
180
|
+
|
181
|
+
@property
|
182
|
+
def is_open(self) -> bool:
|
183
|
+
return self.__token is not None
|
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|