43 #include <visp3/core/vpConfig.h>
44 #include <visp3/robot/vpRobotFranka.h>
46 #if defined(VISP_HAVE_FRANKA)
59 int main(
int argc,
char **argv)
61 #ifdef ENABLE_VISP_NAMESPACE
65 std::string opt_robot_ip =
"192.168.1.1";
66 double opt_grasping_width = 0.;
67 GripperState_t opt_gripper_state = Gripper_None;
69 for (
int i = 1; i < argc; i++) {
70 if (std::string(argv[i]) ==
"--ip" && i + 1 < argc) {
71 opt_robot_ip = std::string(argv[i + 1]);
73 else if (std::string(argv[i]) ==
"--home") {
74 opt_gripper_state = Gripper_Home;
76 else if (std::string(argv[i]) ==
"--open") {
77 opt_gripper_state = Gripper_Open;
79 else if (std::string(argv[i]) ==
"--close") {
80 opt_gripper_state = Gripper_Close;
82 else if (std::string(argv[i]) ==
"--grasp" && i + 1 < argc) {
83 opt_gripper_state = Gripper_Grasp;
84 opt_grasping_width = std::atof(argv[i + 1]);
86 else if (std::string(argv[i]) ==
"--test" && i + 1 < argc) {
87 opt_gripper_state = Gripper_Test;
88 opt_grasping_width = std::atof(argv[i + 1]);
90 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
91 std::cout <<
"Control Panda gripper." << std::endl;
92 std::cout << argv[0] <<
" [--ip <default " << opt_robot_ip
93 <<
">] [--home] [--open] [--close] [--grasp <object width in meter>] [--release] [--test <object width "
94 "in meter>] [--help] [-h]\n"
96 std::cout <<
"Example to grasp a 4cm width object by first opening the gripper, then grasping the object :\n"
97 << argv[0] <<
" --ip 192.168.100.1 --open\n"
98 << argv[0] <<
" --ip 192.168.100.1 --grasp 0.04\n"
105 if (opt_gripper_state == Gripper_None) {
106 std::cout <<
"Specify which action you want to achieve. Run \"" << argv[0]
107 <<
" --help\" to see how to use this binary." << std::endl;
110 else if ((opt_gripper_state == Gripper_Grasp || opt_gripper_state == Gripper_Test) && opt_grasping_width <= 0) {
111 std::cout <<
"Object with in meter should be > 0. Run \"" << argv[0] <<
" --help\" to see how to use this binary."
119 robot.connect(opt_robot_ip);
121 if (opt_gripper_state == Gripper_Home) {
122 std::cout <<
"Gripper homing..." << std::endl;
123 robot.gripperHoming();
125 else if (opt_gripper_state == Gripper_Close) {
126 std::cout <<
"Gripper closing..." << std::endl;
127 robot.gripperClose();
129 else if (opt_gripper_state == Gripper_Open) {
130 std::cout <<
"Gripper opening..." << std::endl;
133 else if (opt_gripper_state == Gripper_Grasp) {
134 std::cout <<
"Gripper grasp " << opt_grasping_width <<
"m object width..." << std::endl;
135 robot.gripperGrasp(opt_grasping_width);
137 else if (opt_gripper_state == Gripper_Release) {
138 std::cout <<
"Gripper release object..." << std::endl;
139 robot.gripperRelease();
141 else if (opt_gripper_state == Gripper_Test) {
142 std::cout <<
"Test gripper performing the following actions:" << std::endl;
143 std::cout <<
"- Gripper homing..." << std::endl;
144 robot.gripperHoming();
146 std::cout <<
"- Gripper closing..." << std::endl;
147 robot.gripperClose();
149 std::cout <<
"- Gripper open 5cm..." << std::endl;
150 robot.gripperMove(0.05);
152 std::cout <<
"- Gripper opening..." << std::endl;
155 std::cout <<
"- Gripper grasp " << opt_grasping_width <<
"m object width..." << std::endl;
156 robot.gripperGrasp(opt_grasping_width);
158 std::cout <<
"- Gripper release object..." << std::endl;
159 robot.gripperRelease();
161 std::cout <<
"The end!" << std::endl;
164 std::cout <<
"ViSP exception: " << e.
what() << std::endl;
167 catch (
const franka::NetworkException &e) {
168 std::cout <<
"Franka network exception: " << e.what() << std::endl;
169 std::cout <<
"Check if you are connected to the Franka robot"
170 <<
" or if you specified the right IP using --ip command line option set by default to 192.168.1.1. "
174 catch (
const std::exception &e) {
175 std::cout <<
"Franka exception: " << e.what() << std::endl;
184 #if !defined(VISP_HAVE_FRANKA)
185 std::cout <<
"Install libfranka 3rd party, configure and build again ViSP to use this example..." << std::endl;
error that can be emitted by ViSP classes.
const char * what() const
VISP_EXPORT void sleepMs(double t)