hlrc / server / src / MiddlewareROS.cpp @ aa50d3e9
History | View | Annotate | Download (4.083 KB)
1 |
/*
|
---|---|
2 |
* This file is part of hlrc_server
|
3 |
*
|
4 |
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
|
5 |
* http://opensource.cit-ec.de/projects/hlrc_server
|
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 |
#include "MiddlewareROS.h" |
30 |
|
31 |
#ifdef ROS_SUPPORT
|
32 |
|
33 |
#include <cstdio> |
34 |
|
35 |
//CallbackWrapper:
|
36 |
#include <boost/range/algorithm/remove_if.hpp> |
37 |
#include <boost/algorithm/string/classification.hpp> |
38 |
|
39 |
using namespace std; |
40 |
using namespace hlrc_server; |
41 |
|
42 |
MiddlewareROS::MiddlewareROS(Arbiter *arbiter, std::string scope) : Middleware(arbiter, scope){
|
43 |
init(); |
44 |
} |
45 |
|
46 |
MiddlewareROS::~MiddlewareROS(){ |
47 |
|
48 |
} |
49 |
|
50 |
void MiddlewareROS::init(){
|
51 |
string scope = base_scope + "/set/"; |
52 |
|
53 |
string node_name = "hlrc_server__"+ base_scope; |
54 |
node_name.erase(boost::remove_if(node_name, boost::is_any_of("/")), node_name.end());
|
55 |
|
56 |
printf("> registering on ROS as node %s\n",node_name.c_str());
|
57 |
if (ros::isInitialized()){
|
58 |
//ros is already active, no need to take care of that
|
59 |
tick_necessary = false;
|
60 |
}else{
|
61 |
printf("> ROS not initialized, calling ros::init()\n");
|
62 |
ros::M_string no_remapping; |
63 |
ros::init(no_remapping, node_name); |
64 |
tick_necessary = true;
|
65 |
} |
66 |
|
67 |
//create node handle
|
68 |
//printf("> creating ros node handle\n");
|
69 |
//ros::NodeHa
|
70 |
ros::NodeHandle n; |
71 |
|
72 |
printf("> setting up ROS services...\n");
|
73 |
//FIXME//init_callback("speech", LocalServer::CallbackPtr(new SpeechCallbackWrapper(this)));
|
74 |
|
75 |
//ros::AsyncSpinner *spinner = new ros::AsyncSpinner(4); // Use 4 threads
|
76 |
//spinner->start();
|
77 |
|
78 |
animation_action_server = new AnimationCallbackWrapper(this, scope, "animation"); |
79 |
utterance_action_server = new UtteranceCallbackWrapper(this, scope, "utterance"); |
80 |
current_emotion_action_server = new EmotionCallbackWrapper(this, scope, "currentEmotion"); |
81 |
default_emotion_action_server = new EmotionCallbackWrapper(this, scope, "defaultEmotion"); |
82 |
gaze_action_server = new GazeCallbackWrapper(this, scope, "gaze"); |
83 |
mouth_action_server = new MouthCallbackWrapper(this, scope, "mouth"); |
84 |
speech_action_server = new SpeechCallbackWrapper(this, scope, "speech"); |
85 |
|
86 |
printf("> init done\n");
|
87 |
} |
88 |
|
89 |
void MiddlewareROS::tick(){
|
90 |
if (tick_necessary){
|
91 |
ros::spinOnce(); |
92 |
} |
93 |
} |
94 |
|
95 |
//call a tts system to convert a string to an utterance
|
96 |
Utterance MiddlewareROS::tts_call(string text){
|
97 |
//double tts_timeout = 1.0; //seconds. DO NOT CHANGE THIS!
|
98 |
|
99 |
Utterance utterance; |
100 |
|
101 |
printf("> WARNING: ros tts call not implemented yet\n");
|
102 |
|
103 |
/*
|
104 |
//build request
|
105 |
boost::shared_ptr<std::string> request(new string(text));
|
106 |
|
107 |
//try to fetch it asynchronously:
|
108 |
try{
|
109 |
RemoteServer::DataFuture<rst::audition::Utterance> future_ptr = tts_server->callAsync<rst::audition::Utterance>("create_utterance", request);
|
110 |
|
111 |
//try to fetch the result
|
112 |
boost::shared_ptr<rst::audition::Utterance> utterance_ptr = future_ptr.get(tts_timeout);
|
113 |
utterance = UtteranceRSB(*(utterance_ptr.get()));
|
114 |
|
115 |
}catch(rsc::threading::FutureTimeoutException e){
|
116 |
printf("> error: tts_call timed out after %3.1f seconds.\n", tts_timeout);
|
117 |
}catch(rsc::threading::FutureTaskExecutionException e){
|
118 |
printf("> error: tts_call failed: %s\n", e.what());
|
119 |
}
|
120 |
|
121 |
printf("> done. got utterance (text=%s)\n",utterance.get_text().c_str());
|
122 |
*/
|
123 |
return utterance;
|
124 |
} |
125 |
|
126 |
|
127 |
#endif
|