Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
frankaMoveToPosition.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Franka robot tool.
32 */
33
38
39#include <iostream>
40
41#include <visp3/core/vpConfig.h>
42#include <visp3/core/vpIoTools.h>
43#include <visp3/robot/vpRobotFranka.h>
44
45#if defined(VISP_HAVE_FRANKA)
46
47int main(int argc, char **argv)
48{
49#ifdef ENABLE_VISP_NAMESPACE
50 using namespace VISP_NAMESPACE_NAME;
51#endif
52
53 std::string opt_robot_ip = "192.168.1.1";
54 std::string opt_position_filename = "";
55
56 for (int i = 1; i < argc; i++) {
57 if (std::string(argv[i]) == "--ip" && i + 1 < argc) {
58 opt_robot_ip = std::string(argv[i + 1]);
59 }
60 else if (std::string(argv[i]) == "--read" && i + 1 < argc) {
61 opt_position_filename = std::string(argv[i + 1]);
62 }
63 else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
64 std::cout << "Move Panda robot to a position specified from a file." << std::endl;
65 std::cout << argv[0] << " [--ip <default " << opt_robot_ip << ">] [--read <position file name>] [--help] [-h]\n"
66 << std::endl;
67 std::cout << "Example:\n" << argv[0] << " --ip 192.168.100.1 --read position.pos\n" << std::endl;
68
69 return EXIT_SUCCESS;
70 }
71 }
72
73 if (opt_position_filename.empty()) {
74 std::cout << "\nError: no position file given as input with --read option. " << std::endl;
75 std::cout << "Call \"" << argv[0] << " --help\" to get usage" << std::endl;
76 return EXIT_FAILURE;
77 }
78 if (!vpIoTools::checkFilename(opt_position_filename)) {
79 std::cout << "\nError: position filename \"" << opt_position_filename << "\" given as input doesn't exist. "
80 << std::endl;
81 std::cout << "Call \"" << argv[0] << " --help\" to get usage" << std::endl;
82 return EXIT_FAILURE;
83 }
84
85 vpRobotFranka robot;
86
87 try {
88 robot.connect(opt_robot_ip);
89
90 robot.move(opt_position_filename);
91 }
92 catch (const vpException &e) {
93 std::cout << "ViSP exception: " << e.what() << std::endl;
94 std::cout << "Stop the robot " << std::endl;
95 robot.setRobotState(vpRobot::STATE_STOP);
96 return EXIT_FAILURE;
97 }
98 catch (const franka::NetworkException &e) {
99 std::cout << "Franka network exception: " << e.what() << std::endl;
100 std::cout << "Check if you are connected to the Franka robot"
101 << " or if you specified the right IP using --ip command line option set by default to 192.168.1.1. "
102 << std::endl;
103 return EXIT_FAILURE;
104 }
105 catch (const std::exception &e) {
106 std::cout << "Franka exception: " << e.what() << std::endl;
107 return EXIT_FAILURE;
108 }
109
110 return EXIT_SUCCESS;
111}
112#else
113int main()
114{
115#if !defined(VISP_HAVE_FRANKA)
116 std::cout << "Install libfranka." << std::endl;
117#endif
118 return EXIT_SUCCESS;
119}
120#endif
error that can be emitted by ViSP classes.
Definition vpException.h:60
static bool checkFilename(const std::string &filename)
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
Definition vpRobot.h:63