Revision d81c4f8b

View differences:

client/cpp/CMakeLists.txt
31 31
#######################################
32 32
FIND_PACKAGE(hlrc_server)
33 33

  
34
#######################################
35
#allow forced disable of RSB
36
option(IGNORE_RSB "IGNORE_RSB" OFF)
37

  
38
#######################################
39
# check if we have RSB support:
40
IF (IGNORE_RSB)
41
    MESSAGE(INFO "RSB disabled per command line flag IGNORE_RSB")
42
ELSE (IGNORE_RSB)
43
FIND_PACKAGE(RSB 0.11 QUIET)
44
IF (RSB_FOUND)
45
    #RSB
46
    SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib:\$ORIGIN/")
47
    FIND_PACKAGE(RSC 0.11 REQUIRED)
48
    FIND_PACKAGE(RSB 0.11 REQUIRED)
49
    #RST
50
    FIND_PACKAGE(RST REQUIRED COMPONENTS sandbox)
51
    INCLUDE_DIRECTORIES(BEFORE SYSTEM ${RST_INCLUDE_DIRS})
52
    ADD_DEFINITIONS(${RST_CFLAGS} ${RSTSANDBOX_CFLAGS})
53

  
54
    INCLUDE_DIRECTORIES(BEFORE SYSTEM ${RSB_INCLUDE_DIRS})
55
    LIST(INSERT CMAKE_MODULE_PATH 0 ${RSC_CMAKE_MODULE_PATH})
56
    #RSB
57
    SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib:\$ORIGIN/")
58
    FIND_PACKAGE(RSC 0.11 REQUIRED)
59
    FIND_PACKAGE(RSB 0.11 REQUIRED)
60
    #RST
61
    FIND_PACKAGE(RST REQUIRED COMPONENTS sandbox)
62
    INCLUDE_DIRECTORIES(BEFORE SYSTEM ${RST_INCLUDE_DIRS})
63
    ADD_DEFINITIONS(${RST_CFLAGS} ${RSTSANDBOX_CFLAGS})
64

  
65
    INCLUDE_DIRECTORIES(BEFORE SYSTEM ${RSB_INCLUDE_DIRS})
66
    LIST(INSERT CMAKE_MODULE_PATH 0 ${RSC_CMAKE_MODULE_PATH})
67

  
68
    message(STATUS "RSB Support is ON")
69
    add_definitions(-DRSB_SUPPORT=1)
70
ELSE(RSB_FOUND)
71
    message(STATUS "RSB not found.")
72
ENDIF(RSB_FOUND)
73
ENDIF(IGNORE_RSB)
74

  
75 34
################################################################
76 35
# check for ROS support:
77 36
find_package(catkin QUIET)
......
118 77
    src/RobotController.cpp
119 78
    src/Middleware.cpp
120 79
    src/MiddlewareROS.cpp
121
    src/MiddlewareRSB.cpp
122 80
)
123 81

  
124 82
add_library(${HLRC_CLIENT_LIBNAME} SHARED
......
142 100
    add_dependencies(${HLRC_CLIENT_LIBNAME} ${catkin_EXPORTED_TARGETS})
143 101
ENDIF (ROS_FOUND)
144 102

  
145
target_link_libraries(${HLRC_CLIENT_LIBNAME} ${RSB_LIBRARIES} ${RST_LIBRARIES} ${catkin_LIBRARIES})
103
target_link_libraries(${HLRC_CLIENT_LIBNAME} ${catkin_LIBRARIES})
146 104

  
147 105
#build & install demo
148 106
#ADD_EXECUTABLE(testMarkerTracker example/testMarkerTracker.cc)
......
173 131
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKECONFIGVERSION_FILENAME}" DESTINATION "${DATADIR}")
174 132

  
175 133
#ADD_EXECUTABLE(${PROJECT_NAME} main.cpp ${SRC_FILES})
176
#TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${RSB_LIBRARIES} ${RST_LIBRARIES} ${OpenCV_LIBS} ${Boost_LIBRARIES} ${Boost_LIBS} ${BART_LIBRARIES} )
134
#TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OpenCV_LIBS} ${Boost_LIBRARIES} ${Boost_LIBS} ${BART_LIBRARIES} )
177 135

  
178 136
#build & install examples
179 137
ADD_EXECUTABLE(${PROJECT_NAME}_example_random_gaze examples/random_gaze/main.cpp)
client/cpp/examples/random_gaze/main.cpp
39 39
int main(int argc, char** argv) {
40 40
	if (argc != 3) {
41 41
		printf("usage: %s <middleware> <robot scope>\n", argv[0]);
42
		printf("       <middleware> is either ROS or RSB\n");
42
		printf("       <middleware> is  ROS\n");
43 43
		printf("       <robot scope> e.g. /flobi or /icub\n\n");
44 44
		exit(EXIT_FAILURE);
45 45
	}
client/cpp/examples/speech_test/main.cpp
33 33
#define BLOCKING true
34 34

  
35 35
int main(int argc, char** argv) {
36
	RobotController* robot_controller = new RobotController("RSB", "/flobi");
36
	RobotController* robot_controller = new RobotController("ROS", "/flobi");
37 37

  
38 38
	int count = 0;
39 39

  
client/cpp/include/MiddlewareROS.h
52 52
#ifndef ROS_SUPPORT
53 53
public:
54 54
	MiddlewareROS(std::string scope) : Middleware(scope) {
55
		printf("> ERROR: hlrc was compiled without ROS middleware support. Please use MiddlewareRSB() instead!\n\n");
55
		printf("> ERROR: hlrc was compiled without ROS middleware support.\n\n");
56 56
		exit(EXIT_FAILURE);
57 57
	}
58 58

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

  
29
#pragma once
30
#include "Middleware.h"
31
#ifdef RSB_SUPPORT
32
#define BOOST_SIGNALS_NO_DEPRECATION_WARNING // mute warnings from RSB
33
#include <rsb/Factory.h>
34
#include <rsb/Informer.h>
35
#include <rsb/Listener.h>
36

  
37
#if USE_INPROTK_SYNTHESIS
38
#include <rst/communicationpatterns/TaskState.pb.h>
39
#endif
40
#endif
41

  
42
class MiddlewareRSB : public Middleware {
43
#ifndef RSB_SUPPORT
44
public:
45
	MiddlewareRSB(std::string scope) : Middleware(scope) {
46
		printf("> ERROR: hlrc was compiled without RSB middleware support. Please use MiddlewareROS() instead!\n\n");
47
		exit(EXIT_FAILURE);
48
	}
49

  
50
	void init(){};
51
	void publish_default_emotion(RobotEmotion e, bool blocking){};
52
	void publish_current_emotion(RobotEmotion e, bool blocking){};
53
	void publish_gaze_target(RobotGaze g, bool blocking){};
54
	void publish_lookat_target(float x, float y, float z, const std::string frame_id, bool blocking, float roll){};
55
	void publish_mouth_target(RobotMouth m, bool blocking){};
56
	void publish_head_animation(RobotHeadAnimation a, bool blocking){};
57
	void publish_speech(std::string text, bool blocking){};
58

  
59
#else
60
public:
61
	MiddlewareRSB(std::string scope);
62

  
63
protected:
64
	void init();
65
	void publish_current_emotion(RobotEmotion e, bool blocking);
66
	void publish_default_emotion(RobotEmotion e, bool blocking);
67
	void publish_gaze_target(RobotGaze target, bool blocking);
68
	void publish_lookat_target(float x, float y, float z, const std::string frame_id, bool blocking, float roll);
69
	void publish_mouth_target(RobotMouth target, bool blocking);
70
	void publish_head_animation(RobotHeadAnimation a, bool blocking);
71
	void publish_speech(std::string text, bool blocking);
72

  
73
private:
74
	void publish_emotion(std::string scope_target, RobotEmotion e, bool blocking);
75

  
76
	// rsb::patterns::RemoteServerPtr inprotk_server;
77
	rsb::patterns::RemoteServerPtr hlrc_server;
78
	// rsb::patterns::LocalServerPtr inprotk_server;
79
#if USE_INPROTK_SYNTHESIS
80
	rsb::Informer<rst::communicationpatterns::TaskState>::Ptr inprotk_informer;
81
	rsb::ListenerPtr inprotk_listener;
82
	rsb::ListenerPtr hack_listener;
83

  
84
	std::mutex pending_tasks_mutex;
85
	std::vector<std::shared_ptr<rst::communicationpatterns::TaskState> > pending_tasks;
86
	unsigned int say_task_active;
87
	unsigned int say_task_done;
88

  
89
	std::mutex current_saytask_mutex;
90
	std::string current_saytask;
91
	std::string get_current_saytask();
92
	void set_current_saytask(std::string text);
93

  
94
	void check_for_inprotk();
95
	void incoming_hack(std::shared_ptr<std::string> finished_task);
96
#endif
97
#endif
98
};
client/cpp/src/MiddlewareRSB.cpp
1
/*
2
 * This file is part of hlrc
3
 *
4
 * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
 * http://opensource.cit-ec.de/projects/hlrc
6
 *
7
 * This file may be licensed under the terms of the
8
 * GNU General Public License Version 3 (the ``GPL''),
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 GPL for the specific language
14
 * governing rights and limitations.
15
 *
16
 * You should have received a copy of the GPL along with this
17
 * program. If not, go to http://www.gnu.org/licenses/gpl.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

  
29
#ifdef RSB_SUPPORT
30

  
31
#include "MiddlewareRSB.h"
32
#include <rsb/converter/Repository.h>
33
#include <rsb/converter/ProtocolBufferConverter.h>
34

  
35
#include <rst/animation/EmotionExpression.pb.h>
36
#include <rst/animation/BinocularHeadGaze.pb.h>
37
#include <rst/animation/HeadAnimation.pb.h>
38
#include <rst/audition/Utterance.pb.h>
39
#include <rst/audition/SoundChunk.pb.h>
40
#include <boost/algorithm/string.hpp>
41
#include <boost/range/algorithm_ext/erase.hpp>
42

  
43
using namespace std;
44
using namespace rsb;
45
using namespace rsb::patterns;
46

  
47
MiddlewareRSB::MiddlewareRSB(string scope) : Middleware(scope) {
48
	printf("> new MiddlewareRSB() on base scope '%s'\n", base_scope.c_str());
49
	init();
50
}
51

  
52
void MiddlewareRSB::init(void) {
53
	printf("> MiddlewareRSB::init() registering converters\n");
54

  
55
	try {
56
		// converter for EmotionState
57
		rsb::converter::Converter<string>::Ptr emotionStateConverter(
58
		   new rsb::converter::ProtocolBufferConverter<rst::animation::EmotionExpression>());
59
		rsb::converter::converterRepository<string>()->registerConverter(emotionStateConverter);
60

  
61
		// converter for Utterance
62
		// rsb::converter::Converter<string>::Ptr UtteranceConverter(new
63
		// rsb::converter::ProtocolBufferConverter<rst::audition::Utterance>());
64
		// rsb::converter::converterRepository<string>()->registerConverter(UtteranceConverter);
65

  
66
		// converter for GazeTarget
67
		rsb::converter::Converter<string>::Ptr gazeTargetConverter(
68
		   new rsb::converter::ProtocolBufferConverter<rst::animation::BinocularHeadGaze>());
69
		rsb::converter::converterRepository<string>()->registerConverter(gazeTargetConverter);
70

  
71
		// converter for MouthTarget
72
		/// rsb::converter::Converter<string>::Ptr mouthTargetConverter(new
73
		/// rsb::converter::ProtocolBufferConverter<rst::robot::MouthTarget>());
74
		/// rsb::converter::converterRepository<string>()->registerConverter(mouthTargetConverter);
75

  
76
		// converter for Animation
77
		rsb::converter::Converter<string>::Ptr animationConverter(
78
		   new rsb::converter::ProtocolBufferConverter<rst::animation::HeadAnimation>());
79
		rsb::converter::converterRepository<string>()->registerConverter(animationConverter);
80
	}
81
	catch (std::invalid_argument e) {
82
		printf("> converters already registered\n");
83
	}
84

  
85
	// first get a factory instance that is used to create RSB domain objects
86
	Factory& factory = getFactory();
87

  
88
	// get server
89
	string scope = base_scope + "/set/";
90
	hlrc_server = factory.createRemoteServer(scope);
91

  
92
	printf("> init done\n");
93
}
94

  
95
void MiddlewareRSB::publish_emotion(string scope_target, RobotEmotion e, bool blocking) {
96
	std::shared_ptr<rst::animation::EmotionExpression> request(new rst::animation::EmotionExpression());
97

  
98
	switch (e.value) {
99
		default:
100
			printf("> WANRING: invalid emotion id %d. defaulting to NEUTRAL\n", e.value);
101
			// fall through:
102
		case (RobotEmotion::NEUTRAL):
103
			request->set_emotion(rst::animation::EmotionExpression::NEUTRAL);
104
			break;
105
		case (RobotEmotion::HAPPY):
106
			request->set_emotion(rst::animation::EmotionExpression::HAPPY);
107
			break;
108
		case (RobotEmotion::SAD):
109
			request->set_emotion(rst::animation::EmotionExpression::SAD);
110
			break;
111
		case (RobotEmotion::ANGRY):
112
			request->set_emotion(rst::animation::EmotionExpression::ANGRY);
113
			break;
114
		case (RobotEmotion::SURPRISED):
115
			request->set_emotion(rst::animation::EmotionExpression::SURPRISED);
116
			break;
117
		case (RobotEmotion::FEAR):
118
			request->set_emotion(rst::animation::EmotionExpression::FEAR);
119
			break;
120
	}
121

  
122
	request->set_duration(e.time_ms);
123

  
124
	if (blocking) {
125
		hlrc_server->call<rst::animation::EmotionExpression>(scope_target, request);
126
	}
127
	else {
128
		hlrc_server->callAsync<rst::animation::EmotionExpression>(scope_target, request);
129
	}
130
}
131

  
132
void MiddlewareRSB::publish_current_emotion(RobotEmotion e, bool blocking) {
133
	publish_emotion("currentEmotion", e, blocking);
134
}
135

  
136
void MiddlewareRSB::publish_default_emotion(RobotEmotion e, bool blocking) {
137
	publish_emotion("defaultEmotion", e, blocking);
138
}
139

  
140
void MiddlewareRSB::publish_gaze_target(RobotGaze incoming_target, bool blocking) {
141
	std::shared_ptr<rst::animation::BinocularHeadGaze> request(new rst::animation::BinocularHeadGaze());
142

  
143
	std::shared_ptr<rst::geometry::SphericalDirectionFloat> target(new rst::geometry::SphericalDirectionFloat());
144
	target->set_azimuth(incoming_target.pan);
145
	target->set_elevation(incoming_target.tilt);
146
	request->set_allocated_target(target.get());
147

  
148
	request->set_eye_vergence(incoming_target.vergence);
149

  
150
	std::shared_ptr<rst::geometry::SphericalDirectionFloat> offset(new rst::geometry::SphericalDirectionFloat());
151
	offset->set_azimuth(incoming_target.pan_offset);
152
	offset->set_elevation(incoming_target.tilt_offset);
153
	request->set_allocated_offset(offset.get());
154

  
155
	if (blocking) {
156
		hlrc_server->call<rst::animation::BinocularHeadGaze>("gaze", request);
157
	}
158
	else {
159
		hlrc_server->callAsync<rst::animation::BinocularHeadGaze>("gaze", request);
160
	}
161
}
162

  
163
void MiddlewareRSB::publish_lookat_target(float x, float y, float z, const std::string frame_id, bool blocking, float roll) {
164
	std::cerr << "not yet implemented" << std::endl;
165
}
166

  
167
void MiddlewareRSB::publish_mouth_target(RobotMouth target, bool blocking) {
168
	/*
169
	    std::shared_ptr<rst::robot::MouthTarget> request(new rst::robot::MouthTarget());
170

  
171
	    request->set_position_left(  target.position_left);
172
	    request->set_position_center(target.position_center);
173
	    request->set_position_right( target.position_right);
174

  
175
	    request->set_opening_left(  target.opening_left);
176
	    request->set_opening_center(target.opening_center);
177
	    request->set_opening_right( target.opening_right);
178

  
179
	    if (blocking){
180
	        hlrc_server->call<rst::robot::MouthTarget>("mouth", request);
181
	    }else{
182
	        hlrc_server->callAsync<rst::robot::MouthTarget>("mouth", request);
183
	    }
184
	*/
185
	printf("> ERROR: mouth targets not yet implemented in RSB middleware!\n");
186
}
187

  
188
void MiddlewareRSB::publish_head_animation(RobotHeadAnimation a, bool blocking) {
189
	std::shared_ptr<rst::animation::HeadAnimation> request(new rst::animation::HeadAnimation());
190

  
191
	switch (a.value) {
192
		default:
193
			printf("> WANRING: invalid animation id %d. defaulting to IDLE", a.value);
194
			// fall through:
195
		case (RobotHeadAnimation::IDLE):
196
			request->set_animation(rst::animation::HeadAnimation::IDLE);
197
			break;
198
		case (RobotHeadAnimation::HEAD_NOD):
199
			request->set_animation(rst::animation::HeadAnimation::HEAD_NOD);
200
			break;
201
		case (RobotHeadAnimation::HEAD_SHAKE):
202
			request->set_animation(rst::animation::HeadAnimation::HEAD_SHAKE);
203
			break;
204
		case (RobotHeadAnimation::EYEBLINK_L):
205
			request->set_animation(rst::animation::HeadAnimation::EYEBLINK_LEFT);
206
			break;
207
		case (RobotHeadAnimation::EYEBLINK_R):
208
			request->set_animation(rst::animation::HeadAnimation::EYEBLINK_RIGHT);
209
			break;
210
		case (RobotHeadAnimation::EYEBLINK_BOTH):
211
			request->set_animation(rst::animation::HeadAnimation::EYEBLINK_BOTH);
212
			break;
213
		case (RobotHeadAnimation::EYEBROWS_RAISE):
214
			request->set_animation(rst::animation::HeadAnimation::EYEBROWS_RAISE);
215
			break;
216
		case (RobotHeadAnimation::EYEBROWS_LOWER):
217
			request->set_animation(rst::animation::HeadAnimation::EYEBROWS_LOWER);
218
			break;
219
		case (RobotHeadAnimation::ENGAGEMENT_LEFT):
220
			request->set_animation(rst::animation::HeadAnimation::ENGAGEMENT_LEFT);
221
			break;
222
		case (RobotHeadAnimation::ENGAGEMENT_RIGHT):
223
			request->set_animation(rst::animation::HeadAnimation::ENGAGEMENT_RIGHT);
224
			break;
225
	}
226

  
227
	request->set_repetitions(a.repetitions);
228
	request->set_emphasis_scale(a.scale);
229
	request->set_duration_each(a.time_ms);
230

  
231
	if (blocking) {
232
		hlrc_server->call<rst::animation::HeadAnimation>("animation", request);
233
	}
234
	else {
235
		hlrc_server->callAsync<rst::animation::HeadAnimation>("animation", request);
236
	}
237
}
238

  
239
void MiddlewareRSB::publish_speech(string text, bool blocking) {
240
	// say it
241
	std::shared_ptr<std::string> request(new string(text));
242

  
243
	if (blocking) {
244
		hlrc_server->call<std::string>("speech", request);
245
	}
246
	else {
247
		hlrc_server->callAsync<std::string>("speech", request);
248
	}
249
}
250

  
251
#endif
client/cpp/src/RobotController.cpp
29 29
#include "RobotController.h"
30 30
#include "Middleware.h"
31 31
#include "MiddlewareROS.h"
32
#include "MiddlewareRSB.h"
33 32

  
34 33
using namespace std;
35 34

  
......
38 37
		// intantiate ROS mw
39 38