franky-control 1.0.0__cp38-cp38-manylinux_2_34_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.
@@ -0,0 +1,842 @@
1
+ Metadata-Version: 2.1
2
+ Name: franky-control
3
+ Version: 1.0.0
4
+ Summary: High-level control library for Franka robots.
5
+ Home-page: https://github.com/TimSchneider42/franky
6
+ Author: Tim Schneider
7
+ Author-email: tim@robot-learning.de
8
+ License: LGPL-3.0-or-later
9
+ Keywords: robot,robotics,trajectory-generation,motion-control
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Topic :: Scientific/Engineering
13
+ Classifier: Programming Language :: C++
14
+ Requires-Python: >=3.7
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy
18
+
19
+ <div align="center">
20
+ <img width="340" src="https://raw.githubusercontent.com/timschneider42/franky/master/doc/logo.svg?sanitize=true">
21
+ <h3 align="center">
22
+ High-Level Control Library for Franka Robots with Python and C++ Support
23
+ </h3>
24
+ </div>
25
+ <p align="center">
26
+ <a href="https://github.com/timschneider42/franky/actions">
27
+ <img src="https://github.com/timschneider42/franky/workflows/CI/badge.svg" alt="CI">
28
+ </a>
29
+
30
+ <a href="https://github.com/timschneider42/franky/actions">
31
+ <img src="https://github.com/timschneider42/franky/workflows/Publish/badge.svg" alt="Publish">
32
+ </a>
33
+
34
+ <a href="https://github.com/timschneider42/franky/issues">
35
+ <img src="https://img.shields.io/github/issues/timschneider42/franky.svg" alt="Issues">
36
+ </a>
37
+
38
+ <a href="https://github.com/timschneider42/franky/releases">
39
+ <img src="https://img.shields.io/github/v/release/timschneider42/franky.svg?include_prereleases&sort=semver" alt="Releases">
40
+ </a>
41
+
42
+ <a href="https://github.com/timschneider42/franky/blob/master/LICENSE">
43
+ <img src="https://img.shields.io/badge/license-LGPL-green.svg" alt="LGPL">
44
+ </a>
45
+ </p>
46
+
47
+ Franky is a high-level control library for Franka robots offering Python and C++ support.
48
+ By providing a high-level control interface, Franky eliminates the need for strict real-time programming at 1 kHz,
49
+ making control from non-real time environments, such as Python programs, feasible.
50
+ Instead of relying on low-level control commands, Franky expects high-level position or velocity targets and
51
+ uses [Ruckig](https://github.com/pantor/ruckig) to plan time-optimal trajectories in real time.
52
+
53
+ Although Python does not provide real-time guarantees, Franky strives to maintain as much real-time control as possible.
54
+ Motions can be preempted at any moment, prompting Franky to re-plan trajectories on the fly.
55
+ To handle unforeseen situations—such as unexpected contact with the environment—Franky includes a reaction system that
56
+ allows to dynamically update motion commands.
57
+ Furthermore, most non-real time functionality of [libfranka](https://frankaemika.github.io/docs/libfranka.html), such as
58
+ Gripper control, is made directly available in Python.
59
+
60
+ Check out the [tutorial](#-tutorial) and the [examples](https://github.com/TimSchneider42/franky/tree/master/examples)
61
+ for an introduction.
62
+ The full documentation can be found
63
+ at [https://timschneider42.github.io/franky/](https://timschneider42.github.io/franky/).
64
+
65
+ ## 🚀 Features
66
+
67
+ - **Control your Franka robot directly from Python in just a few lines!**
68
+ No more endless hours setting up ROS, juggling packages, or untangling dependencies. Just `pip install` — no ROS at all.
69
+
70
+ - **[Four control modes](#-motion-types)**:
71
+ - [Cartesian position](#cartesian-position-control)
72
+ - [Cartesian velocity](#cartesian-velocity-control)
73
+ - [Joint position](#joint-position-control)
74
+ - [Joint velocity](#joint-velocity-control)
75
+
76
+ Franky uses [Ruckig](https://github.com/pantor/ruckig) to generate smooth, time-optimal trajectories while respecting velocity, acceleration, and jerk limits.
77
+
78
+ - **[Real-time control from Python and C++](#-real-time-motions)**:
79
+ Need to change the target while the robot’s moving? No problem. Franky re-plans trajectories on the fly, so you can preempt motions anytime.
80
+
81
+ - **[Reactive behavior](#-real-time-reactions)**:
82
+ Robots don’t always go according to plan. Franky lets you define reactions to unexpected events—like contact with the environment — so you can change course in real time.
83
+
84
+ - **[Motion and reaction callbacks](#motion-callbacks)**:
85
+ Want to monitor what’s happening under the hood? Add callbacks to your motions and reactions. They won’t block the control thread and are super handy for debugging or logging.
86
+
87
+ - **Things are moving too fast? [Tune the robot's dynamics to your needs](#-robot)**:
88
+ Adjust max velocity, acceleration, and jerk to match your setup or task. Fine control for smooth, safe operation.
89
+
90
+ - **Full Python access to the libfranka API**:
91
+ Want to tweak impedance, read the robot state, set force thresholds, or mess with the Jacobian? Go for it. If libfranka supports it, chances are Franky does too.
92
+
93
+
94
+ ## ⚙️ Setup
95
+
96
+ To install franky, you have to follow three steps:
97
+
98
+ 1. Ensure that you are using a realtime kernel
99
+ 2. Ensure that the executing user has permission to run real-time applications
100
+ 3. Install franky via pip or build it from source
101
+
102
+ ### Installing a real-time kernel
103
+
104
+ In order for franky to function properly, it requires the underlying OS to use a realtime kernel.
105
+ Otherwise, you might see `communication_constrains_violation` errors.
106
+
107
+ To check whether your system is currently using a real-time kernel, type `uname -a`.
108
+ You should see something like this:
109
+
110
+ ```
111
+ $ uname -a
112
+ Linux [PCNAME] 5.15.0-1056-realtime #63-Ubuntu SMP PREEMPT_RT ...
113
+ ```
114
+
115
+ If it does not say PREEMPT_RT, you are not currently running a real-time kernel.
116
+
117
+ There are multiple ways of installing a real-time kernel.
118
+ You
119
+ can [build it from source](https://frankaemika.github.io/docs/installation_linux.html#setting-up-the-real-time-kernel)
120
+ or, if you are using Ubuntu, it can be [enabled through Ubuntu Pro](https://ubuntu.com/real-time).
121
+
122
+ ### Allowing the executing user to run real-time applications
123
+
124
+ First, create a group `realtime` and add your user (or whoever is running franky) to this group:
125
+
126
+ ```bash
127
+ sudo addgroup realtime
128
+ sudo usermod -a -G realtime $(whoami)
129
+ ```
130
+
131
+ Afterward, add the following limits to the real-time group in /etc/security/limits.conf:
132
+
133
+ ```
134
+ @realtime soft rtprio 99
135
+ @realtime soft priority 99
136
+ @realtime soft memlock 102400
137
+ @realtime hard rtprio 99
138
+ @realtime hard priority 99
139
+ @realtime hard memlock 102400
140
+ ```
141
+
142
+ Log out and log in again to let the changes take effect.
143
+
144
+ To verify that the changes were applied, check if your user is in the `realtime` group:
145
+
146
+ ```bash
147
+ $ groups
148
+ ... realtime
149
+ ```
150
+
151
+ If realtime is not listed in your groups, try rebooting.
152
+
153
+ ### Installing franky
154
+
155
+ To start using franky with Python and libfranka *0.15.0*, just install it via
156
+
157
+ ```bash
158
+ pip install franky-control
159
+ ```
160
+
161
+ We also provide wheels for libfranka versions *0.7.1*, *0.8.0*, *0.9.2*, *0.10.0*, *0.11.0*, *0.12.1*, *0.13.3*,
162
+ *0.14.2*, and *0.15.0*.
163
+ They can be installed via
164
+
165
+ ```bash
166
+ VERSION=0-9-2
167
+ wget https://github.com/TimSchneider42/franky/releases/latest/download/libfranka_${VERSION}_wheels.zip
168
+ unzip libfranka_${VERSION}_wheels.zip
169
+ pip install numpy
170
+ pip install --no-index --find-links=./dist franky-control
171
+ ```
172
+
173
+ Franky is based on [libfranka](https://github.com/frankaemika/libfranka), [Eigen](https://eigen.tuxfamily.org) for
174
+ transformation calculations and [pybind11](https://github.com/pybind/pybind11) for the Python bindings.
175
+ As the Franka is sensitive to acceleration discontinuities, it requires jerk-constrained motion generation, for which
176
+ franky uses the [Ruckig](https://ruckig.com) community version for Online Trajectory Generation (OTG).
177
+
178
+ After installing the dependencies (the exact versions can be found [here](#-development)), you can build and install
179
+ franky via
180
+
181
+ ```bash
182
+ git clone --recurse-submodules git@github.com:timschneider42/franky.git
183
+ cd franky
184
+ mkdir -p build
185
+ cd build
186
+ cmake -DCMAKE_BUILD_TYPE=Release ..
187
+ make
188
+ make install
189
+ ```
190
+
191
+ To use franky, you can also include it as a subproject in your parent CMake via `add_subdirectory(franky)` and then
192
+ `target_link_libraries(<target> franky)`.
193
+
194
+ If you need only the Python module, you can install franky via
195
+
196
+ ```bash
197
+ pip install .
198
+ ```
199
+
200
+ Make sure that the built library `_franky.cpython-3**-****-linux-gnu.so` is in the Python path, e.g. by adjusting
201
+ `PYTHONPATH` accordingly.
202
+
203
+ #### Using Docker
204
+
205
+ To use franky within Docker we provide a [Dockerfile](docker/run/Dockerfile) and
206
+ accompanying [docker-compose](docker-compose.yml) file.
207
+
208
+ ```bash
209
+ git clone https://github.com/timschneider42/franky.git
210
+ cd franky/
211
+ docker compose build franky-run
212
+ ```
213
+
214
+ To use another version of libfranka than the default (0.15.0) add a build argument:
215
+
216
+ ```bash
217
+ docker compose build franky-run --build-arg LIBFRANKA_VERSION=0.9.2
218
+ ```
219
+
220
+ To run the container:
221
+
222
+ ```bash
223
+ docker compose run franky-run bash
224
+ ```
225
+
226
+ The container requires access to the host machines network *and* elevated user rights to allow the docker user to set RT
227
+ capabilities of the processes run from within it.
228
+
229
+ #### Building franky with Docker
230
+
231
+ For building franky and its wheels, we provide another Docker container that can also be launched using docker-compose:
232
+
233
+ ```bash
234
+ docker compose build franky-build
235
+ docker compose run --rm franky-build run-tests # To run the tests
236
+ docker compose run --rm franky-build build-wheels # To build wheels for all supported python versions
237
+ ```
238
+
239
+ ## 📚 Tutorial
240
+
241
+ Franky comes with both a C++ and Python API that differ only regarding real-time capability.
242
+ We will introduce both languages next to each other.
243
+ In your C++ project, just include `include <franky.hpp>` and link the library.
244
+ For Python, just `import franky`.
245
+ As a first example, only four lines of code are needed for simple robotic motions.
246
+
247
+ ```c++
248
+ #include <franky.hpp>
249
+ using namespace franky;
250
+
251
+ // Connect to the robot with the FCI IP address
252
+ Robot robot("172.16.0.2");
253
+
254
+ // Reduce velocity and acceleration of the robot
255
+ robot.setRelativeDynamicsFactor(0.05);
256
+
257
+ // Move the end-effector 20cm in positive x-direction
258
+ auto motion = std::make_shared<CartesianMotion>(RobotPose(Affine({0.2, 0.0, 0.0}), 0.0), ReferenceType::Relative);
259
+
260
+ // Finally move the robot
261
+ robot.move(motion);
262
+ ```
263
+
264
+ The corresponding program in Python is
265
+
266
+ ```python
267
+ from franky import Affine, CartesianMotion, Robot, ReferenceType
268
+
269
+ robot = Robot("172.16.0.2")
270
+ robot.relative_dynamics_factor = 0.05
271
+
272
+ motion = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)
273
+ robot.move(motion)
274
+ ```
275
+
276
+ Furthermore, we will introduce methods for geometric calculations, for moving the robot according to different motion
277
+ types, how to implement real-time reactions and changing waypoints in real time as well as controlling the gripper.
278
+
279
+ ### 🧮 Geometry
280
+
281
+ `franky.Affine` is a python wrapper for [Eigen::Affine3d](https://eigen.tuxfamily.org/dox/group__TutorialGeometry.html).
282
+ It is used for Cartesian poses, frames and transformation.
283
+ franky adds its own constructor, which takes a position and a quaternion as inputs:
284
+
285
+ ```python
286
+ import math
287
+ from scipy.spatial.transform import Rotation
288
+ from franky import Affine
289
+
290
+ z_translation = Affine([0.0, 0.0, 0.5])
291
+
292
+ quat = Rotation.from_euler("xyz", [0, 0, math.pi / 2]).as_quat()
293
+ z_rotation = Affine([0.0, 0.0, 0.0], quat)
294
+
295
+ combined_transformation = z_translation * z_rotation
296
+ ```
297
+
298
+ In all cases, distances are in [m] and rotations in [rad].
299
+
300
+ ### 🤖 Robot
301
+
302
+ Franky exposes most of the libfanka API for Python.
303
+ Moreover, we added methods to adapt the dynamics limits of the robot for all motions.
304
+
305
+ ```python
306
+ from franky import *
307
+
308
+ robot = Robot("172.16.0.2")
309
+
310
+ # Recover from errors
311
+ robot.recover_from_errors()
312
+
313
+ # Set velocity, acceleration and jerk to 5% of the maximum
314
+ robot.relative_dynamics_factor = 0.05
315
+
316
+ # Alternatively, you can define each constraint individually
317
+ robot.relative_dynamics_factor = RelativeDynamicsFactor(velocity=0.1, acceleration=0.05, jerk=0.1)
318
+
319
+ # Or, for more finegrained access, set individual limits
320
+ robot.translation_velocity_limit.set(3.0)
321
+ robot.rotation_velocity_limit.set(2.5)
322
+ robot.elbow_velocity_limit.set(2.62)
323
+ robot.translation_acceleration_limit.set(9.0)
324
+ robot.rotation_acceleration_limit.set(17.0)
325
+ robot.elbow_acceleration_limit.set(10.0)
326
+ robot.translation_jerk_limit.set(4500.0)
327
+ robot.rotation_jerk_limit.set(8500.0)
328
+ robot.elbow_jerk_limit.set(5000.0)
329
+ robot.joint_velocity_limit.set([2.62, 2.62, 2.62, 2.62, 5.26, 4.18, 5.26])
330
+ robot.joint_acceleration_limit.set([10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0])
331
+ robot.joint_jerk_limit.set([5000.0, 5000.0, 5000.0, 5000.0, 5000.0, 5000.0, 5000.0])
332
+ # By default, these limits are set to their respective maxima (the values shown here)
333
+
334
+ # Get the max of each limit (as provided by Franka) with the max function, e.g.:
335
+ print(robot.joint_jerk_limit.max)
336
+ ```
337
+
338
+ #### Robot State
339
+
340
+ The robot state can be retrieved by calling the following methods:
341
+
342
+ * `state`: Object of type `franky.RobotState`, which extends the
343
+ libfranka [franka::RobotState](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html) structure by
344
+ additional state elements.
345
+ * `current_cartesian_state`: Object of type `franky.CartesianState`, which contains the end-effector pose and velocity
346
+ obtained
347
+ from [franka::RobotState::O_T_EE](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html#a193781d47722b32925e0ea7ac415f442)
348
+ and [franka::RobotState::O_dP_EE_c](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html#a4be112bd1a9a7d777a67aea4a18a8dcc).
349
+ * `current_joint_position`: Object of type `franky.JointState`, which contains the joint positions and velocities
350
+ obtained
351
+ from [franka::RobotState::q](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html#ade3335d1ac2f6c44741a916d565f7091)
352
+ and [franka::RobotState::dq](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html#a706045af1b176049e9e56df755325bd2).
353
+
354
+ ```python
355
+ from franky import *
356
+
357
+ robot = Robot("172.16.0.2")
358
+
359
+ # Get the current state as `franky.RobotState`. See the documentation for a list of fields.
360
+ state = robot.state
361
+
362
+ # Get the robot's cartesian state
363
+ cartesian_state = robot.current_cartesian_state
364
+ robot_pose = cartesian_state.pose # Contains end-effector pose and elbow position
365
+ ee_pose = robot_pose.end_effector_pose
366
+ elbow_pos = robot_pose.elbow_position
367
+ robot_velocity = cartesian_state.velocity # Contains end-effector twist and elbow velocity
368
+ ee_twist = robot_velocity.end_effector_twist
369
+ elbow_vel = robot_velocity.elbow_velocity
370
+
371
+ # Get the robot's joint state
372
+ joint_state = robot.current_joint_state
373
+ joint_pos = joint_state.position
374
+ joint_vel = joint_state.velocity
375
+
376
+ # Use the robot model to compute kinematics
377
+ q = [-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7]
378
+ f_t_ee = Affine()
379
+ ee_t_k = Affine()
380
+ ee_pose_kin = robot.model.pose(Frame.EndEffector, q, f_t_ee, ee_t_k)
381
+
382
+ # Get the jacobian of the current robot state
383
+ jacobian = robot.model.body_jacobian(Frame.EndEffector, state)
384
+
385
+ # Alternatively, just get the URDF as string and do the kinematics computation yourself (only for libfranka >= 0.15.0)
386
+ urdf_model = robot.model_urdf
387
+ ```
388
+
389
+ For a full list of state-related features, check
390
+ the [Robot](https://timschneider42.github.io/franky/classfranky_1_1_robot.html)
391
+ and [Model](https://timschneider42.github.io/franky/classfranky_1_1_model.html) sections of the documentation.
392
+
393
+ ### 🏃‍♂️ Motion Types
394
+
395
+ Franky currently supports four different impedance control modes: **joint position control**, **joint velocity control
396
+ **, **cartesian position control**, and **cartesian velocity control**.
397
+ Each of these control modes is invoked by passing the robot an appropriate _Motion_ object.
398
+
399
+ In the following, we provide a brief example for each motion type implemented by Franky in Python.
400
+ The C++ interface is generally analogous, though some variable and method names are different because we
401
+ follow [PEP 8](https://peps.python.org/pep-0008/) naming conventions in Python
402
+ and [Google naming conventions](https://google.github.io/styleguide/cppguide.html) in C++.
403
+
404
+ All units are in $m$, $\frac{m}{s}$, $\textit{rad}$, or $\frac{\textit{rad}}{s}$.
405
+
406
+ #### Joint Position Control
407
+
408
+ ```python
409
+ from franky import *
410
+
411
+ # A point-to-point motion in the joint space
412
+ m_jp1 = JointMotion([-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7])
413
+
414
+ # A motion in joint space with multiple waypoints
415
+ m_jp2 = JointWaypointMotion([
416
+ JointWaypoint([-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7]),
417
+ JointWaypoint([0.0, 0.3, 0.3, -1.5, -0.2, 1.5, 0.8]),
418
+ JointWaypoint([0.1, 0.4, 0.3, -1.4, -0.3, 1.7, 0.9])
419
+ ])
420
+
421
+ # Intermediate waypoints also permit to specify target velocities. The default target velocity is 0, meaning that the
422
+ # robot will stop at every waypoint.
423
+ m_jp3 = JointWaypointMotion([
424
+ JointWaypoint([-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7]),
425
+ JointWaypoint(
426
+ JointState(
427
+ position=[0.0, 0.3, 0.3, -1.5, -0.2, 1.5, 0.8],
428
+ velocity=[0.1, 0.0, 0.0, 0.0, -0.0, 0.0, 0.0])),
429
+ JointWaypoint([0.1, 0.4, 0.3, -1.4, -0.3, 1.7, 0.9])
430
+ ])
431
+
432
+ # Stop the robot in joint position control mode. The difference of JointStopMotion to other stop motions such as
433
+ # CartesianStopMotion is that # JointStopMotion # stops the robot in joint position control mode while
434
+ # CartesianStopMotion stops it in cartesian pose control mode. The difference becomes relevant when asynchronous move
435
+ # commands are being sent or reactions are being used(see below).
436
+ m_jp4 = JointStopMotion()
437
+ ```
438
+
439
+ #### Joint Velocity Control
440
+
441
+ ```python
442
+ from franky import *
443
+
444
+ # Accelerate to the given joint velocity and hold it. After 1000ms stop the robot again.
445
+ m_jv1 = JointVelocityMotion([0.1, 0.3, -0.1, 0.0, 0.1, -0.2, 0.4], duration=Duration(1000))
446
+
447
+ # Joint velocity motions also support waypoints. Unlike in joint position control, a joint velocity waypoint is a
448
+ # target velocity to be reached. This particular example first accelerates the joints, holds the velocity for 1s, then
449
+ # reverses direction for 2s, reverses direction again for 1s, and finally stops. It is important not to forget to stop
450
+ # the robot at the end of such a sequence, as it will otherwise throw an error.
451
+ m_jv2 = JointVelocityWaypointMotion([
452
+ JointVelocityWaypoint([0.1, 0.3, -0.1, 0.0, 0.1, -0.2, 0.4], hold_target_duration=Duration(1000)),
453
+ JointVelocityWaypoint([-0.1, -0.3, 0.1, -0.0, -0.1, 0.2, -0.4], hold_target_duration=Duration(2000)),
454
+ JointVelocityWaypoint([0.1, 0.3, -0.1, 0.0, 0.1, -0.2, 0.4], hold_target_duration=Duration(1000)),
455
+ JointVelocityWaypoint([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
456
+ ])
457
+
458
+ # Stop the robot in joint velocity control mode.
459
+ m_jv3 = JointVelocityStopMotion()
460
+ ```
461
+
462
+ #### Cartesian Position Control
463
+
464
+ ```python
465
+ import math
466
+ from scipy.spatial.transform import Rotation
467
+ from franky import *
468
+
469
+ # Move to the given target pose
470
+ quat = Rotation.from_euler("xyz", [0, 0, math.pi / 2]).as_quat()
471
+ m_cp1 = CartesianMotion(Affine([0.4, -0.2, 0.3], quat))
472
+
473
+ # With target elbow angle (otherwise, the Franka firmware will choose by itself)
474
+ m_cp2 = CartesianMotion(RobotPose(Affine([0.4, -0.2, 0.3], quat), elbow_state=ElbowState(0.3)))
475
+
476
+ # A linear motion in cartesian space relative to the initial position
477
+ # (Note that this motion is relative both in position and orientation. Hence, when the robot's end-effector is oriented
478
+ # differently, it will move in a different direction)
479
+ m_cp3 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)
480
+
481
+ # Generalization of CartesianMotion that allows for multiple waypoints
482
+ m_cp4 = CartesianWaypointMotion([
483
+ CartesianWaypoint(RobotPose(Affine([0.4, -0.2, 0.3], quat), elbow_state=ElbowState(0.3))),
484
+ # The following waypoint is relative to the prior one and 50% slower
485
+ CartesianWaypoint(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative, RelativeDynamicsFactor(0.5, 1.0, 1.0))
486
+ ])
487
+
488
+ # Cartesian waypoints also permit to specify target velocities
489
+ m_cp5 = CartesianWaypointMotion([
490
+ CartesianWaypoint(Affine([0.5, -0.2, 0.3], quat)),
491
+ CartesianWaypoint(
492
+ CartesianState(
493
+ pose=Affine([0.4, -0.1, 0.3], quat),
494
+ velocity=Twist([-0.01, 0.01, 0.0]))),
495
+ CartesianWaypoint(Affine([0.3, 0.0, 0.3], quat))
496
+ ])
497
+
498
+ # Stop the robot in cartesian position control mode.
499
+ m_cp6 = CartesianStopMotion()
500
+ ```
501
+
502
+ #### Cartesian Velocity Control
503
+
504
+ ```python
505
+ from franky import *
506
+
507
+ # A cartesian velocity motion with linear (first argument) and angular (second argument) components
508
+ m_cv1 = CartesianVelocityMotion(Twist([0.2, -0.1, 0.1], [0.1, -0.1, 0.2]))
509
+
510
+ # With target elbow velocity
511
+ m_cv2 = CartesianVelocityMotion(RobotVelocity(Twist([0.2, -0.1, 0.1], [0.1, -0.1, 0.2]), elbow_velocity=-0.2))
512
+
513
+ # Cartesian velocity motions also support multiple waypoints. Unlike in cartesian position control, a cartesian velocity
514
+ # waypoint is a target velocity to be reached. This particular example first accelerates the end-effector, holds the
515
+ # velocity for 1s, then # reverses direction for 2s, reverses direction again for 1s, and finally stops. It is important
516
+ # not to forget to stop # the robot at the end of such a sequence, as it will otherwise throw an error.
517
+ m_cv4 = CartesianVelocityWaypointMotion([
518
+ CartesianVelocityWaypoint(Twist([0.2, -0.1, 0.1], [0.1, -0.1, 0.2]), hold_target_duration=Duration(1000)),
519
+ CartesianVelocityWaypoint(Twist([-0.2, 0.1, -0.1], [-0.1, 0.1, -0.2]), hold_target_duration=Duration(2000)),
520
+ CartesianVelocityWaypoint(Twist([0.2, -0.1, 0.1], [0.1, -0.1, 0.2]), hold_target_duration=Duration(1000)),
521
+ CartesianVelocityWaypoint(Twist()),
522
+ ])
523
+
524
+ # Stop the robot in cartesian velocity control mode.
525
+ m_cv6 = CartesianVelocityStopMotion()
526
+ ```
527
+
528
+ #### Relative Dynamics Factors
529
+
530
+ Every motion and waypoint type allows to adapt the dynamics (velocity, acceleration and jerk) by setting the respective
531
+ `relative_dynamics_factor` parameter.
532
+ This parameter can also be set for the robot globally as shown below or in the `robot.move` command.
533
+ Crucially, relative dynamics factors on different layers (robot, move command, and motion) do not override each other
534
+ but rather get multiplied.
535
+ Hence, a relative dynamics factor on a motion can only reduce the dynamics of the robot and never increase them.
536
+
537
+ There is one exception to this rule and that is if any layer sets the relative dynamics factor to
538
+ `RelativeDynamicsFactor.MAX_DYNAMICS`.
539
+ This will cause the motion to be executed with maximum velocity, acceleration, and jerk limits, independently of the
540
+ relative dynamics factors of the other layers.
541
+ This feature should only be used to abruptly stop the robot in case of an unexpected environment contact as executing
542
+ other motions with it is likely to lead to a discontinuity error and might be dangerous.
543
+
544
+ #### Executing Motions
545
+
546
+ The real robot can be moved by applying a motion to the robot using `move`:
547
+
548
+ ```python
549
+ # Before moving the robot, set an appropriate dynamics factor. We start small:
550
+ robot.relative_dynamics_factor = 0.05
551
+ # or alternatively, to control the scaling of velocity, acceleration, and jerk limits separately:
552
+ robot.relative_dynamics_factor = RelativeDynamicsFactor(0.05, 0.1, 0.15)
553
+ # If these values are set too high, you will see discontinuity errors
554
+
555
+ robot.move(m_jp1)
556
+
557
+ # We can also set a relative dynamics factor in the move command. It will be multiplied with the other relative
558
+ # dynamics factors (robot and motion if present).
559
+ robot.move(m_jp2, relative_dynamics_factor=0.8)
560
+ ```
561
+
562
+ #### Motion Callbacks
563
+
564
+ All motions support callbacks, which will be invoked in every control step at 1kHz.
565
+ Callbacks can be attached as follows:
566
+
567
+ ```python
568
+ def cb(
569
+ robot_state: RobotState,
570
+ time_step: Duration,
571
+ rel_time: Duration,
572
+ abs_time: Duration,
573
+ control_signal: JointPositions):
574
+ print(f"At time {abs_time}, the target joint positions were {control_signal.q}")
575
+
576
+
577
+ m_jp1.register_callback(cb)
578
+ robot.move(m_jp1)
579
+ ```
580
+
581
+ Note that in Python, these callbacks are not executed in the control thread since they would otherwise block it.
582
+ Instead, they are put in a queue and executed by another thread.
583
+ While this scheme ensures that the control thread can always run, it cannot prevent that the queue grows indefinitely
584
+ when the callbacks take more time to execute than it takes for new callbacks to be queued.
585
+ Hence, callbacks might be executed significantly after they were queued if they take a long time to execute.
586
+
587
+ ### ⚡ Real-Time Reactions
588
+
589
+ By adding reactions to the motion data, the robot can react to unforeseen events.
590
+ In the Python API, you can define conditions by using a comparison between a robot's value and a given threshold.
591
+ If the threshold is exceeded, the reaction fires.
592
+
593
+ ```python
594
+ from franky import CartesianMotion, Affine, ReferenceType, Measure, Reaction
595
+
596
+ motion = CartesianMotion(Affine([0.0, 0.0, 0.1]), ReferenceType.Relative) # Move down 10cm
597
+
598
+ # It is important that the reaction motion uses the same control mode as the original motion. Hence, we cannot register
599
+ # a JointMotion as a reaction motion to a CartesianMotion.
600
+ reaction_motion = CartesianMotion(Affine([0.0, 0.0, 0.01]), ReferenceType.Relative) # Move up for 1cm
601
+
602
+ # Trigger reaction if the Z force is greater than 30N
603
+ reaction = Reaction(Measure.FORCE_Z > 30.0, reaction_motion)
604
+ motion.add_reaction(reaction)
605
+
606
+ robot.move(motion)
607
+ ```
608
+
609
+ Possible values to measure are
610
+
611
+ * `Measure.FORCE_X,` `Measure.FORCE_Y,` `Measure.FORCE_Z`: Force in X, Y and Z direction
612
+ * `Measure.REL_TIME`: Time in seconds since the current motion started
613
+ * `Measure.ABS_TIME`: Time in seconds since the initial motion started
614
+
615
+ The difference between `Measure.REL_TIME` and `Measure.ABS_TIME` is that `Measure.REL_TIME` is reset to zero whenever a
616
+ new motion starts (either by calling `Robot.move` or as a result of a triggered `Reaction`).
617
+ `Measure.ABS_TIME`, on the other hand, is only reset to zero when a motion terminates regularly without being
618
+ interrupted and the robot stops moving.
619
+ Hence, `Measure.ABS_TIME` measures the total time in which the robot has moved without interruption.
620
+
621
+ `Measure` values support all classical arithmetic operations, like addition, subtraction, multiplication, division, and
622
+ exponentiation (both as base and exponent).
623
+
624
+ ```python
625
+ normal_force = (Measure.FORCE_X ** 2 + Measure.FORCE_Y ** 2 + Measure.FORCE_Z ** 2) ** 0.5
626
+ ```
627
+
628
+ With arithmetic comparisons, conditions can be generated.
629
+
630
+ ```python
631
+ normal_force_within_bounds = normal_force < 30.0
632
+ time_up = Measure.ABS_TIME > 10.0
633
+ ```
634
+
635
+ Conditions support negation, conjunction (and), and disjunction (or):
636
+
637
+ ```python
638
+ abort = ~normal_force_within_bounds | time_up
639
+ fast_abort = ~normal_force_within_bounds | time_up
640
+ ```
641
+
642
+ To check whether a reaction has fired, a callback can be attached:
643
+
644
+ ```python
645
+ from franky import RobotState
646
+
647
+
648
+ def reaction_callback(robot_state: RobotState, rel_time: float, abs_time: float):
649
+ print(f"Reaction fired at {abs_time}.")
650
+
651
+
652
+ reaction.register_callback(reaction_callback)
653
+ ```
654
+
655
+ Similar to the motion callbacks, in Python, reaction callbacks are not executed in real-time but in a regular thread
656
+ with lower priority to ensure that the control thread does not get blocked.
657
+ Thus, the callbacks might fire substantially after the reaction has fired, depending on the time it takes to execute
658
+ them.
659
+
660
+ In C++ you can additionally use lambdas to define more complex behaviours:
661
+
662
+ ```c++
663
+ auto motion = CartesianMotion(RobotPose(Affine({0.0, 0.0, 0.2}), 0.0), ReferenceType::Relative);
664
+
665
+ // Stop motion if force is over 10N
666
+ auto stop_motion = StopMotion<franka::CartesianPose>()
667
+
668
+ motion
669
+ .addReaction(
670
+ Reaction(
671
+ Measure::ForceZ() > 10.0, // [N],
672
+ stop_motion))
673
+ .addReaction(
674
+ Reaction(
675
+ Condition(
676
+ [](const franka::RobotState& state, double rel_time, double abs_time) {
677
+ // Lambda condition
678
+ return state.current_errors.self_collision_avoidance_violation;
679
+ }),
680
+ [](const franka::RobotState& state, double rel_time, double abs_time) {
681
+ // Lambda reaction motion generator
682
+ // (we are just returning a stop motion, but there could be arbitrary
683
+ // logic here for generating reaction motions)
684
+ return StopMotion<franka::CartesianPose>();
685
+ })
686
+ ));
687
+
688
+ robot.move(motion)
689
+ ```
690
+
691
+ ### ⏱️ Real-Time Motions
692
+
693
+ By setting the `asynchronous` parameter of `Robot.move` to `True`, the function does not block until the motion
694
+ finishes.
695
+ Instead, it returns immediately and, thus, allows the main thread to set new motions asynchronously.
696
+
697
+ ```python
698
+ import time
699
+ from franky import Affine, CartesianMotion, Robot, ReferenceType
700
+
701
+ robot = Robot("172.16.0.2")
702
+ robot.relative_dynamics_factor = 0.05
703
+
704
+ motion1 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)
705
+ robot.move(motion1, asynchronous=True)
706
+
707
+ time.sleep(0.5)
708
+ # Note that similar to reactions, when preempting active motions with new motions, the control mode cannot change.
709
+ # Hence, we cannot use, e.g., a JointMotion here.
710
+ motion2 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)
711
+ robot.move(motion2, asynchronous=True)
712
+ ```
713
+
714
+ By calling `Robot.join_motion` the main thread can be synchronized with the motion thread, as it will block until the
715
+ robot finishes its motion.
716
+
717
+ ```python
718
+ robot.join_motion()
719
+ ```
720
+
721
+ Note that when exceptions occur during the asynchronous execution of a motion, they will not be thrown immediately.
722
+ Instead, the control thread stores the exception and terminates.
723
+ The next time `Robot.join_motion` or `Robot.move` are called, they will throw the stored exception in the main thread.
724
+ Hence, after an asynchronous motion has finished, make sure to call `Robot.join_motion` to ensure being notified of any
725
+ exceptions that occurred during the motion.
726
+
727
+ ### Gripper
728
+
729
+ In the `franky::Gripper` class, the default gripper force and gripper speed can be set.
730
+ Then, additionally to the libfranka commands, the following helper methods can be used:
731
+
732
+ ```c++
733
+ #include <franky.hpp>
734
+ #include <chrono>
735
+ #include <future>
736
+
737
+ auto gripper = franky::Gripper("172.16.0.2");
738
+
739
+ double speed = 0.02; // [m/s]
740
+ double force = 20.0; // [N]
741
+
742
+ // Move the fingers to a specific width (5cm)
743
+ bool success = gripper.move(0.05, speed);
744
+
745
+ // Grasp an object of unknown width
746
+ success &= gripper.grasp(0.0, speed, force, epsilon_outer=1.0);
747
+
748
+ // Get the width of the grasped object
749
+ double width = gripper.width();
750
+
751
+ // Release the object
752
+ gripper.open(speed);
753
+
754
+ // There are also asynchronous versions of the methods
755
+ std::future<bool> success_future = gripper.moveAsync(0.05, speed);
756
+
757
+ // Wait for 1s
758
+ if (!success_future.wait_for(std::chrono::seconds(1)) == std::future_status::ready) {
759
+ // Get the result
760
+ std::cout << "Success: " << success_future.get() << std::endl;
761
+ } else {
762
+ gripper.stop();
763
+ success_future.wait();
764
+ std::cout << "Gripper motion timed out." << std::endl;
765
+ }
766
+ ```
767
+
768
+ The Python API follows the c++ API closely:
769
+
770
+ ```python
771
+ import franky
772
+
773
+ gripper = franky.Gripper("172.16.0.2")
774
+
775
+ speed = 0.02 # [m/s]
776
+ force = 20.0 # [N]
777
+
778
+ # Move the fingers to a specific width (5cm)
779
+ success = gripper.move(0.05, speed)
780
+
781
+ # Grasp an object of unknown width
782
+ success &= gripper.grasp(0.0, speed, force, epsilon_outer=1.0)
783
+
784
+ # Get the width of the grasped object
785
+ width = gripper.width
786
+
787
+ # Release the object
788
+ gripper.open(speed)
789
+
790
+ # There are also asynchronous versions of the methods
791
+ success_future = gripper.move_async(0.05, speed)
792
+
793
+ # Wait for 1s
794
+ if success_future.wait(1):
795
+ print(f"Success: {success_future.get()}")
796
+ else:
797
+ gripper.stop()
798
+ success_future.wait()
799
+ print("Gripper motion timed out.")
800
+ ```
801
+
802
+ ## 🛠️ Development
803
+
804
+ Franky is currently tested against following versions
805
+
806
+ - libfranka 0.7.1, 0.8.0, 0.9.2, 0.10.0, 0.11.0, 0.12.1, 0.13.3, 0.14.2, 0.15.0
807
+ - Eigen 3.4.0
808
+ - Pybind11 2.13.6
809
+ - Pinocchio 3.4.0
810
+ - Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13
811
+ - Catch2 2.13.8 (for testing only)
812
+
813
+ ## 📜 License
814
+
815
+ For non-commercial applications, this software is licensed under the LGPL v3.0.
816
+ If you want to use franky within commercial applications or under a different license, please contact us for individual
817
+ agreements.
818
+
819
+ ## 🔍 Differences to frankx
820
+
821
+ Franky started originally as a fork of [frankx](https://github.com/pantor/frankx), though both codebase and
822
+ functionality differ substantially from frankx by now.
823
+ Aside of bug fixes and general performance improvements, Franky provides the following new features/improvements:
824
+
825
+ * [Motions can be updated asynchronously.](#-real-time-motions)
826
+ * [Reactions allow for the registration of callbacks instead of just printing to stdout when fired.](#-real-time-reactions)
827
+ * [Motions allow for the registration of callbacks for profiling.](#motion-callbacks)
828
+ * [The robot state is also available during control.](#robot-state)
829
+ * A larger part of the libfranka API is exposed to python (e.g.,`setCollisionBehavior`, `setJoinImpedance`, and
830
+ `setCartesianImpedance`).
831
+ * Cartesian motion generation handles boundaries in Euler angles properly.
832
+ * [There is a new joint motion type that supports waypoints.](#-motion-types)
833
+ * [The signature of `Affine` changed.](#-geometry) `Affine` does not handle elbow positions anymore.
834
+ Instead, a new class `RobotPose` stores both the end-effector pose and optionally the elbow position.
835
+ * The `MotionData` class does not exist anymore.
836
+ Instead, reactions and other settings moved to `Motion`.
837
+ * [The `Measure` class allows for arithmetic operations.](#-real-time-reactions)
838
+ * Exceptions caused by libfranka are raised properly instead of being printed to stdout.
839
+ * [We provide wheels for both Franka Research 3 and the older Franka Panda](#-setup)
840
+ * Franky supports [joint velocity control](#joint-velocity-control)
841
+ and [cartesian velocity control](#cartesian-velocity-control)
842
+ * The dynamics limits are not hard-coded anymore but can be [set for each robot instance](#-robot).