Revision 0c15613f server/src/MiddlewareROS.cpp

View differences:

server/src/MiddlewareROS.cpp
35 35
//CallbackWrapper:
36 36
#include <boost/range/algorithm/remove_if.hpp>
37 37
#include <boost/algorithm/string/classification.hpp>
38
#include <actionlib/client/simple_action_client.h>
39
#include "ROS/UtteranceROS.h"
38 40

  
39 41
using namespace std;
40 42
using namespace hlrc_server;
41 43

  
44
template <typename actionspec>
45
actionlib::SimpleActionClient<actionspec> * create_action_client(string scope){
46
    printf("> starting SimpleActionClient on %s\n",scope.c_str());
47

  
48
    actionlib::SimpleActionClient<actionspec> *ac = new actionlib::SimpleActionClient<actionspec>(scope, true);
49

  
50
    if (!ac->waitForServer(ros::Duration(1))){
51
        char buf[256];
52
        snprintf(buf, 256, "ERROR: action service %s not ready", scope.c_str());
53
        throw runtime_error(buf);
54
    }
55
    return ac;
56
}
57

  
58

  
42 59
MiddlewareROS::MiddlewareROS(Arbiter *arbiter, std::string scope) : Middleware(arbiter, scope){
43 60
    init();
44 61
}
......
83 100
    mouth_action_server = new MouthCallbackWrapper(this, scope, "mouth");
84 101
    speech_action_server = new SpeechCallbackWrapper(this, scope, "speech");
85 102

  
103
    //create tts client
104
    tts_ac = create_action_client<hlrc_server::ttsAction>(base_scope + "/tts_provider");
105

  
106

  
107

  
86 108
    printf("> init done\n");
87 109
}
88 110

  
......
98 120

  
99 121
    boost::shared_ptr<Utterance> utterance(new Utterance());
100 122

  
101
    printf("> WARNING: ros tts call not implemented yet\n");
123
    hlrc_server::ttsGoal goal;
102 124

  
103
/*
104
    //build request
105
    boost::shared_ptr<std::string> request(new string(text));
125
    goal.text = text;
106 126

  
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);
127
    //send
128
    tts_ac->sendGoal(goal);
110 129

  
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()));
130
    //call ros:
131
    bool finished_before_timeout = tts_ac->waitForResult(ros::Duration(ROS_ACTION_CALL_TIMEOUT));
114 132

  
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());
133
    if (!finished_before_timeout){
134
        printf("> ERROR: NO REPLY to utterance action call received within %4.2f s\n",ROS_ACTION_CALL_TIMEOUT);
135
    }else{
136
        //done, return utterance ptr
137
        ttsResultConstPtr tts_res = tts_ac->getResult();
138
        boost::shared_ptr<Utterance> utterance(new UtteranceROS(tts_res));
139
        printf("> done. got utterance (text=%s)\n",utterance->get_text().c_str());
140
        return utterance;
119 141
    }
120 142

  
121
    printf("> done. got utterance (text=%s)\n",utterance.get_text().c_str());
122
    */
123

  
143
    printf("> failed... got no utterance\n");
124 144
    return utterance;
125 145
}
126 146

  

Also available in: Unified diff