franky-panda


Namefranky-panda JSON
Version 0.8.0 PyPI version JSON
download
home_pagehttps://github.com/TimSchneider42/franky
SummaryHigh-Level Motion Library for the Franka Panda Robot (fork of frankx)
upload_time2024-02-02 17:50:16
maintainer
docs_urlNone
authorTim Schneider
requires_python>=3.6
licenseLGPL
keywords robot robotics trajectory-generation motion-control
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
  <img width="340" src="https://raw.githubusercontent.com/timschneider42/franky/master/doc/logo.svg?sanitize=true">
  <h3 align="center">
    High-Level Motion Library for the Franka Emika Robot
  </h3>
</div>
<p align="center">
  <a href="https://github.com/timschneider42/franky/actions">
    <img src="https://github.com/timschneider42/franky/workflows/CI/badge.svg" alt="CI">
  </a>

  <a href="https://github.com/timschneider42/franky/actions">
    <img src="https://github.com/timschneider42/franky/workflows/Publish/badge.svg" alt="Publish">
  </a>

  <a href="https://github.com/timschneider42/franky/issues">
    <img src="https://img.shields.io/github/issues/timschneider42/franky.svg" alt="Issues">
  </a>

  <a href="https://github.com/timschneider42/franky/releases">
    <img src="https://img.shields.io/github/v/release/timschneider42/franky.svg?include_prereleases&sort=semver" alt="Releases">
  </a>

  <a href="https://github.com/timschneider42/franky/blob/master/LICENSE">
    <img src="https://img.shields.io/badge/license-LGPL-green.svg" alt="LGPL">
  </a>
</p>


Franky is a high-level motion library (both C++ and Python) for the Franka Emika robot.
It adds a Python wrapper around [libfranka](https://frankaemika.github.io/docs/libfranka.html), while replacing necessary real-time programming with higher-level motion commands.
As franky focuses on making real-time trajectory generation easy, it allows the robot to react to unforeseen events.


## Differences to frankx
Franky is a fork of [frankx](https://github.com/pantor/frankx), though both codebase and functionality differ substantially from frankx by now.
In particular, franky provides the following new features/improvements:
* [Motions can be updated asynchronously.](#real-time-motion)
* [Reactions allow for the registration of callbacks instead of just printing to stdout when fired.](#real-time-reactions)
* [The robot state is also available during control.](#robot-state)
* A larger part of the libfranka API is exposed to python (e.g.,`setCollisionBehavior`, `setJoinImpedance`, and `setCartesianImpedance`).
* Cartesian motion generation handles boundaries in Euler angles properly.
* [There is a new joint motion type that supports waypoints.](#motion-types)
* [The signature of `Affine` changed.](#geometry) `Affine` does not handle elbow positions anymore. Instead, a new class `RobotPose` stores both the end-effector pose and optionally the elbow position.
* The `MotionData` class does not exist anymore. Instead, reactions and other settings moved to `Motion`.
* [The `Measure` class allows for arithmetic operations.](#real-time-reactions)
* Exceptions caused by libfranka are raised properly instead of being printed to stdout.
* [We provide wheels for both Franka Research 3 and the older Franka Panda](#installation)

## Installation

To start using franky with Python and libfranka *0.12.1*, just install it via
```bash
pip install franky-panda
```
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*. 
They can be installed via
```bash
VERSION=0-9-2
wget https://github.com/TimSchneider42/franky/releases/latest/download/libfranka_${VERSION}_wheels.zip
unzip libfranka_${VERSION}_wheels.zip
pip install --no-index --find-links=./dist franky-panda
```

Franky is based on [libfranka](https://github.com/frankaemika/libfranka), [Eigen](https://eigen.tuxfamily.org) for transformation calculations and [pybind11](https://github.com/pybind/pybind11) for the Python bindings.
Franky uses the [Ruckig](https://ruckig.com) Community Version for Online Trajectory Generation (OTG).
As the Franka is quite sensitive to acceleration discontinuities, it requires constrained jerk for all motions.
After installing the dependencies (the exact versions can be found below), you can build and install franky via

```bash
git clone --recurse-submodules git@github.com:timschneider42/franky.git
cd franky
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
make install
```

To use franky, you can also include it as a subproject in your parent CMake via `add_subdirectory(franky)` and then `target_link_libraries(<target> libfranky)`. If you need only the Python module, you can install franky via

```bash
pip install .
```

Make sure that the built library can be found from Python by adapting your Python Path.


#### Using Docker

To use franky within Docker we have supplied a [Dockerfile](docker/Dockerfile) which you currently need to build yourself:

```bash
git clone https://github.com/timschneider42/franky.git
cd franky/
docker build -t franky --build-arg libfranka_version=0.7.0 -f docker/Dockerfile .
```

To use another version of libfranka than the default (v.0.7.0) simply change the build argument. Then, to run the container simply:

```bash
docker run -it --rm --network=host --privileged franky
```

The container requires access to the host machines network *and* elevated user rights to allow the docker user to set RT capabilities of the processes run from within it.


## Tutorial

Franky comes with both a C++ and Python API that differ only regarding real-time capability. We will introduce both languages next to each other. In your C++ project, just include `include <franky/franky.hpp>` and link the library. For Python, just `import franky`. As a first example, only four lines of code are needed for simple robotic motions.

```c++
#include <franky/franky.hpp>
using namespace franky;

// Connect to the robot with the FCI IP address
Robot robot("172.16.0.2");

// Reduce velocity and acceleration of the robot
robot.setDynamicRel(0.05);

// Move the end-effector 20cm in positive x-direction
auto motion = CartesianMotion(RobotPose(Affine({0.2, 0.0, 0.0}), 0.0), ReferenceType::Relative);

// Finally move the robot
robot.move(motion);
```

The corresponding program in Python is
```python
from franky import Affine, CartesianMotion, Robot, ReferenceType

robot = Robot("172.16.0.2")
robot.relative_dynamics_factor = 0.05

motion = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)
robot.move(motion)
```

Furthermore, we will introduce methods for geometric calculations, for moving the robot according to different motion types, how to implement real-time reactions and changing waypoints in real time as well as controlling the gripper.


### Geometry

`franky.Affine` is a python wrapper for [Eigen::Affine3d](https://eigen.tuxfamily.org/dox/group__TutorialGeometry.html). 
It is used for Cartesian poses, frames and transformation. 
franky adds its own constructor, which takes a position and a quaternion as inputs:
```python
import math
from scipy.spatial.transform import Rotation
from franky import Affine

z_translation = Affine([0.0, 0.0, 0.5])

quat = Rotation.from_euler("xyz", [0, 0, math.pi / 2]).as_quat()
z_rotation = Affine([0.0, 0.0, 0.0], quat)

combined_transformation = z_translation * z_rotation
```

In all cases, distances are in [m] and rotations in [rad].

### Robot

We wrapped most of the libfanka API (including the RobotState or ErrorMessage) for Python. 
Moreover, we added methods to adapt the dynamics of the robot for all motions. 
The `rel` name denotes that this a factor of the maximum constraints of the robot.
```python
from franky import Robot

robot = Robot("172.16.0.2")

# Recover from errors
robot.recover_from_errors()

# Set velocity, acceleration and jerk to 5% of the maximum
robot.relative_dynamics_factor = 0.05

# Alternatively, you can define each constraint individually
robot.velocity_rel = 0.2
robot.acceleration_rel = 0.1
robot.jerk_rel = 0.01

# Get the current pose
current_pose = robot.current_pose
```


### Robot State

The robot state can be retrieved by calling the following methods:

* `state`: Return an object of the `franky.RobotState` class which contains most of the same attributes, under the same name, as the libfranka [franka::RobotState](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html) definition.

* `current_pose`: Return a 3D Affine transformation object of the measured end effector pose in base frame (alias for [franka::RobotState::O_T_EE](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html#a193781d47722b32925e0ea7ac415f442)).

* `current_joint_positions`: Return a sequence of the manipulator arm's 7-joint positions (alias for [franka::RobotState::q](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html#ade3335d1ac2f6c44741a916d565f7091)).

```.py
robot = Robot("172.16.0.2")

# Get the current state
state = robot.state
pose = robot.current_pose
joint_positions = robot.current_joint_positions
```


### Motion Types

Franky defines a number of different motion types. 
In python, you can use them as follows:
```python
import math
from scipy.spatial.transform import Rotation
from franky import JointWaypointMotion, JointWaypoint, JointPositionStopMotion, CartesianMotion, CartesianWaypointMotion, CartesianWaypoint, Affine, RobotPose, ReferenceType, CartesianPoseStopMotion

# A point-to-point motion in the joint space
m1 = JointWaypointMotion([JointWaypoint([-1.8, 1.1, 1.7, -2.1, -1.1, 1.6, -0.4])])

# A motion in joint space with multiple waypoints
m2 = JointWaypointMotion([
    JointWaypoint([-1.8, 1.1, 1.7, -2.1, -1.1, 1.6, -0.4]),
    JointWaypoint([-1.7, 1.2, 1.8, -2.0, -1.0, 1.7, -0.3]),
    JointWaypoint([-1.9, 1.0, 1.6, -2.2, -1.2, 1.5, -0.5])
])

# Stop the robot
m3 = JointPositionStopMotion()

# A linear motion in cartesian space
quat = Rotation.from_euler("xyz", [0, 0, math.pi / 2]).as_quat()
m4 = CartesianMotion(Affine([0.2, -0.4, 0.3], quat))
m5 = CartesianMotion(RobotPose(Affine([0.2, -0.4, 0.3], quat), elbow_position=1.7)) # With target elbow angle

# A linear motion in cartesian space relative to the initial position
# (Note that this motion is relative both in position and orientation. Hence, when the robot's end-effector is oriented
# differently, it will move in a different direction)
m6 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)

# Generalization of CartesianMotion that allows for multiple waypoints
m7 = CartesianWaypointMotion([
  CartesianWaypoint(RobotPose(Affine([0.2, -0.4, 0.3], quat), elbow_position=1.7)),
  # The following waypoint is relative to the prior one and 50% slower
  CartesianWaypoint(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative, velocity_rel=0.5)
])

# Stop the robot. The difference of JointPositionStopMotion to CartesianPoseStopMotion is that JointPositionStopMotion
# stops the robot in joint position control mode while CartesianPoseStopMotion stops it in cartesian pose control mode.
# The difference becomes relevant when asynchronous move commands are being sent (see below).
m8 = CartesianPoseStopMotion()
```

Every motion and waypoint type allows to adapt the dynamics (velocity, acceleration and jerk) by setting the respective `velocity_rel`, `acceleration_rel`, and `jerk_rel` parameters.

The real robot can be moved by applying a motion to the robot using `move`:
```python
robot.move(m1)
robot.move(m2)
```


### Real-Time Reactions

By adding reactions to the motion data, the robot can react to unforeseen events. 
In the Python API, you can define conditions by using a comparison between a robot's value and a given threshold. 
If the threshold is exceeded, the reaction fires. 
```python
from franky import CartesianMotion, Affine, ReferenceType, Measure, Reaction

motion = CartesianMotion(Affine([0.0, 0.0, 0.1]), ReferenceType.Relative)  # Move down 10cm

reaction_motion = CartesianMotion(Affine([0.0, 0.0, 0.01]), ReferenceType.Relative)  # Move up for 1cm

# Trigger reaction if the Z force is greater than 30N
reaction = Reaction(Measure.FORCE_Z > 30.0, reaction_motion)
motion.add_reaction(reaction)

robot.move(motion)
```

Possible values to measure are
* `Measure.FORCE_X,` `Measure.FORCE_Y,` `Measure.FORCE_Z`: Force in X, Y and Z direction
* `Measure.REL_TIME`: Time in seconds since the current motion started
* `Measure.ABS_TIME`: Time in seconds since the initial motion started

The difference between `Measure.REL_TIME` and `Measure.ABS_TIME` is that `Measure.REL_TIME` is reset to zero whenever a new motion starts (either by calling `Robot.move` or as a result of a triggered `Reaction`).
`Measure.ABS_TIME`, on the other hand, is only reset to zero when a motion terminates regularly without being interrupted and the robot stops moving.
Hence, `Measure.ABS_TIME` measures the total time in which the robot has moved without interruption.

`Measure` values support all classical arithmetic operations, like addition, subtraction, multiplication, division, and exponentiation (both as base and exponent).
```python
normal_force = (Measure.FORCE_X ** 2 + Measure.FORCE_Y ** 2 + Measure.FORCE_Z ** 2) ** 0.5
```

With arithmetic comparisons, conditions can be generated.
```python
normal_force_within_bounds = normal_force < 30.0
time_up = Measure.ABS_TIME > 10.0
```

Conditions support negation, conjunction (and), and disjunction (or):
```python
abort = ~normal_force_within_bounds | time_up
fast_abort = ~normal_force_within_bounds | time_up
```

To check whether a reaction has fired, a callback can be attached:
```python
from franky import RobotState

def reaction_callback(robot_state: RobotState, rel_time: float, abs_time: float):
    print(f"Reaction fired at {abs_time}.")

reaction.register_callback(reaction_callback)
```

Note that these callbacks are not executed in the control thread since they would otherwise block it.
Instead, they are put in a queue and executed by another thread.
While this scheme ensures that the control thread can always run, it cannot prevent that the queue grows indefinitely when the callbacks take more time to execute than it takes for new callbacks to be queued.
Hence, callbacks might be executed significantly after their respective reaction has fired if they are triggered in rapid succession or take a long time to execute.

In C++ you can additionally use lambdas to define more complex behaviours:
```c++
auto motion = CartesianMotion(RobotPose(Affine({0.0, 0.0, 0.2}), 0.0), ReferenceType::Relative);

// Stop motion if force is over 10N
auto stop_motion = StopMotion<franka::CartesianPose>()

motion
  .addReaction(
    Reaction(
      Measure::ForceZ() > 10.0,  // [N],
      stop_motion))
  .addReaction(
    Reaction(
      Condition(
        [](const franka::RobotState& state, double rel_time, double abs_time) {
          // Lambda condition
          return state.current_errors.self_collision_avoidance_violation;
        }),
      [](const franka::RobotState& state, double rel_time, double abs_time) {
        // Lambda reaction motion generator
        // (we are just returning a stop motion, but there could be arbitrary 
        // logic here for generating reaction motions)
        return StopMotion<franka::CartesianPose>();
      })
    ));

robot.move(motion)
```


### Real-Time Motion

By setting the `asynchronous` parameter of `Robot.move` to `True`, the function does not block until the motion finishes.
Instead, it returns immediately and, thus, allows the main thread to set new motions asynchronously. 
```python
import time
from franky import Affine, CartesianMotion, Robot, ReferenceType

robot = Robot("172.16.0.2")
robot.relative_dynamics_factor = 0.05

motion1 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)
robot.move(motion1, asynchronous=True)

time.sleep(0.5)
motion2 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)
robot.move(motion2, asynchronous=True)
```

By calling `Robot.join_motion` the main thread can be synchronized with the motion thread, as it will block until the robot finishes its motion.
```python
robot.join_motion()
```

Note that when exceptions occur during the asynchronous execution of a motion, they will not be thrown immediately.
Instead, the control thread stores the exception and terminates.
The next time `Robot.join_motion` or `Robot.move` are called, they will throw the stored exception in the main thread.
Hence, after an asynchronous motion has finished, make sure to call `Robot.join_motion` to ensure being notified of any exceptions that occurred during the motion.


### Gripper

In the `franky::Gripper` class, the default gripper force and gripper speed can be set. 
Then, additionally to the libfranka commands, the following helper methods can be used:

```c++
auto gripper = Gripper("172.16.0.2");

// These are the default values
gripper.gripper_speed = 0.02; // [m/s]
gripper.gripper_force = 20.0; // [N]

// Preshape gripper before grasp, use the given speed
gripper.move(50.0); // [mm]

// Grasp an object of unknown width
is_grasping = gripper.clamp();

// Do something
is_grasping &= gripper.isGrasping();

// Release an object and move to a given distance
if (is_grasping) {
  gripper.release(50.0);
}
```

The Python API is straight-forward for the Gripper class.


## Documentation

An auto-generated documentation can be found at [https://timschneider42.github.io/franky/](https://timschneider42.github.io/franky/).
Moreover, there are multiple examples for both C++ and Python in the [examples](https://github.com/TimSchneider42/franky/tree/master/examples) directory. 


## Development

Franky is written in C++17 and Python3.7. It is currently tested against following versions

- Eigen v3.3.7
- Libfranka v0.12.1
- Pybind11 v2.9.1
- Catch2 v2.13 (only for testing)


## License

For non-commercial applications, this software is licensed under the LGPL v3.0. 
If you want to use franky within commercial applications or under a different license, please contact us for individual agreements.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TimSchneider42/franky",
    "name": "franky-panda",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "robot,robotics,trajectory-generation,motion-control",
    "author": "Tim Schneider",
    "author_email": "tim@robot-learning.de",
    "download_url": "",
    "platform": null,
    "description": "<div align=\"center\">\n  <img width=\"340\" src=\"https://raw.githubusercontent.com/timschneider42/franky/master/doc/logo.svg?sanitize=true\">\n  <h3 align=\"center\">\n    High-Level Motion Library for the Franka Emika Robot\n  </h3>\n</div>\n<p align=\"center\">\n  <a href=\"https://github.com/timschneider42/franky/actions\">\n    <img src=\"https://github.com/timschneider42/franky/workflows/CI/badge.svg\" alt=\"CI\">\n  </a>\n\n  <a href=\"https://github.com/timschneider42/franky/actions\">\n    <img src=\"https://github.com/timschneider42/franky/workflows/Publish/badge.svg\" alt=\"Publish\">\n  </a>\n\n  <a href=\"https://github.com/timschneider42/franky/issues\">\n    <img src=\"https://img.shields.io/github/issues/timschneider42/franky.svg\" alt=\"Issues\">\n  </a>\n\n  <a href=\"https://github.com/timschneider42/franky/releases\">\n    <img src=\"https://img.shields.io/github/v/release/timschneider42/franky.svg?include_prereleases&sort=semver\" alt=\"Releases\">\n  </a>\n\n  <a href=\"https://github.com/timschneider42/franky/blob/master/LICENSE\">\n    <img src=\"https://img.shields.io/badge/license-LGPL-green.svg\" alt=\"LGPL\">\n  </a>\n</p>\n\n\nFranky is a high-level motion library (both C++ and Python) for the Franka Emika robot.\nIt adds a Python wrapper around [libfranka](https://frankaemika.github.io/docs/libfranka.html), while replacing necessary real-time programming with higher-level motion commands.\nAs franky focuses on making real-time trajectory generation easy, it allows the robot to react to unforeseen events.\n\n\n## Differences to frankx\nFranky is a fork of [frankx](https://github.com/pantor/frankx), though both codebase and functionality differ substantially from frankx by now.\nIn particular, franky provides the following new features/improvements:\n* [Motions can be updated asynchronously.](#real-time-motion)\n* [Reactions allow for the registration of callbacks instead of just printing to stdout when fired.](#real-time-reactions)\n* [The robot state is also available during control.](#robot-state)\n* A larger part of the libfranka API is exposed to python (e.g.,`setCollisionBehavior`, `setJoinImpedance`, and `setCartesianImpedance`).\n* Cartesian motion generation handles boundaries in Euler angles properly.\n* [There is a new joint motion type that supports waypoints.](#motion-types)\n* [The signature of `Affine` changed.](#geometry) `Affine` does not handle elbow positions anymore. Instead, a new class `RobotPose` stores both the end-effector pose and optionally the elbow position.\n* The `MotionData` class does not exist anymore. Instead, reactions and other settings moved to `Motion`.\n* [The `Measure` class allows for arithmetic operations.](#real-time-reactions)\n* Exceptions caused by libfranka are raised properly instead of being printed to stdout.\n* [We provide wheels for both Franka Research 3 and the older Franka Panda](#installation)\n\n## Installation\n\nTo start using franky with Python and libfranka *0.12.1*, just install it via\n```bash\npip install franky-panda\n```\nWe 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*. \nThey can be installed via\n```bash\nVERSION=0-9-2\nwget https://github.com/TimSchneider42/franky/releases/latest/download/libfranka_${VERSION}_wheels.zip\nunzip libfranka_${VERSION}_wheels.zip\npip install --no-index --find-links=./dist franky-panda\n```\n\nFranky is based on [libfranka](https://github.com/frankaemika/libfranka), [Eigen](https://eigen.tuxfamily.org) for transformation calculations and [pybind11](https://github.com/pybind/pybind11) for the Python bindings.\nFranky uses the [Ruckig](https://ruckig.com) Community Version for Online Trajectory Generation (OTG).\nAs the Franka is quite sensitive to acceleration discontinuities, it requires constrained jerk for all motions.\nAfter installing the dependencies (the exact versions can be found below), you can build and install franky via\n\n```bash\ngit clone --recurse-submodules git@github.com:timschneider42/franky.git\ncd franky\nmkdir -p build\ncd build\ncmake -DCMAKE_BUILD_TYPE=Release ..\nmake\nmake install\n```\n\nTo use franky, you can also include it as a subproject in your parent CMake via `add_subdirectory(franky)` and then `target_link_libraries(<target> libfranky)`. If you need only the Python module, you can install franky via\n\n```bash\npip install .\n```\n\nMake sure that the built library can be found from Python by adapting your Python Path.\n\n\n#### Using Docker\n\nTo use franky within Docker we have supplied a [Dockerfile](docker/Dockerfile) which you currently need to build yourself:\n\n```bash\ngit clone https://github.com/timschneider42/franky.git\ncd franky/\ndocker build -t franky --build-arg libfranka_version=0.7.0 -f docker/Dockerfile .\n```\n\nTo use another version of libfranka than the default (v.0.7.0) simply change the build argument. Then, to run the container simply:\n\n```bash\ndocker run -it --rm --network=host --privileged franky\n```\n\nThe container requires access to the host machines network *and* elevated user rights to allow the docker user to set RT capabilities of the processes run from within it.\n\n\n## Tutorial\n\nFranky comes with both a C++ and Python API that differ only regarding real-time capability. We will introduce both languages next to each other. In your C++ project, just include `include <franky/franky.hpp>` and link the library. For Python, just `import franky`. As a first example, only four lines of code are needed for simple robotic motions.\n\n```c++\n#include <franky/franky.hpp>\nusing namespace franky;\n\n// Connect to the robot with the FCI IP address\nRobot robot(\"172.16.0.2\");\n\n// Reduce velocity and acceleration of the robot\nrobot.setDynamicRel(0.05);\n\n// Move the end-effector 20cm in positive x-direction\nauto motion = CartesianMotion(RobotPose(Affine({0.2, 0.0, 0.0}), 0.0), ReferenceType::Relative);\n\n// Finally move the robot\nrobot.move(motion);\n```\n\nThe corresponding program in Python is\n```python\nfrom franky import Affine, CartesianMotion, Robot, ReferenceType\n\nrobot = Robot(\"172.16.0.2\")\nrobot.relative_dynamics_factor = 0.05\n\nmotion = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)\nrobot.move(motion)\n```\n\nFurthermore, we will introduce methods for geometric calculations, for moving the robot according to different motion types, how to implement real-time reactions and changing waypoints in real time as well as controlling the gripper.\n\n\n### Geometry\n\n`franky.Affine` is a python wrapper for [Eigen::Affine3d](https://eigen.tuxfamily.org/dox/group__TutorialGeometry.html). \nIt is used for Cartesian poses, frames and transformation. \nfranky adds its own constructor, which takes a position and a quaternion as inputs:\n```python\nimport math\nfrom scipy.spatial.transform import Rotation\nfrom franky import Affine\n\nz_translation = Affine([0.0, 0.0, 0.5])\n\nquat = Rotation.from_euler(\"xyz\", [0, 0, math.pi / 2]).as_quat()\nz_rotation = Affine([0.0, 0.0, 0.0], quat)\n\ncombined_transformation = z_translation * z_rotation\n```\n\nIn all cases, distances are in [m] and rotations in [rad].\n\n### Robot\n\nWe wrapped most of the libfanka API (including the RobotState or ErrorMessage) for Python. \nMoreover, we added methods to adapt the dynamics of the robot for all motions. \nThe `rel` name denotes that this a factor of the maximum constraints of the robot.\n```python\nfrom franky import Robot\n\nrobot = Robot(\"172.16.0.2\")\n\n# Recover from errors\nrobot.recover_from_errors()\n\n# Set velocity, acceleration and jerk to 5% of the maximum\nrobot.relative_dynamics_factor = 0.05\n\n# Alternatively, you can define each constraint individually\nrobot.velocity_rel = 0.2\nrobot.acceleration_rel = 0.1\nrobot.jerk_rel = 0.01\n\n# Get the current pose\ncurrent_pose = robot.current_pose\n```\n\n\n### Robot State\n\nThe robot state can be retrieved by calling the following methods:\n\n* `state`: Return an object of the `franky.RobotState` class which contains most of the same attributes, under the same name, as the libfranka [franka::RobotState](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html) definition.\n\n* `current_pose`: Return a 3D Affine transformation object of the measured end effector pose in base frame (alias for [franka::RobotState::O_T_EE](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html#a193781d47722b32925e0ea7ac415f442)).\n\n* `current_joint_positions`: Return a sequence of the manipulator arm's 7-joint positions (alias for [franka::RobotState::q](https://frankaemika.github.io/libfranka/structfranka_1_1RobotState.html#ade3335d1ac2f6c44741a916d565f7091)).\n\n```.py\nrobot = Robot(\"172.16.0.2\")\n\n# Get the current state\nstate = robot.state\npose = robot.current_pose\njoint_positions = robot.current_joint_positions\n```\n\n\n### Motion Types\n\nFranky defines a number of different motion types. \nIn python, you can use them as follows:\n```python\nimport math\nfrom scipy.spatial.transform import Rotation\nfrom franky import JointWaypointMotion, JointWaypoint, JointPositionStopMotion, CartesianMotion, CartesianWaypointMotion, CartesianWaypoint, Affine, RobotPose, ReferenceType, CartesianPoseStopMotion\n\n# A point-to-point motion in the joint space\nm1 = JointWaypointMotion([JointWaypoint([-1.8, 1.1, 1.7, -2.1, -1.1, 1.6, -0.4])])\n\n# A motion in joint space with multiple waypoints\nm2 = JointWaypointMotion([\n    JointWaypoint([-1.8, 1.1, 1.7, -2.1, -1.1, 1.6, -0.4]),\n    JointWaypoint([-1.7, 1.2, 1.8, -2.0, -1.0, 1.7, -0.3]),\n    JointWaypoint([-1.9, 1.0, 1.6, -2.2, -1.2, 1.5, -0.5])\n])\n\n# Stop the robot\nm3 = JointPositionStopMotion()\n\n# A linear motion in cartesian space\nquat = Rotation.from_euler(\"xyz\", [0, 0, math.pi / 2]).as_quat()\nm4 = CartesianMotion(Affine([0.2, -0.4, 0.3], quat))\nm5 = CartesianMotion(RobotPose(Affine([0.2, -0.4, 0.3], quat), elbow_position=1.7)) # With target elbow angle\n\n# A linear motion in cartesian space relative to the initial position\n# (Note that this motion is relative both in position and orientation. Hence, when the robot's end-effector is oriented\n# differently, it will move in a different direction)\nm6 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)\n\n# Generalization of CartesianMotion that allows for multiple waypoints\nm7 = CartesianWaypointMotion([\n  CartesianWaypoint(RobotPose(Affine([0.2, -0.4, 0.3], quat), elbow_position=1.7)),\n  # The following waypoint is relative to the prior one and 50% slower\n  CartesianWaypoint(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative, velocity_rel=0.5)\n])\n\n# Stop the robot. The difference of JointPositionStopMotion to CartesianPoseStopMotion is that JointPositionStopMotion\n# stops the robot in joint position control mode while CartesianPoseStopMotion stops it in cartesian pose control mode.\n# The difference becomes relevant when asynchronous move commands are being sent (see below).\nm8 = CartesianPoseStopMotion()\n```\n\nEvery motion and waypoint type allows to adapt the dynamics (velocity, acceleration and jerk) by setting the respective `velocity_rel`, `acceleration_rel`, and `jerk_rel` parameters.\n\nThe real robot can be moved by applying a motion to the robot using `move`:\n```python\nrobot.move(m1)\nrobot.move(m2)\n```\n\n\n### Real-Time Reactions\n\nBy adding reactions to the motion data, the robot can react to unforeseen events. \nIn the Python API, you can define conditions by using a comparison between a robot's value and a given threshold. \nIf the threshold is exceeded, the reaction fires. \n```python\nfrom franky import CartesianMotion, Affine, ReferenceType, Measure, Reaction\n\nmotion = CartesianMotion(Affine([0.0, 0.0, 0.1]), ReferenceType.Relative)  # Move down 10cm\n\nreaction_motion = CartesianMotion(Affine([0.0, 0.0, 0.01]), ReferenceType.Relative)  # Move up for 1cm\n\n# Trigger reaction if the Z force is greater than 30N\nreaction = Reaction(Measure.FORCE_Z > 30.0, reaction_motion)\nmotion.add_reaction(reaction)\n\nrobot.move(motion)\n```\n\nPossible values to measure are\n* `Measure.FORCE_X,` `Measure.FORCE_Y,` `Measure.FORCE_Z`: Force in X, Y and Z direction\n* `Measure.REL_TIME`: Time in seconds since the current motion started\n* `Measure.ABS_TIME`: Time in seconds since the initial motion started\n\nThe difference between `Measure.REL_TIME` and `Measure.ABS_TIME` is that `Measure.REL_TIME` is reset to zero whenever a new motion starts (either by calling `Robot.move` or as a result of a triggered `Reaction`).\n`Measure.ABS_TIME`, on the other hand, is only reset to zero when a motion terminates regularly without being interrupted and the robot stops moving.\nHence, `Measure.ABS_TIME` measures the total time in which the robot has moved without interruption.\n\n`Measure` values support all classical arithmetic operations, like addition, subtraction, multiplication, division, and exponentiation (both as base and exponent).\n```python\nnormal_force = (Measure.FORCE_X ** 2 + Measure.FORCE_Y ** 2 + Measure.FORCE_Z ** 2) ** 0.5\n```\n\nWith arithmetic comparisons, conditions can be generated.\n```python\nnormal_force_within_bounds = normal_force < 30.0\ntime_up = Measure.ABS_TIME > 10.0\n```\n\nConditions support negation, conjunction (and), and disjunction (or):\n```python\nabort = ~normal_force_within_bounds | time_up\nfast_abort = ~normal_force_within_bounds | time_up\n```\n\nTo check whether a reaction has fired, a callback can be attached:\n```python\nfrom franky import RobotState\n\ndef reaction_callback(robot_state: RobotState, rel_time: float, abs_time: float):\n    print(f\"Reaction fired at {abs_time}.\")\n\nreaction.register_callback(reaction_callback)\n```\n\nNote that these callbacks are not executed in the control thread since they would otherwise block it.\nInstead, they are put in a queue and executed by another thread.\nWhile this scheme ensures that the control thread can always run, it cannot prevent that the queue grows indefinitely when the callbacks take more time to execute than it takes for new callbacks to be queued.\nHence, callbacks might be executed significantly after their respective reaction has fired if they are triggered in rapid succession or take a long time to execute.\n\nIn C++ you can additionally use lambdas to define more complex behaviours:\n```c++\nauto motion = CartesianMotion(RobotPose(Affine({0.0, 0.0, 0.2}), 0.0), ReferenceType::Relative);\n\n// Stop motion if force is over 10N\nauto stop_motion = StopMotion<franka::CartesianPose>()\n\nmotion\n  .addReaction(\n    Reaction(\n      Measure::ForceZ() > 10.0,  // [N],\n      stop_motion))\n  .addReaction(\n    Reaction(\n      Condition(\n        [](const franka::RobotState& state, double rel_time, double abs_time) {\n          // Lambda condition\n          return state.current_errors.self_collision_avoidance_violation;\n        }),\n      [](const franka::RobotState& state, double rel_time, double abs_time) {\n        // Lambda reaction motion generator\n        // (we are just returning a stop motion, but there could be arbitrary \n        // logic here for generating reaction motions)\n        return StopMotion<franka::CartesianPose>();\n      })\n    ));\n\nrobot.move(motion)\n```\n\n\n### Real-Time Motion\n\nBy setting the `asynchronous` parameter of `Robot.move` to `True`, the function does not block until the motion finishes.\nInstead, it returns immediately and, thus, allows the main thread to set new motions asynchronously. \n```python\nimport time\nfrom franky import Affine, CartesianMotion, Robot, ReferenceType\n\nrobot = Robot(\"172.16.0.2\")\nrobot.relative_dynamics_factor = 0.05\n\nmotion1 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)\nrobot.move(motion1, asynchronous=True)\n\ntime.sleep(0.5)\nmotion2 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative)\nrobot.move(motion2, asynchronous=True)\n```\n\nBy calling `Robot.join_motion` the main thread can be synchronized with the motion thread, as it will block until the robot finishes its motion.\n```python\nrobot.join_motion()\n```\n\nNote that when exceptions occur during the asynchronous execution of a motion, they will not be thrown immediately.\nInstead, the control thread stores the exception and terminates.\nThe next time `Robot.join_motion` or `Robot.move` are called, they will throw the stored exception in the main thread.\nHence, after an asynchronous motion has finished, make sure to call `Robot.join_motion` to ensure being notified of any exceptions that occurred during the motion.\n\n\n### Gripper\n\nIn the `franky::Gripper` class, the default gripper force and gripper speed can be set. \nThen, additionally to the libfranka commands, the following helper methods can be used:\n\n```c++\nauto gripper = Gripper(\"172.16.0.2\");\n\n// These are the default values\ngripper.gripper_speed = 0.02; // [m/s]\ngripper.gripper_force = 20.0; // [N]\n\n// Preshape gripper before grasp, use the given speed\ngripper.move(50.0); // [mm]\n\n// Grasp an object of unknown width\nis_grasping = gripper.clamp();\n\n// Do something\nis_grasping &= gripper.isGrasping();\n\n// Release an object and move to a given distance\nif (is_grasping) {\n  gripper.release(50.0);\n}\n```\n\nThe Python API is straight-forward for the Gripper class.\n\n\n## Documentation\n\nAn auto-generated documentation can be found at [https://timschneider42.github.io/franky/](https://timschneider42.github.io/franky/).\nMoreover, there are multiple examples for both C++ and Python in the [examples](https://github.com/TimSchneider42/franky/tree/master/examples) directory. \n\n\n## Development\n\nFranky is written in C++17 and Python3.7. It is currently tested against following versions\n\n- Eigen v3.3.7\n- Libfranka v0.12.1\n- Pybind11 v2.9.1\n- Catch2 v2.13 (only for testing)\n\n\n## License\n\nFor non-commercial applications, this software is licensed under the LGPL v3.0. \nIf you want to use franky within commercial applications or under a different license, please contact us for individual agreements.\n",
    "bugtrack_url": null,
    "license": "LGPL",
    "summary": "High-Level Motion Library for the Franka Panda Robot (fork of frankx)",
    "version": "0.8.0",
    "project_urls": {
        "Homepage": "https://github.com/TimSchneider42/franky"
    },
    "split_keywords": [
        "robot",
        "robotics",
        "trajectory-generation",
        "motion-control"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "15883b1ccfa7a6e524b1f5b25e04b700a5cbb6564b47d8d33d78b23fe58004aa",
                "md5": "602a2a07c9a8fa9a5cbcd95c65b043be",
                "sha256": "bfdcc0e8bdecaaef370f369acd74b8012cda695ca0fe0181e9b877bf417de1b0"
            },
            "downloads": -1,
            "filename": "franky_panda-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "602a2a07c9a8fa9a5cbcd95c65b043be",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.6",
            "size": 2449409,
            "upload_time": "2024-02-02T17:50:16",
            "upload_time_iso_8601": "2024-02-02T17:50:16.254233Z",
            "url": "https://files.pythonhosted.org/packages/15/88/3b1ccfa7a6e524b1f5b25e04b700a5cbb6564b47d8d33d78b23fe58004aa/franky_panda-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "db58eec4b85c4e00e5aa570c5e4eaba22a3b7a39f25145319d7a012a8c428420",
                "md5": "cceb834b099670ae2ba916acd55d9851",
                "sha256": "172e7ad2d3bb48d6c5b2318c0e1d5186886c427743df340b65689964bf8e677f"
            },
            "downloads": -1,
            "filename": "franky_panda-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "cceb834b099670ae2ba916acd55d9851",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.6",
            "size": 2450690,
            "upload_time": "2024-02-02T17:50:19",
            "upload_time_iso_8601": "2024-02-02T17:50:19.745249Z",
            "url": "https://files.pythonhosted.org/packages/db/58/eec4b85c4e00e5aa570c5e4eaba22a3b7a39f25145319d7a012a8c428420/franky_panda-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "31e829275f5b5ce534dbd9efe0276145cb3671eeec1174079eaf69b8281310e0",
                "md5": "56df3b74008db5ba762618759931c06d",
                "sha256": "af296e3e3346a9d311098c39ca006df0d383a2e6acef9c540072ef871b532cfc"
            },
            "downloads": -1,
            "filename": "franky_panda-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "56df3b74008db5ba762618759931c06d",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.6",
            "size": 2453971,
            "upload_time": "2024-02-02T17:50:22",
            "upload_time_iso_8601": "2024-02-02T17:50:22.409139Z",
            "url": "https://files.pythonhosted.org/packages/31/e8/29275f5b5ce534dbd9efe0276145cb3671eeec1174079eaf69b8281310e0/franky_panda-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "900703661fa7af4d76bcb98c2357d421e686d074c36031d3a32de3f218aea564",
                "md5": "da6f7ac51cc431100b8a86135904f715",
                "sha256": "d93dafd98f6d26476f41f930f54f3cb063c99d90830b963fc3c477b651664738"
            },
            "downloads": -1,
            "filename": "franky_panda-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "da6f7ac51cc431100b8a86135904f715",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.6",
            "size": 2449161,
            "upload_time": "2024-02-02T17:50:24",
            "upload_time_iso_8601": "2024-02-02T17:50:24.280484Z",
            "url": "https://files.pythonhosted.org/packages/90/07/03661fa7af4d76bcb98c2357d421e686d074c36031d3a32de3f218aea564/franky_panda-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f5d9f9c6686d9a7a78a56ae5a0c037ea70ebfeb56795235418b0f71e19f2756b",
                "md5": "df56b162f5e5cfc1266db91243b15998",
                "sha256": "53ff5b737df174dfcadd3df075f52d78f7ba766a8eecc7d642ff6b9494adea84"
            },
            "downloads": -1,
            "filename": "franky_panda-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "df56b162f5e5cfc1266db91243b15998",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.6",
            "size": 2448490,
            "upload_time": "2024-02-02T17:50:27",
            "upload_time_iso_8601": "2024-02-02T17:50:27.297826Z",
            "url": "https://files.pythonhosted.org/packages/f5/d9/f9c6686d9a7a78a56ae5a0c037ea70ebfeb56795235418b0f71e19f2756b/franky_panda-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-02 17:50:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TimSchneider42",
    "github_project": "franky",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "franky-panda"
}
        
Elapsed time: 0.18628s