Revision f150aab5 server/src/main.cpp
server/src/main.cpp | ||
---|---|---|
1 | 1 |
/* |
2 |
* This file is part of hlrc_server |
|
3 |
* |
|
4 |
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de |
|
5 |
* http://opensource.cit-ec.de/projects/hlrc_server |
|
6 |
* |
|
7 |
* This file may be licensed under the terms of the |
|
8 |
* GNU General Public License Version 3 (the ``GPL''), |
|
9 |
* or (at your option) any later version. |
|
10 |
* |
|
11 |
* Software distributed under the License is distributed |
|
12 |
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either |
|
13 |
* express or implied. See the GPL for the specific language |
|
14 |
* governing rights and limitations. |
|
15 |
* |
|
16 |
* You should have received a copy of the GPL along with this |
|
17 |
* program. If not, go to http://www.gnu.org/licenses/gpl.html |
|
18 |
* or write to the Free Software Foundation, Inc., |
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* The development of this software was supported by the |
|
22 |
* Excellence Cluster EXC 277 Cognitive Interaction Technology. |
|
23 |
* The Excellence Cluster EXC 277 is a grant of the Deutsche |
|
24 |
* Forschungsgemeinschaft (DFG) in the context of the German |
|
25 |
* Excellence Initiative. |
|
26 |
* |
|
27 |
*/ |
|
2 |
* This file is part of hlrc_server
|
|
3 |
*
|
|
4 |
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
|
|
5 |
* http://opensource.cit-ec.de/projects/hlrc_server
|
|
6 |
*
|
|
7 |
* This file may be licensed under the terms of the
|
|
8 |
* GNU General Public License Version 3 (the ``GPL''),
|
|
9 |
* or (at your option) any later version.
|
|
10 |
*
|
|
11 |
* Software distributed under the License is distributed
|
|
12 |
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
|
|
13 |
* express or implied. See the GPL for the specific language
|
|
14 |
* governing rights and limitations.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GPL along with this
|
|
17 |
* program. If not, go to http://www.gnu.org/licenses/gpl.html
|
|
18 |
* or write to the Free Software Foundation, Inc.,
|
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
20 |
*
|
|
21 |
* The development of this software was supported by the
|
|
22 |
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
|
|
23 |
* The Excellence Cluster EXC 277 is a grant of the Deutsche
|
|
24 |
* Forschungsgemeinschaft (DFG) in the context of the German
|
|
25 |
* Excellence Initiative.
|
|
26 |
*
|
|
27 |
*/
|
|
28 | 28 |
|
29 | 29 |
#include "MiddlewareRSB.h" |
30 | 30 |
#include "MiddlewareROS.h" |
... | ... | |
39 | 39 |
#include <boost/thread/thread.hpp> |
40 | 40 |
#include <boost/algorithm/string.hpp> |
41 | 41 |
|
42 |
Arbiter *arbiter;
|
|
42 |
Arbiter* arbiter;
|
|
43 | 43 |
|
44 | 44 |
using namespace std; |
45 | 45 |
using namespace boost; |
46 | 46 |
|
47 |
int main(int argc, char *argv[]) { |
|
48 |
if ((argc != 5) && (argc != 6)){ |
|
49 |
printf("> ERROR: invalid number of parameters passed to server!\n\nusage: %s <mw_hlrc> <mw_humotion> <base scopename hlrc> <base scopename humotion> [<audio output>] (example: %s RSB RSB /flobi1/ pulse )\n",argv[0],argv[0]); |
|
50 |
printf(" audio output is optional and can be {pulse,oss,alsa,null,sndio,..}\n\n"); |
|
51 |
exit(EXIT_FAILURE); |
|
52 |
} |
|
47 |
int main(int argc, char* argv[]) { |
|
48 |
if ((argc != 5) && (argc != 6)) { |
|
49 |
printf("> ERROR: invalid number of parameters passed to server!\n\nusage: %s <mw_hlrc> <mw_humotion> <base scopename " |
|
50 |
"hlrc> <base scopename humotion> [<audio output>] (example: %s RSB RSB /flobi1/ pulse )\n", |
|
51 |
argv[0], argv[0]); |
|
52 |
printf(" audio output is optional and can be {pulse,oss,alsa,null,sndio,..}\n\n"); |
|
53 |
exit(EXIT_FAILURE); |
|
54 |
} |
|
53 | 55 |
|
54 |
printf("> hlrc_server starting\n");
|
|
56 |
printf("> hlrc_server starting\n");
|
|
55 | 57 |
|
56 |
//fetch scope from cmd line
|
|
57 |
std::string scope_hlrc = argv[3];
|
|
58 |
std::string scope_humotion = argv[4];
|
|
58 |
// fetch scope from cmd line
|
|
59 |
std::string scope_hlrc = argv[3];
|
|
60 |
std::string scope_humotion = argv[4];
|
|
59 | 61 |
|
60 |
//fetch middleware from cmd line
|
|
61 |
std::string mw = argv[1];
|
|
62 |
to_upper(mw); //convert to uppercase
|
|
62 |
// fetch middleware from cmd line
|
|
63 |
std::string mw = argv[1];
|
|
64 |
to_upper(mw); // convert to uppercase
|
|
63 | 65 |
|
64 |
//fetch mw for humotion
|
|
65 |
std::string mw_humotion = argv[2];
|
|
66 |
// fetch mw for humotion
|
|
67 |
std::string mw_humotion = argv[2];
|
|
66 | 68 |
|
67 |
//arbiter
|
|
68 |
std::string sound_output = "pulse";
|
|
69 |
if (argc == 6){
|
|
70 |
sound_output = argv[5];
|
|
71 |
}
|
|
72 |
arbiter = new Arbiter(sound_output);
|
|
69 |
// arbiter
|
|
70 |
std::string sound_output = "pulse";
|
|
71 |
if (argc == 6) {
|
|
72 |
sound_output = argv[5];
|
|
73 |
}
|
|
74 |
arbiter = new Arbiter(sound_output);
|
|
73 | 75 |
|
74 |
//mw connection |
|
75 |
Middleware *middleware; |
|
76 |
if (mw == "ROS"){ |
|
77 |
middleware = new MiddlewareROS(arbiter, scope_hlrc); |
|
78 |
}else{ |
|
79 |
middleware = new MiddlewareRSB(arbiter, scope_hlrc); |
|
80 |
} |
|
76 |
// mw connection |
|
77 |
Middleware* middleware; |
|
78 |
if (mw == "ROS") { |
|
79 |
middleware = new MiddlewareROS(arbiter, scope_hlrc); |
|
80 |
} |
|
81 |
else { |
|
82 |
middleware = new MiddlewareRSB(arbiter, scope_hlrc); |
|
83 |
} |
|
81 | 84 |
|
82 |
//human motion connection:
|
|
83 |
humotion::client::Client *client = new humotion::client::Client(scope_humotion, mw_humotion);
|
|
85 |
// human motion connection:
|
|
86 |
humotion::client::Client* client = new humotion::client::Client(scope_humotion, mw_humotion);
|
|
84 | 87 |
|
85 |
printf("> all done. hlrc server ready\n");
|
|
88 |
printf("> all done. hlrc server ready\n");
|
|
86 | 89 |
|
87 |
//send values to human motion server
|
|
88 |
float loop_delay = 1000.0 / 50.0; //run with 50Hz
|
|
89 |
boost::system_time timeout = get_system_time() + posix_time::milliseconds(loop_delay);
|
|
90 |
// send values to human motion server
|
|
91 |
float loop_delay = 1000.0 / 50.0; // run with 50Hz
|
|
92 |
boost::system_time timeout = get_system_time() + posix_time::milliseconds(loop_delay);
|
|
90 | 93 |
|
91 |
while(client->ok()){
|
|
92 |
middleware->tick();
|
|
94 |
while (client->ok()) {
|
|
95 |
middleware->tick();
|
|
93 | 96 |
|
94 |
//find correct arbitration
|
|
95 |
arbiter->arbitrate();
|
|
97 |
// find correct arbitration
|
|
98 |
arbiter->arbitrate();
|
|
96 | 99 |
|
97 |
//periodically send mouth & gaze target
|
|
98 |
client->update_mouth_target(arbiter->get_mouth_state());
|
|
99 |
client->update_gaze_target(arbiter->get_gaze_state());
|
|
100 |
client->send_all();
|
|
100 |
// periodically send mouth & gaze target
|
|
101 |
client->update_mouth_target(arbiter->get_mouth_state());
|
|
102 |
client->update_gaze_target(arbiter->get_gaze_state());
|
|
103 |
client->send_all();
|
|
101 | 104 |
|
102 |
//debug:
|
|
103 |
//arbiter->get_mouth_state().dump();
|
|
105 |
// debug:
|
|
106 |
// arbiter->get_mouth_state().dump();
|
|
104 | 107 |
|
105 |
thread::sleep(timeout); |
|
106 |
timeout = get_system_time() + posix_time::milliseconds(loop_delay); |
|
107 |
} |
|
108 |
|
|
109 |
return EXIT_SUCCESS; |
|
108 |
thread::sleep(timeout); |
|
109 |
timeout = get_system_time() + posix_time::milliseconds(loop_delay); |
|
110 |
} |
|
110 | 111 |
|
112 |
return EXIT_SUCCESS; |
|
111 | 113 |
} |
112 |
|
Also available in: Unified diff