humotion / src / server / middleware_rsb.cpp @ 99ebae32
History | View | Annotate | Download (5 KB)
1 | 8c6c1163 | Simon Schulz | /*
|
---|---|---|---|
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 | //! constructor
|
||
50 | MiddlewareRSB::MiddlewareRSB(string scope, Controller *c) : Middleware(scope, c){
|
||
51 | printf("> registering converters\n");
|
||
52 | |||
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 | |||
57 | //converter for MouthTarget
|
||
58 | rsb::converter::Converter<string>::Ptr mouthTargetConverter(new rsb::converter::ProtocolBufferConverter<rst::robot::MouthTarget>()); |
||
59 | rsb::converter::converterRepository<string>()->registerConverter(mouthTargetConverter);
|
||
60 | |||
61 | //first get a factory instance that is used to create RSB domain objects
|
||
62 | Factory &factory = getFactory(); |
||
63 | |||
64 | //create listeners
|
||
65 | mouth_target_listener = factory.createListener(base_scope + "/humotion/mouth/target");
|
||
66 | mouth_target_listener->addHandler(HandlerPtr(new DataFunctionHandler<rst::robot::MouthTarget> (boost::bind(&MiddlewareRSB::incoming_mouth_target, this, _1)))); |
||
67 | |||
68 | gaze_target_listener = factory.createListener(base_scope + "/humotion/gaze/target");
|
||
69 | gaze_target_listener->addHandler(HandlerPtr(new EventFunctionHandler(boost::bind(&MiddlewareRSB::incoming_gaze_target, this, _1)))); |
||
70 | |||
71 | //informer->publish(gaze_target);
|
||
72 | printf("> MiddlewareRSB initialised\n");
|
||
73 | } |
||
74 | |||
75 | |||
76 | //! destructor
|
||
77 | MiddlewareRSB::~MiddlewareRSB(){ |
||
78 | } |
||
79 | |||
80 | //! connection ok?
|
||
81 | //! \return true if conn is alive
|
||
82 | bool MiddlewareRSB::ok(){
|
||
83 | return true; |
||
84 | } |
||
85 | |||
86 | //! do a single tick
|
||
87 | void MiddlewareRSB::tick(){
|
||
88 | //nothing to do
|
||
89 | } |
||
90 | |||
91 | //! callback to handle incoming mouth target
|
||
92 | void MiddlewareRSB::incoming_mouth_target(boost::shared_ptr<rst::robot::MouthTarget> msg){
|
||
93 | //printf("> incoming mouth_target\n");
|
||
94 | MouthState mouth_state; |
||
95 | |||
96 | mouth_state.position_left = msg->position_left(); |
||
97 | mouth_state.position_center = msg->position_center(); |
||
98 | mouth_state.position_right = msg->position_right(); |
||
99 | |||
100 | mouth_state.opening_left = msg->opening_left(); |
||
101 | mouth_state.opening_center = msg->opening_center(); |
||
102 | mouth_state.opening_right = msg->opening_right(); |
||
103 | |||
104 | controller->set_mouth_target(mouth_state); |
||
105 | } |
||
106 | |||
107 | //! callback to handle incoming gaze target
|
||
108 | void MiddlewareRSB::incoming_gaze_target(rsb::EventPtr event){
|
||
109 | //printf("> incoming gaze_target [P:%3.1f, T:%3.1f, R:%3.1f]\n", msg->pan(), msg->tilt(), msg->roll());
|
||
110 | |||
111 | boost::shared_ptr<void> ev_data = event->getData();
|
||
112 | rst::robot::HumotionGazeTarget *msg = (rst::robot::HumotionGazeTarget*) ev_data.get(); |
||
113 | |||
114 | GazeState gaze_state; |
||
115 | |||
116 | if (msg->type() == rst::robot::HumotionGazeTarget::ABSOLUTE){
|
||
117 | gaze_state.type = GazeState::ABSOLUTE; |
||
118 | }else{
|
||
119 | gaze_state.type = GazeState::RELATIVE; |
||
120 | } |
||
121 | |||
122 | gaze_state.pan = msg->pan(); |
||
123 | gaze_state.tilt = msg->tilt(); |
||
124 | gaze_state.roll = msg->roll(); |
||
125 | gaze_state.vergence = msg->vergence(); |
||
126 | |||
127 | gaze_state.pan_offset = msg->pan_offset(); |
||
128 | gaze_state.tilt_offset = msg->tilt_offset(); |
||
129 | gaze_state.roll_offset = msg->roll_offset(); |
||
130 | |||
131 | gaze_state.eyelid_opening_upper = msg->eyelid_opening_upper(); |
||
132 | gaze_state.eyelid_opening_lower = msg->eyelid_opening_lower(); |
||
133 | |||
134 | gaze_state.eyebrow_left = msg->eyebrow_left(); |
||
135 | gaze_state.eyebrow_right = msg->eyebrow_right(); |
||
136 | |||
137 | gaze_state.eyeblink_request_left = msg->eyeblink_request_left(); |
||
138 | gaze_state.eyeblink_request_right = msg->eyeblink_request_right(); |
||
139 | |||
140 | gaze_state.timestamp = event->getMetaData().getCreateTime() / 1000.0; //createTime() returns milliseconds -> convert to seconds |
||
141 | |||
142 | controller->set_gaze_target(gaze_state); |
||
143 | } |
||
144 | |||
145 | #endif |