Skip to content

Commit f2d852a

Browse files
Updated Gripper instructions in README
1 parent 06da172 commit f2d852a

File tree

1 file changed

+59
-15
lines changed

1 file changed

+59
-15
lines changed

README.md

+59-15
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ docker compose run --rm franky-build build-wheels # To build wheels for all sup
167167

168168
## Tutorial
169169

170-
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.
170+
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.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.
171171

172172
```c++
173-
#include <franky/franky.hpp>
173+
#include <franky.hpp>
174174
using namespace franky;
175175

176176
// Connect to the robot with the FCI IP address
@@ -482,29 +482,73 @@ In the `franky::Gripper` class, the default gripper force and gripper speed can
482482
Then, additionally to the libfranka commands, the following helper methods can be used:
483483

484484
```c++
485-
auto gripper = Gripper("172.16.0.2");
485+
#include <franky.hpp>
486+
#include <chrono>
487+
#include <future>
486488

487-
// These are the default values
488-
gripper.gripper_speed = 0.02; // [m/s]
489-
gripper.gripper_force = 20.0; // [N]
489+
auto gripper = franky::Gripper("172.16.0.2");
490490

491-
// Preshape gripper before grasp, use the given speed
492-
gripper.move(0.05); // [m]
491+
double speed = 0.02; // [m/s]
492+
double force = 20.0; // [N]
493+
494+
// Move the fingers to a specific width (5cm)
495+
bool success = gripper.move(0.05, speed, force);
493496

494497
// Grasp an object of unknown width
495-
is_grasping = gripper.clamp();
498+
success &= gripper.grasp(0.0, speed, force, epsilon_outer=1.0);
499+
500+
// Get the width of the grasped object
501+
double width = gripper.width();
502+
503+
// Release the object
504+
gripper.open(speed);
496505

497-
// Do something
498-
is_grasping &= gripper.isGrasping();
506+
// There are also asynchronous versions of the methods
507+
std::future<bool> success_future = gripper.moveAsync(0.05, speed, force);
499508

500-
// Release an object and move to a given distance
501-
if (is_grasping) {
502-
gripper.release(0.05);
509+
// Wait for 1s
510+
if (!success_future.wait_for(std::chrono::seconds(1)) == std::future_status::ready) {
511+
// Get the result
512+
std::cout << "Success: " << success_future.get() << std::endl;
513+
} else {
514+
gripper.stop();
515+
success_future.wait();
516+
std::cout << "Gripper motion timed out." << std::endl;
503517
}
504518
```
505519

506-
The Python API is straight-forward for the Gripper class.
520+
The Python API follows the c++ API closely:
521+
```python
522+
import franky
523+
524+
gripper = franky.Gripper("172.16.0.2")
525+
526+
speed = 0.02 # [m/s]
527+
force = 20.0 # [N]
507528

529+
# Move the fingers to a specific width (5cm)
530+
success = gripper.move(0.05, speed, force)
531+
532+
# Grasp an object of unknown width
533+
success &= gripper.grasp(0.0, speed, force, epsilon_outer=1.0)
534+
535+
# Get the width of the grasped object
536+
width = gripper.width()
537+
538+
# Release the object
539+
gripper.open(speed)
540+
541+
# There are also asynchronous versions of the methods
542+
success_future = gripper.move_async(0.05, speed, force)
543+
544+
# Wait for 1s
545+
if success_future.wait(1):
546+
print(f"Success: {success_future.get()}")
547+
else:
548+
gripper.stop()
549+
success_future.wait()
550+
print("Gripper motion timed out.")
551+
```
508552

509553
## Documentation
510554

0 commit comments

Comments
 (0)