-
Notifications
You must be signed in to change notification settings - Fork 16
/
hand_remote.cc
78 lines (66 loc) · 1.78 KB
/
hand_remote.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*!
\file examples/hand_remote.cc
\brief Control manipulator example
\author João Borrego : jsbruglie
*/
#include "hand_remote.hh"
int main(int _argc, char **_argv)
{
// Command-line arguments
std::string config_file, robot;
parseArgs(_argc, _argv, config_file, robot);
// Load gazebo as a client
gazebo::client::setup(_argc, _argv);
// Interface
Interface api;
// Init interface with config file
if (!api.init(config_file, robot)) {
std::cout << "Exiting..." << std::endl;
exit(EXIT_FAILURE);
}
// Main loop - Keyboard input
api.loop();
// Shut down
gazebo::client::shutdown();
return 0;
}
//////////////////////////////////////////////////
const std::string getUsage(const char* argv_0)
{
return \
"usage: " + std::string(argv_0) + " [options]\n" +
"options: -c <robot configuration yaml>\n" +
" -r <robot>\n";
}
//////////////////////////////////////////////////
void parseArgs(
int argc,
char** argv,
std::string & cfg_dir,
std::string & robot)
{
int opt;
bool c, r;
while ((opt = getopt(argc,argv,"c: r:")) != EOF)
{
switch (opt)
{
case 'c':
c = true; cfg_dir = optarg; break;
case 'r':
r = true; robot = optarg; break;
case '?':
std::cerr << getUsage(argv[0]);
default:
std::cout << std::endl;
exit(EXIT_FAILURE);
}
}
if (!c || !r) {
std::cerr << getUsage(argv[0]);
exit(EXIT_FAILURE);
}
std::cout << "Parameters:\n" <<
" Robot configuration yaml '" << cfg_dir << "'\n" <<
" Robot '" << robot << "'\n" << std::endl;
}