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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 | /**
* @file main.cpp
*
* @author <a href="mailto:xu@informatik.hu-berlin.de">Xu Yuan</a>
*
*/
#include <glib.h>
#include <glib-object.h>
#include <SimSpark/SimSparkController.h>
#include <sstream>
using namespace std;
// allows for changing the platform name during the compilation
#ifndef PLATFORM_NAME
#define PLATFORM_NAME SimSpark
#endif
#define MAKE_STRING(name) #name
#define MAKE_NAME(name) MAKE_STRING(name)
int main(int argc, char** argv)
{
g_type_init();
string teamName = "";
gchar* optTeamName = NULL;
unsigned int teamNumber = 0; // zero means read from config
unsigned int playerNumber = 0; // zero means get a number from server
string server = "localhost";
string modelPath = "rsg/agent/naov4/nao.rsg";
gchar* optModelPath = NULL;
gchar* optServer = NULL;
unsigned int port = 3100;
gboolean sync = false;
GOptionEntry entries[] = {
{"team_number", 'm', 0, G_OPTION_ARG_INT, &teamNumber, "team number", "0"},
{"num",'n', 0, G_OPTION_ARG_INT, &playerNumber, "player number", "0"},
{"team", 't', 0, G_OPTION_ARG_STRING, &optTeamName, "team name", "NaoTH"},
{"server", 's', 0, G_OPTION_ARG_STRING, &optServer, "server host", "localhost"},
{"model_path", 0, 0, G_OPTION_ARG_STRING, &optModelPath, "path for the model of the robot", "rsg/agent/naov4/nao.rsg"},
{"port", 'p', 0, G_OPTION_ARG_INT, &port, "server port", "3100"},
{"sync", 0, 0, G_OPTION_ARG_NONE, &sync, "sync mode", NULL},
{NULL,0,0,G_OPTION_ARG_NONE, NULL, NULL, NULL} // This NULL is very important!!!
};
std::stringstream info;
info << "==========================================" << std::endl;
info << " http://www.naoth.de " << std::endl;
info << "NaoTH compiled on: " << __DATE__ << " at " << __TIME__ << std::endl;
#ifdef REVISION
info << "Revision number: " << MAKE_STRING(REVISION) << std::endl;<--- Skipping configuration 'REVISION' since the value of 'REVISION' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
#endif
#ifdef USER_NAME
info << "Owner: " << MAKE_STRING(USER_NAME) << std::endl;<--- Skipping configuration 'USER_NAME' since the value of 'USER_NAME' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
#endif
#ifdef BRANCH_PATH
info << "Branch path: " << MAKE_STRING(BRANCH_PATH) << std::endl;<--- Skipping configuration 'BRANCH_PATH' since the value of 'BRANCH_PATH' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
#endif
info << "==========================================\n" << std::endl;
GError *error = NULL;
GOptionContext *context = g_option_context_new(info.str().c_str());
g_option_context_add_main_entries (context, entries, "NaoTH Simspark (SPL) controller");
if (!g_option_context_parse (context, &argc, &argv, &error))
{
g_print ("option parsing failed: %s\n", error->message);
return EXIT_FAILURE;
}
if ( optTeamName != NULL )
{
teamName = optTeamName;
g_free(optTeamName);
}
if ( optServer != NULL )
{
server = optServer;
g_free(optServer);
}
if ( optModelPath != NULL )
{
modelPath = optModelPath;
g_free(optModelPath);
}
g_option_context_free(context);
SimSparkController theController(MAKE_NAME(PLATFORM_NAME));
if (!theController.init(modelPath, teamName, teamNumber, playerNumber, server, port, sync > 0))
{
cerr << "NaoTH SimSpark (SPL) initialization failed!" << endl;
return EXIT_FAILURE;
}
naoth::init_agent(theController);
theController.main();
return 0;
}//end main
|