Statistics
| Branch: | Tag: | Revision:

humotion / src / server / middleware_rsb.cpp @ 7b67834d

History | View | Annotate | Download (5.331 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 "server/middleware_rsb.h"
29

    
30
#ifdef RSB_SUPPORT
31

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

    
40

    
41

    
42
using namespace std;
43
using namespace boost;
44
using namespace humotion;
45
using namespace humotion::server;
46
using namespace rsb;
47
using namespace rsb::patterns;
48

    
49
WARNING: RSB interface might be deprtecated and needs some backporting
50
from the ROS code. [todo]
51

    
52
//! constructor
53
MiddlewareRSB::MiddlewareRSB(string scope, Controller *c) : Middleware(scope, c){
54
    printf("> using RSB middleware\n");
55
    printf("> registering converters\n");
56

    
57
    //converter for GazeTarget
58
    rsb::converter::Converter<string>::Ptr gazeTargetConverter(new rsb::converter::ProtocolBufferConverter<rst::robot::HumotionGazeTarget>());
59
    rsb::converter::converterRepository<string>()->registerConverter(gazeTargetConverter);
60

    
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

    
65
    //first get a factory instance that is used to create RSB domain objects
66
    Factory &factory = getFactory();
67

    
68
    //create listeners
69
    mouth_target_listener = factory.createListener(base_scope + "/humotion/mouth/target");
70
    mouth_target_listener->addHandler(HandlerPtr(new DataFunctionHandler<rst::robot::MouthTarget> (boost::bind(&MiddlewareRSB::incoming_mouth_target, this, _1))));
71

    
72
    gaze_target_listener  = factory.createListener(base_scope + "/humotion/gaze/target");
73
    gaze_target_listener->addHandler(HandlerPtr(new EventFunctionHandler(boost::bind(&MiddlewareRSB::incoming_gaze_target, this, _1))));
74

    
75
    //informer->publish(gaze_target);
76
    printf("> MiddlewareRSB initialised\n");
77
}
78

    
79

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

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

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

    
95
//! callback to handle incoming mouth  target
96
void MiddlewareRSB::incoming_mouth_target(boost::shared_ptr<rst::robot::MouthTarget> msg){
97
    //printf("> incoming mouth_target\n");
98
    MouthState mouth_state;
99

    
100
    mouth_state.position_left   = msg->position_left();
101
    mouth_state.position_center = msg->position_center();
102
    mouth_state.position_right  = msg->position_right();
103

    
104
    mouth_state.opening_left   = msg->opening_left();
105
    mouth_state.opening_center = msg->opening_center();
106
    mouth_state.opening_right  = msg->opening_right();
107

    
108
    controller->set_mouth_target(mouth_state);
109
}
110

    
111
//! callback to handle incoming gaze  target
112
void MiddlewareRSB::incoming_gaze_target(rsb::EventPtr event){
113
    //printf("> incoming gaze_target [P:%3.1f, T:%3.1f, R:%3.1f]\n", msg->pan(), msg->tilt(), msg->roll());
114

    
115
    boost::shared_ptr<void> ev_data = event->getData();
116
    rst::robot::HumotionGazeTarget *msg = (rst::robot::HumotionGazeTarget*) ev_data.get();
117

    
118
    GazeState gaze_state;
119

    
120
    if (msg->gaze_type() == rst::robot::HumotionGazeTarget::ABSOLUTE){
121
        gaze_state.gaze_type = GazeState::ABSOLUTE;
122
    }else{
123
        gaze_state.gaze_type = GazeState::RELATIVE;
124
    }
125

    
126
    gaze_state.pan  = msg->pan();
127
    gaze_state.tilt = msg->tilt();
128
    gaze_state.roll = msg->roll();
129
    gaze_state.vergence = msg->vergence();
130

    
131
    gaze_state.pan_offset  = msg->pan_offset();
132
    gaze_state.tilt_offset = msg->tilt_offset();
133
    gaze_state.roll_offset = msg->roll_offset();
134

    
135
    gaze_state.eyelid_opening_upper = msg->eyelid_opening_upper();
136
    gaze_state.eyelid_opening_lower = msg->eyelid_opening_lower();
137

    
138
    gaze_state.eyebrow_left = msg->eyebrow_left();
139
    gaze_state.eyebrow_right = msg->eyebrow_right();
140

    
141
    gaze_state.eyeblink_request_left = msg->eyeblink_request_left();
142
    gaze_state.eyeblink_request_right = msg->eyeblink_request_right();
143

    
144
    gaze_state.timestamp = msg->gaze_timestamp(); FIXME: convert RSB timestamp to our representation
145
                                                         //event->getMetaData().getCreateTime() / 1000.0; //createTime() returns milliseconds -> convert to seconds
146

    
147
                                                         controller->set_gaze_target(gaze_state);
148
}
149

    
150
#endif