humotion / src / client / middleware_rsb.cpp @ 45091351
History | View | Annotate | Download (5.109 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 |
|
32 |
#define BOOST_SIGNALS_NO_DEPRECATION_WARNING 1 |
33 |
#include <rsb/converter/ProtocolBufferConverter.h> |
34 |
#include <rsb/converter/Repository.h> |
35 |
#include <rsb/Factory.h> |
36 |
#include <rsb/Listener.h> |
37 |
#include <rsb/MetaData.h> |
38 |
#include <rsb/patterns/RemoteServer.h> |
39 |
#include <string> |
40 |
|
41 |
#include "humotion/gaze.h" |
42 |
#include "humotion/mouth.h" |
43 |
|
44 |
// using namespace std;
|
45 |
// using namespace rsb;
|
46 |
// using namespace boost;
|
47 |
// using namespace humotion;
|
48 |
using humotion::client::MiddlewareRSB;
|
49 |
|
50 |
//! constructor
|
51 |
MiddlewareRSB::MiddlewareRSB(string scope) : Middleware(scope) {
|
52 |
printf("> registering converters\n");
|
53 |
|
54 |
try {
|
55 |
// converter for GazeTarget
|
56 |
rsb::converter::Converter<string>::Ptr gazeTargetConverter(
|
57 |
new rsb::converter::ProtocolBufferConverter<rst::robot::HumotionGazeTarget>());
|
58 |
rsb::converter::converterRepository<string>()->registerConverter(gazeTargetConverter);
|
59 |
} catch (std::invalid_argument e) {
|
60 |
printf("> it seems like a converter for rst::robot::HumotionGazeTarget "
|
61 |
"is already registered. fine, will not add another converter\n");
|
62 |
} |
63 |
|
64 |
try {
|
65 |
// converter for MouthTarget
|
66 |
rsb::converter::Converter<string>::Ptr mouthTargetConverter(
|
67 |
new rsb::converter::ProtocolBufferConverter<rst::robot::MouthTarget>());
|
68 |
rsb::converter::converterRepository<std::string>()->registerConverter(mouthTargetConverter);
|
69 |
} catch (std::invalid_argument e) {
|
70 |
printf("> it seems like a converter for rst::robot::MouthTarget is "
|
71 |
"already registered. fine, will not add another converter\n");
|
72 |
} |
73 |
|
74 |
|
75 |
// first get a factory instance that is used to create RSB domain objects
|
76 |
Factory &factory = getFactory(); |
77 |
|
78 |
// create informer
|
79 |
mouth_target_informer = factory.createInformer<rst::robot::MouthTarget> |
80 |
(base_scope + "/humotion/mouth/target");
|
81 |
gaze_target_informer = factory.createInformer<rst::robot::HumotionGazeTarget> |
82 |
(base_scope + "/humotion/gaze/target");
|
83 |
|
84 |
printf("> MiddlewareRSB initialised\n");
|
85 |
} |
86 |
|
87 |
//! destructor
|
88 |
MiddlewareRSB::~MiddlewareRSB() { |
89 |
} |
90 |
|
91 |
//! connection ok?
|
92 |
//! \return true if conn is alive
|
93 |
bool MiddlewareRSB::ok() {
|
94 |
return true; |
95 |
} |
96 |
|
97 |
//! do a single tick
|
98 |
void MiddlewareRSB::tick() {
|
99 |
// nothing to do
|
100 |
} |
101 |
|
102 |
|
103 |
//! send mouth target to server
|
104 |
void MiddlewareRSB::send_mouth_target() {
|
105 |
// build target packet
|
106 |
boost::shared_ptr<rst::robot::MouthTarget> request(new rst::robot::MouthTarget());
|
107 |
|
108 |
request->set_position_left(mouth_state.position_left); |
109 |
request->set_position_center(mouth_state.position_center); |
110 |
request->set_position_right(mouth_state.position_right); |
111 |
|
112 |
request->set_opening_left(mouth_state.opening_left); |
113 |
request->set_opening_center(mouth_state.opening_center); |
114 |
request->set_opening_right(mouth_state.opening_right); |
115 |
|
116 |
|
117 |
mouth_target_informer->publish(request); |
118 |
} |
119 |
|
120 |
//! send mouth target to server
|
121 |
void MiddlewareRSB::send_gaze_target(int gaze_type) { |
122 |
// build target packet
|
123 |
boost::shared_ptr<rst::robot::HumotionGazeTarget> request(new rst::robot::HumotionGazeTarget());
|
124 |
|
125 |
request->set_pan(gaze_state.pan); |
126 |
request->set_tilt(gaze_state.tilt); |
127 |
request->set_roll(gaze_state.roll); |
128 |
request->set_vergence(gaze_state.vergence); |
129 |
|
130 |
request->set_pan_offset(gaze_state.pan_offset); |
131 |
request->set_tilt_offset(gaze_state.tilt_offset); |
132 |
request->set_roll_offset(gaze_state.roll_offset); |
133 |
|
134 |
request->set_eyelid_opening_upper(gaze_state.eyelid_opening_upper); |
135 |
request->set_eyelid_opening_lower(gaze_state.eyelid_opening_lower); |
136 |
|
137 |
request->set_eyebrow_left(gaze_state.eyebrow_left); |
138 |
request->set_eyebrow_right(gaze_state.eyebrow_right); |
139 |
|
140 |
request->set_eyeblink_request_left(gaze_state.eyeblink_request_left); |
141 |
request->set_eyeblink_request_right(gaze_state.eyeblink_request_right); |
142 |
|
143 |
if (gaze_state.type == GazeState::ABSOLUTE) {
|
144 |
request->set_type(rst::robot::HumotionGazeTarget::ABSOLUTE); |
145 |
} else {
|
146 |
request->set_type(rst::robot::HumotionGazeTarget::RELATIVE); |
147 |
} |
148 |
|
149 |
|
150 |
// add position to send queue
|
151 |
gaze_target_informer->publish(request); |
152 |
} |
153 |
|
154 |
#endif
|