Statistics
| Branch: | Tag: | Revision:

hlrc / server / src / main.cpp @ 9cb381ec

History | View | Annotate | Download (3.284 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 <chrono>
38
#include <thread>
39
#include <boost/algorithm/string.hpp>
40

    
41
Arbiter *arbiter;
42

    
43
using namespace std;
44

    
45
int main(int argc, char *argv[]) {
46
    if ((argc != 5) && (argc != 6)){
47
        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]);
48
        printf("          audio output is optional and can be {pulse,oss,alsa,null,sndio,..}\n\n");
49
        exit(EXIT_FAILURE);
50
    }
51

    
52
    printf("> hlrc_server starting\n");
53

    
54
    //fetch scope from cmd line
55
    std::string scope_hlrc = argv[3];
56
    std::string scope_humotion = argv[4];
57

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

    
62
    //fetch mw for humotion
63
    std::string mw_humotion = argv[2];
64

    
65
    //arbiter
66
    std::string sound_output = "pulse";
67
    if (argc == 6){
68
        sound_output = argv[5];
69
    }
70
    arbiter = new Arbiter(sound_output);
71

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

    
80
    //human motion connection:
81
    humotion::client::Client *client = new humotion::client::Client(scope_humotion, mw_humotion);
82

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

    
85
    //send values to human motion server with 50Hz
86
    const auto loop_period = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<float>(1.0 / 50));
87
    auto timeout = std::chrono::steady_clock::now() + loop_period;
88

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

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

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

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

    
103
        std::this_thread::sleep_until(timeout);
104
        timeout += loop_period;
105
    }
106

    
107
    return EXIT_SUCCESS;
108
}