An example showing how to control FRANKA's gripper.
#include <iostream>
#include <visp3/core/vpConfig.h>
#ifdef VISP_HAVE_FRANKA
#include <sstream>
#include <string>
#include <thread>
#include <franka/exception.h>
#include <franka/gripper.h>
int main(int argc, char **argv)
{
if (argc != 4) {
std::cerr << "Usage: ./grasp_object <gripper-hostname> <homing> <object-width>" << std::endl;
return -1;
}
try {
franka::Gripper gripper(argv[1]);
double grasping_width = std::stod(argv[3]);
std::stringstream ss(argv[2]);
bool homing;
if (!(ss >> homing)) {
std::cerr << "<homing> can be 0 or 1." << std::endl;
return -1;
}
if (homing) {
gripper.homing();
}
franka::GripperState gripper_state = gripper.readOnce();
if (gripper_state.max_width < grasping_width) {
std::cout << "Object is too large for the current fingers on the gripper." << std::endl;
return -1;
}
if (!gripper.grasp(grasping_width, 0.1, 300)) {
std::cout << "Failed to grasp object." << std::endl;
return -1;
}
std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(3000));
gripper_state = gripper.readOnce();
if (!gripper_state.is_grasped) {
std::cout << "Object lost." << std::endl;
return -1;
}
std::cout << "Grasped object, will release it now." << std::endl;
gripper.stop();
} catch (franka::Exception const &e) {
std::cout << e.what() << std::endl;
return -1;
}
return 0;
}
#else
int main() { std::cout << "This example needs libfranka to control Panda robot." << std::endl; }
#endif