Statistics
| Branch: | Tag: | Revision:

humotion / src / client / middleware_rsb.cpp @ e4bb9fd4

History | View | Annotate | Download (4.95 KB)

1
/*
2
* This file is part of humotion
3
*
4
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
* http://opensource.cit-ec.de/projects/humotion
6
*
7
* This file may be licensed under the terms of the
8
* GNU Lesser General Public License Version 3 (the ``LGPL''),
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 LGPL for the specific language
14
* governing rights and limitations.
15
*
16
* You should have received a copy of the LGPL along with this
17
* program. If not, go to http://www.gnu.org/licenses/lgpl.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
#include "client/middleware_rsb.h"
29

    
30
#ifdef RSB_SUPPORT
31
#define BOOST_SIGNALS_NO_DEPRECATION_WARNING 1
32
#include <rsb/Listener.h>
33
#include <rsb/patterns/RemoteServer.h>
34
#include <rsb/MetaData.h>
35
#include <rsb/converter/Repository.h>
36
#include <rsb/converter/ProtocolBufferConverter.h>
37
#include <rsb/Factory.h>
38

    
39
#include <humotion/mouth.h>
40
#include <humotion/gaze.h>
41

    
42
using namespace std;
43
using namespace rsb;
44
using namespace boost;
45
using namespace humotion;
46
using namespace humotion::client;
47

    
48
//! constructor
49
MiddlewareRSB::MiddlewareRSB(string scope) : Middleware(scope){
50
    printf("> registering converters\n");
51

    
52
    try{
53
        //converter for GazeTarget
54
        rsb::converter::Converter<string>::Ptr gazeTargetConverter(new rsb::converter::ProtocolBufferConverter<rst::robot::HumotionGazeTarget>());
55
        rsb::converter::converterRepository<string>()->registerConverter(gazeTargetConverter);
56
    }catch (std::invalid_argument e){
57
        printf("> it seems like a converter for rst::robot::HumotionGazeTarget is already registered. fine, will not add another converter\n");
58
    }
59

    
60
    try{
61
        //converter for MouthTarget
62
        rsb::converter::Converter<string>::Ptr mouthTargetConverter(new rsb::converter::ProtocolBufferConverter<rst::robot::MouthTarget>());
63
        rsb::converter::converterRepository<string>()->registerConverter(mouthTargetConverter);
64
    }catch (std::invalid_argument e){
65
        printf("> it seems like a converter for rst::robot::MouthTarget is already registered. fine, will not add another converter\n");
66
    }
67

    
68

    
69
    //first get a factory instance that is used to create RSB domain objects
70
    Factory &factory = getFactory();
71

    
72
    //create informer
73
    mouth_target_informer = factory.createInformer<rst::robot::MouthTarget> (base_scope + "/humotion/mouth/target");
74
    gaze_target_informer  = factory.createInformer<rst::robot::HumotionGazeTarget> (base_scope + "/humotion/gaze/target");
75

    
76
    printf("> MiddlewareRSB initialised\n");
77
}
78

    
79
//! destructor
80
MiddlewareRSB::~MiddlewareRSB(){
81
}
82

    
83
//! connection ok?
84
//! \return true if conn is alive
85
bool MiddlewareRSB::ok(){
86
    return true;
87
}
88

    
89
//! do a single tick
90
void MiddlewareRSB::tick(){
91
    //nothing to do
92
}
93

    
94

    
95
//! send mouth target to server
96
void MiddlewareRSB::send_mouth_target(){
97
    //build target packet:
98
    boost::shared_ptr<rst::robot::MouthTarget> request(new rst::robot::MouthTarget());
99

    
100
    request->set_position_left(mouth_state.position_left);
101
    request->set_position_center(mouth_state.position_center);
102
    request->set_position_right(mouth_state.position_right);
103

    
104
    request->set_opening_left(mouth_state.opening_left);
105
    request->set_opening_center(mouth_state.opening_center);
106
    request->set_opening_right(mouth_state.opening_right);
107

    
108

    
109
    mouth_target_informer->publish(request);
110
}
111

    
112
//! send mouth target to server
113
void MiddlewareRSB::send_gaze_target(int gaze_type){
114
    //build target packet:
115
    boost::shared_ptr<rst::robot::HumotionGazeTarget> request(new rst::robot::HumotionGazeTarget());
116

    
117
    request->set_pan(gaze_state.pan);
118
    request->set_tilt(gaze_state.tilt);
119
    request->set_roll (gaze_state.roll);
120
    request->set_vergence(gaze_state.vergence);
121

    
122
    request->set_pan_offset(gaze_state.pan_offset);
123
    request->set_tilt_offset(gaze_state.tilt_offset);
124
    request->set_roll_offset(gaze_state.roll_offset);
125

    
126
    request->set_eyelid_opening_upper(gaze_state.eyelid_opening_upper);
127
    request->set_eyelid_opening_lower(gaze_state.eyelid_opening_lower);
128

    
129
    request->set_eyebrow_left(gaze_state.eyebrow_left);
130
    request->set_eyebrow_right(gaze_state.eyebrow_right);
131

    
132
    request->set_eyeblink_request_left(gaze_state.eyeblink_request_left);
133
    request->set_eyeblink_request_right(gaze_state.eyeblink_request_right);
134

    
135
    if (gaze_state.type == GazeState::ABSOLUTE){
136
        request->set_type(rst::robot::HumotionGazeTarget::ABSOLUTE);
137
    }else{
138
        request->set_type(rst::robot::HumotionGazeTarget::RELATIVE);
139
    }
140

    
141

    
142
    //add position to send queue
143
    gaze_target_informer->publish(request);
144
}
145

    
146
#endif