humotion / src / client / middleware_rsb.cpp @ ea068cf1
History | View | Annotate | Download (5.109 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 "client/middleware_rsb.h" |
||
29 | |||
30 | #ifdef RSB_SUPPORT
|
||
31 | 0c8d22a5 | sschulz | |
32 | 8c6c1163 | Simon Schulz | #define BOOST_SIGNALS_NO_DEPRECATION_WARNING 1 |
33 | #include <rsb/converter/ProtocolBufferConverter.h> |
||
34 | 0c8d22a5 | sschulz | #include <rsb/converter/Repository.h> |
35 | 8c6c1163 | Simon Schulz | #include <rsb/Factory.h> |
36 | 0c8d22a5 | sschulz | #include <rsb/Listener.h> |
37 | #include <rsb/MetaData.h> |
||
38 | #include <rsb/patterns/RemoteServer.h> |
||
39 | #include <string> |
||
40 | 8c6c1163 | Simon Schulz | |
41 | 0c8d22a5 | sschulz | #include "humotion/gaze.h" |
42 | #include "humotion/mouth.h" |
||
43 | 8c6c1163 | Simon Schulz | |
44 | 0c8d22a5 | sschulz | // using namespace std;
|
45 | // using namespace rsb;
|
||
46 | // using namespace boost;
|
||
47 | // using namespace humotion;
|
||
48 | using humotion::client::MiddlewareRSB;
|
||
49 | 8c6c1163 | Simon Schulz | |
50 | //! constructor
|
||
51 | 0c8d22a5 | sschulz | MiddlewareRSB::MiddlewareRSB(string scope) : Middleware(scope) {
|
52 | 8c6c1163 | Simon Schulz | printf("> registering converters\n");
|
53 | |||
54 | 0c8d22a5 | sschulz | try {
|
55 | // converter for GazeTarget
|
||
56 | rsb::converter::Converter<string>::Ptr gazeTargetConverter(
|
||
57 | new rsb::converter::ProtocolBufferConverter<rst::robot::HumotionGazeTarget>());
|
||
58 | 8c6c1163 | Simon Schulz | rsb::converter::converterRepository<string>()->registerConverter(gazeTargetConverter);
|
59 | 0c8d22a5 | sschulz | } 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 | 8c6c1163 | Simon Schulz | } |
63 | |||
64 | 0c8d22a5 | sschulz | 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 | 8c6c1163 | Simon Schulz | } |
73 | |||
74 | |||
75 | 0c8d22a5 | sschulz | // first get a factory instance that is used to create RSB domain objects
|
76 | 8c6c1163 | Simon Schulz | Factory &factory = getFactory(); |
77 | |||
78 | 0c8d22a5 | sschulz | // 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 | 8c6c1163 | Simon Schulz | |
84 | printf("> MiddlewareRSB initialised\n");
|
||
85 | } |
||
86 | |||
87 | //! destructor
|
||
88 | 0c8d22a5 | sschulz | MiddlewareRSB::~MiddlewareRSB() { |
89 | 8c6c1163 | Simon Schulz | } |
90 | |||
91 | //! connection ok?
|
||
92 | //! \return true if conn is alive
|
||
93 | 0c8d22a5 | sschulz | bool MiddlewareRSB::ok() {
|
94 | 8c6c1163 | Simon Schulz | return true; |
95 | } |
||
96 | |||
97 | //! do a single tick
|
||
98 | 0c8d22a5 | sschulz | void MiddlewareRSB::tick() {
|
99 | // nothing to do
|
||
100 | 8c6c1163 | Simon Schulz | } |
101 | |||
102 | |||
103 | //! send mouth target to server
|
||
104 | 0c8d22a5 | sschulz | void MiddlewareRSB::send_mouth_target() {
|
105 | // build target packet
|
||
106 | 8c6c1163 | Simon Schulz | 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 | 0c8d22a5 | sschulz | void MiddlewareRSB::send_gaze_target(int gaze_type) { |
122 | // build target packet
|
||
123 | 8c6c1163 | Simon Schulz | 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 | 0c8d22a5 | sschulz | request->set_roll(gaze_state.roll); |
128 | 8c6c1163 | Simon Schulz | 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 | 0c8d22a5 | sschulz | if (gaze_state.type == GazeState::ABSOLUTE) {
|
144 | 89374d69 | Simon Schulz | request->set_type(rst::robot::HumotionGazeTarget::ABSOLUTE); |
145 | 0c8d22a5 | sschulz | } else {
|
146 | 89374d69 | Simon Schulz | request->set_type(rst::robot::HumotionGazeTarget::RELATIVE); |
147 | } |
||
148 | |||
149 | 8c6c1163 | Simon Schulz | |
150 | 0c8d22a5 | sschulz | // add position to send queue
|
151 | 8c6c1163 | Simon Schulz | gaze_target_informer->publish(request); |
152 | } |
||
153 | |||
154 | #endif |