41 #include <visp3/core/vpConfig.h>
42 #include <visp3/robot/vpRobotFranka.h>
44 #if defined(VISP_HAVE_FRANKA)
57 int main(
int argc,
char **argv)
59 #ifdef ENABLE_VISP_NAMESPACE
63 std::string opt_robot_ip =
"192.168.1.1";
64 double opt_grasping_width = 0.;
65 double opt_grasping_speed = 0.1;
66 double opt_grasping_force = 60;
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) {
72 opt_robot_ip = std::string(argv[i]);
74 else if (std::string(argv[i]) ==
"--home") {
75 opt_gripper_state = Gripper_Home;
77 else if (std::string(argv[i]) ==
"--open") {
78 opt_gripper_state = Gripper_Open;
80 else if (std::string(argv[i]) ==
"--close") {
81 opt_gripper_state = Gripper_Close;
83 else if (std::string(argv[i]) ==
"--release") {
84 opt_gripper_state = Gripper_Release;
86 else if (std::string(argv[i]) ==
"--grasp" && i + 1 < argc) {
88 opt_gripper_state = Gripper_Grasp;
89 opt_grasping_width = std::atof(argv[i]);
91 else if (std::string(argv[i]) ==
"--grasp-speed" && i + 1 < argc) {
93 opt_grasping_speed = std::atof(argv[i]);
95 else if (std::string(argv[i]) ==
"--grasp-force" && i + 1 < argc) {
97 opt_grasping_force = std::atof(argv[i]);
99 else if (std::string(argv[i]) ==
"--test" && i + 1 < argc) {
101 opt_gripper_state = Gripper_Test;
102 opt_grasping_width = std::atof(argv[i]);
104 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
105 std::cout <<
"SYNOPSYS" << std::endl
107 <<
" [--ip <controller ip>]"
111 <<
" [--grasp <width>]"
112 <<
" [--grasp-speed <speed>]"
113 <<
" [--grasp-force <force>]"
115 <<
" [--test <width>]"
116 <<
" [--help] [-h]\n" << std::endl;
117 std::cout <<
"DESCRIPTION" << std::endl
118 <<
" Control Panda gripper." << std::endl
120 <<
" --ip <controller ip>" << std::endl
121 <<
" Franka controller ip address" << std::endl
122 <<
" Default: " << opt_robot_ip << std::endl
124 <<
" --home" << std::endl
125 <<
" Performs homing of the gripper." << std::endl
127 <<
" --open" << std::endl
128 <<
" Performs opening of the gripper." << std::endl
130 <<
" --close" << std::endl
131 <<
" Performs closing of the gripper." << std::endl
133 <<
" --grasp <object width>" << std::endl
134 <<
" Performs grasping of an object." << std::endl
135 <<
" Object width is to specify in [m]." << std::endl
136 <<
" Default width: " << opt_grasping_width <<
" [m]" << std::endl
138 <<
" --grasp-speed <speed>" << std::endl
139 <<
" Closing speed in [m/s] applied during grasping." << std::endl
140 <<
" Default: " << opt_grasping_speed <<
" [m/s]" << std::endl
142 <<
" --grasp-force <force>" << std::endl
143 <<
" Force in [N] applied during grasping." << std::endl
144 <<
" Default: " << opt_grasping_force <<
" [N]" << std::endl
146 <<
" --release" << std::endl
147 <<
" Release an object that is grasped." << std::endl
149 <<
" --test <object width>" << std::endl
150 <<
" Performs a gripper test on an object width specified in [m]." << std::endl
151 <<
" Default width: " << opt_grasping_width <<
" [m]" << std::endl
153 <<
" --help, -h" << std::endl
154 <<
" Print this helper message." << std::endl
156 std::cout <<
"EXAMPLE" << std::endl
157 <<
" To grasp a 4cm width object by first opening the gripper, then grasping the object:\n"
158 <<
" " << argv[0] <<
" --ip 192.168.100.1 --open\n"
159 <<
" " << argv[0] <<
" --ip 192.168.100.1 --grasp 0.04\n"
166 if (opt_gripper_state == Gripper_None) {
167 std::cout <<
"Specify which action you want to achieve. Run \"" << argv[0]
168 <<
" --help\" to see how to use this binary." << std::endl;
171 else if ((opt_gripper_state == Gripper_Grasp || opt_gripper_state == Gripper_Test) && opt_grasping_width <= 0) {
172 std::cout <<
"Object with in meter should be > 0. Run \"" << argv[0] <<
" --help\" to see how to use this binary."
180 robot.connect(opt_robot_ip);
182 if (opt_gripper_state == Gripper_Home) {
183 std::cout <<
"Gripper homing..." << std::endl;
184 robot.gripperHoming();
186 else if (opt_gripper_state == Gripper_Close) {
187 std::cout <<
"Gripper closing..." << std::endl;
188 robot.gripperClose();
190 else if (opt_gripper_state == Gripper_Open) {
191 std::cout <<
"Gripper opening..." << std::endl;
194 else if (opt_gripper_state == Gripper_Grasp) {
195 std::cout <<
"Gripper grasp " << opt_grasping_width <<
"m object width, with speed: " << opt_grasping_speed <<
" and force: " << opt_grasping_force <<
"N..." << std::endl;
196 robot.gripperGrasp(opt_grasping_width, opt_grasping_speed, opt_grasping_force);
198 else if (opt_gripper_state == Gripper_Release) {
199 std::cout <<
"Gripper release object..." << std::endl;
200 robot.gripperRelease();
202 else if (opt_gripper_state == Gripper_Test) {
203 std::cout <<
"Test gripper performing the following actions:" << std::endl;
204 std::cout <<
"- Gripper homing..." << std::endl;
205 robot.gripperHoming();
207 std::cout <<
"- Gripper closing..." << std::endl;
208 robot.gripperClose();
210 std::cout <<
"- Gripper open 5cm..." << std::endl;
211 robot.gripperMove(0.05);
213 std::cout <<
"- Gripper opening..." << std::endl;
216 std::cout <<
"- Gripper grasp " << opt_grasping_width <<
"m object width, with speed: " << opt_grasping_speed <<
" and force: " << opt_grasping_force <<
"N..." << std::endl;
217 robot.gripperGrasp(opt_grasping_width, opt_grasping_speed, opt_grasping_force);
219 std::cout <<
"- Gripper release object..." << std::endl;
220 robot.gripperRelease();
222 std::cout <<
"The end!" << std::endl;
225 std::cout <<
"ViSP exception: " << e.
what() << std::endl;
228 catch (
const franka::NetworkException &e) {
229 std::cout <<
"Franka network exception: " << e.what() << std::endl;
230 std::cout <<
"Check if you are connected to the Franka robot"
231 <<
" or if you specified the right IP using --ip command line option set by default to 192.168.1.1. "
235 catch (
const std::exception &e) {
236 std::cout <<
"Franka exception: " << e.what() << std::endl;
245 #if !defined(VISP_HAVE_FRANKA)
246 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)