43 #include <visp3/robot/vpRobotFranka.h> 45 #if defined(VISP_HAVE_FRANKA) 57 int main(
int argc,
char **argv)
59 std::string opt_robot_ip =
"192.168.1.1";
60 double opt_grasping_width = 0.;
61 GripperState_t opt_gripper_state = Gripper_None;
63 for (
int i = 1; i < argc; i++) {
64 if (std::string(argv[i]) ==
"--ip" && i + 1 < argc) {
65 opt_robot_ip = std::string(argv[i + 1]);
67 else if (std::string(argv[i]) ==
"--home") {
68 opt_gripper_state = Gripper_Home;
70 else if (std::string(argv[i]) ==
"--open") {
71 opt_gripper_state = Gripper_Open;
72 }
else if (std::string(argv[i]) ==
"--close") {
73 opt_gripper_state = Gripper_Close;
74 }
else if (std::string(argv[i]) ==
"--grasp" && i + 1 < argc) {
75 opt_gripper_state = Gripper_Grasp;
76 opt_grasping_width = std::atof(argv[i + 1]);
77 }
else if (std::string(argv[i]) ==
"--test" && i + 1 < argc) {
78 opt_gripper_state = Gripper_Test;
79 opt_grasping_width = std::atof(argv[i + 1]);
81 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
82 std::cout <<
"Control Panda gripper." << std::endl;
83 std::cout << argv[0] <<
" [--ip <default " << opt_robot_ip <<
">] [--home] [--open] [--close] [--grasp <object width in meter>] [--release] [--test <object width in meter>] [--help] [-h]\n" << std::endl;
84 std::cout <<
"Example to grasp a 4cm width object by first opening the gripper, then grasping the object :\n" 85 << argv[0] <<
" --ip 192.168.100.1 --open\n" 86 << argv[0] <<
" --ip 192.168.100.1 --grasp 0.04\n" << std::endl;
92 if (opt_gripper_state == Gripper_None) {
93 std::cout <<
"Specify which action you want to achieve. Run \"" << argv[0] <<
" --help\" to see how to use this binary." << std::endl;
95 }
else if ((opt_gripper_state == Gripper_Grasp || opt_gripper_state == Gripper_Test) && opt_grasping_width <= 0) {
96 std::cout <<
"Object with in meter should be > 0. Run \"" << argv[0] <<
" --help\" to see how to use this binary." << std::endl;
105 if (opt_gripper_state == Gripper_Home) {
106 std::cout <<
"Gripper homing..." << std::endl;
109 else if (opt_gripper_state == Gripper_Close) {
110 std::cout <<
"Gripper closing..." << std::endl;
113 else if (opt_gripper_state == Gripper_Open) {
114 std::cout <<
"Gripper opening..." << std::endl;
117 else if (opt_gripper_state == Gripper_Grasp) {
118 std::cout <<
"Gripper grasp " << opt_grasping_width <<
"m object width..." << std::endl;
121 else if (opt_gripper_state == Gripper_Release) {
122 std::cout <<
"Gripper release object..." << std::endl;
125 else if (opt_gripper_state == Gripper_Test) {
126 std::cout <<
"Test gripper performing the following actions:" << std::endl;
127 std::cout <<
"- Gripper homing..." << std::endl;
130 std::cout <<
"- Gripper closing..." << std::endl;
133 std::cout <<
"- Gripper open 5cm..." << std::endl;
136 std::cout <<
"- Gripper opening..." << std::endl;
139 std::cout <<
"- Gripper grasp " << opt_grasping_width <<
"m object width..." << std::endl;
142 std::cout <<
"- Gripper release object..." << std::endl;
145 std::cout <<
"The end!" << std::endl;
148 std::cout <<
"ViSP exception: " << e.
what() << std::endl;
151 catch(
const franka::NetworkException &e) {
152 std::cout <<
"Franka network exception: " << e.what() << std::endl;
153 std::cout <<
"Check if you are connected to the Franka robot" 154 <<
" or if you specified the right IP using --ip command line option set by default to 192.168.1.1. " << std::endl;
157 catch(
const std::exception &e) {
158 std::cout <<
"Franka exception: " << e.what() << std::endl;
167 #if !defined(VISP_HAVE_FRANKA) 168 std::cout <<
"Install libfranka 3rd party, configure and build again ViSP to use this example..." << std::endl;
int gripperMove(double width)
error that can be emited by ViSP classes.
int gripperGrasp(double grasping_width, double force=60.)
VISP_EXPORT void sleepMs(double t)
const char * what() const
void connect(const std::string &franka_address, franka::RealtimeConfig realtime_config=franka::RealtimeConfig::kEnforce)