Statistics
| Branch: | Tag: | Revision:

hlrc / server / src / main.cpp @ 0c286af0

History | View | Annotate | Download (3.196 KB)

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
*/
28

    
29
#include "MiddlewareRSB.h"
30
#include "MiddlewareROS.h"
31
#include "Arbiter.h"
32

    
33
#include <string>
34
#include <iostream>
35
#include <stdlib.h>
36
#include <math.h>
37
#include <boost/date_time/posix_time/posix_time.hpp>
38
#include <boost/thread/thread_time.hpp>
39
#include <boost/thread/thread.hpp>
40
#include <boost/algorithm/string.hpp>
41

    
42
Arbiter *arbiter;
43

    
44
using namespace std;
45
using namespace boost;
46

    
47
int main(int argc, char *argv[]) {
48
    if ((argc != 3) && (argc != 4)){
49
        printf("> ERROR: no base scope passed to server!\n\nusage: %s <base scopename> <mw> [<audio output>]  (example: %s /flobi1/ RSB 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
    }
53

    
54
    printf("> hlrc_server starting\n");
55

    
56
    //fetch scope from cmd line
57
    std::string scope = argv[1];
58

    
59
    //fetch middleware from cmd line
60
    std::string mw = argv[2];
61
    to_upper(mw); //convert to uppercase
62

    
63
    //arbiter
64
    std::string sound_output = "pulse";
65
    if (argc == 4){
66
        sound_output = argv[3];
67
    }
68
    arbiter = new Arbiter(sound_output);
69

    
70
    //mw connection
71
    Middleware *middleware;
72
    if (mw == "ROS"){
73
        middleware = new MiddlewareROS(arbiter, scope);
74
    }else{
75
        middleware = new MiddlewareRSB(arbiter, scope);
76
    }
77

    
78
    //human motion connection:
79
    printf("> initializing humotion client\n");
80
    humotion::client::Client *client = new humotion::client::Client(scope, "ROS");
81

    
82
    printf("> all done. hlrc server ready\n");
83

    
84
    //send values to human motion server
85
    float loop_delay = 1000.0 / 50.0; //run with 50Hz
86
    boost::system_time timeout = get_system_time() + posix_time::milliseconds(loop_delay);
87

    
88
    while(client->ok()){
89
        middleware->tick();
90

    
91
        //find correct arbitration
92
        arbiter->arbitrate();
93

    
94
        //periodically send mouth & gaze target
95
        client->update_mouth_target(arbiter->get_mouth_state());
96
        client->update_gaze_target(arbiter->get_gaze_state());
97
        client->send_all();
98

    
99
        //debug:
100
        //arbiter->get_mouth_state().dump();
101

    
102
        thread::sleep(timeout);
103
        timeout = get_system_time() + posix_time::milliseconds(loop_delay);
104
    }
105

    
106
    return EXIT_SUCCESS;
107

    
108
}
109