Revision f150aab5 server/include/ROS/GazeCallbackWrapperROS.h
server/include/ROS/GazeCallbackWrapperROS.h | ||
---|---|---|
1 | 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 |
*/ |
|
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 | 28 |
|
29 | 29 |
#pragma once |
30 | 30 |
#include "hlrc_server/gazetargetAction.h" |
31 | 31 |
#include "CallbackWrapperROS.h" |
32 | 32 |
|
33 |
//callback handler incoming gaze requests: |
|
34 |
class GazeCallbackWrapper : CallbackWrapper<hlrc_server::gazetargetAction>{ |
|
33 |
// callback handler incoming gaze requests:
|
|
34 |
class GazeCallbackWrapper : CallbackWrapper<hlrc_server::gazetargetAction> {
|
|
35 | 35 |
protected: |
36 |
hlrc_server::gazetargetFeedback feedback;
|
|
37 |
hlrc_server::gazetargetResult result;
|
|
36 |
hlrc_server::gazetargetFeedback feedback;
|
|
37 |
hlrc_server::gazetargetResult result;
|
|
38 | 38 |
|
39 | 39 |
public: |
40 |
|
|
41 |
GazeCallbackWrapper(Middleware *mw, std::string scope, std::string name) : CallbackWrapper<hlrc_server::gazetargetAction>(mw, scope, name, boost::bind(&GazeCallbackWrapper::call, this, _1)){
|
|
42 |
//
|
|
43 |
};
|
|
44 |
|
|
45 |
void call(const GoalConstPtr &goal){
|
|
46 |
feedback.result = 1;
|
|
47 |
|
|
48 |
hlrc_server::gazetargetGoalConstPtr request = goal;
|
|
49 |
/*printf("> incoming gaze (p=%3.1f t=%3.1f r=%3.1f / v=%3.1f) [%s ts=%f]\n",
|
|
50 |
request->pan,
|
|
51 |
request->tilt,
|
|
52 |
request->roll,
|
|
53 |
request->vergence,
|
|
54 |
request->gaze_type==hlrc_server::gazetargetGoal::GAZETARGET_ABSOLUTE?"ABSOLUTE":"RELATIVE",
|
|
55 |
request->gaze_timestamp.toSec()
|
|
56 |
);*/
|
|
57 |
|
|
58 |
humotion::GazeState gaze_state;
|
|
59 |
|
|
60 |
//fill in gaze
|
|
61 |
gaze_state.pan = request->pan;
|
|
62 |
gaze_state.tilt = request->tilt;
|
|
63 |
gaze_state.roll = request->roll;
|
|
64 |
|
|
65 |
//use timestamp from request
|
|
66 |
gaze_state.timestamp.set(request->gaze_timestamp.sec, request->gaze_timestamp.nsec);
|
|
67 |
|
|
68 |
if (request->gaze_type == hlrc_server::gazetargetGoal::GAZETARGET_ABSOLUTE){
|
|
69 |
gaze_state.gaze_type = humotion::GazeState::GAZETYPE_ABSOLUTE;
|
|
70 |
}else{
|
|
71 |
gaze_state.gaze_type = humotion::GazeState::GAZETYPE_RELATIVE;
|
|
72 |
}
|
|
73 |
|
|
74 |
//default: |
|
75 |
gaze_state.vergence = request->vergence;
|
|
76 |
gaze_state.pan_offset = request->pan_offset;
|
|
77 |
gaze_state.tilt_offset = request->tilt_offset;
|
|
78 |
|
|
79 |
//processing |
|
80 |
feedback.result = 1;
|
|
81 |
as_.publishFeedback(feedback);
|
|
82 |
|
|
83 |
//send to application: |
|
84 |
mw->gaze_callback(gaze_state);
|
|
85 |
|
|
86 |
if (feedback.result){ |
|
87 |
result.result = feedback.result;
|
|
88 |
as_.setSucceeded(result);
|
|
89 |
}else{
|
|
90 |
as_.setAborted(result);
|
|
91 |
}
|
|
92 |
|
|
93 |
|
|
94 |
}
|
|
40 |
GazeCallbackWrapper(Middleware* mw, std::string scope, std::string name) |
|
41 |
: CallbackWrapper<hlrc_server::gazetargetAction>(mw, scope, name, boost::bind(&GazeCallbackWrapper::call, this, _1)){
|
|
42 |
//
|
|
43 |
};
|
|
44 |
|
|
45 |
void call(const GoalConstPtr& goal) {
|
|
46 |
feedback.result = 1;
|
|
47 |
|
|
48 |
hlrc_server::gazetargetGoalConstPtr request = goal;
|
|
49 |
/*printf("> incoming gaze (p=%3.1f t=%3.1f r=%3.1f / v=%3.1f) [%s ts=%f]\n",
|
|
50 |
request->pan,
|
|
51 |
request->tilt,
|
|
52 |
request->roll,
|
|
53 |
request->vergence,
|
|
54 |
request->gaze_type==hlrc_server::gazetargetGoal::GAZETARGET_ABSOLUTE?"ABSOLUTE":"RELATIVE",
|
|
55 |
request->gaze_timestamp.toSec()
|
|
56 |
);*/
|
|
57 |
|
|
58 |
humotion::GazeState gaze_state;
|
|
59 |
|
|
60 |
// fill in gaze
|
|
61 |
gaze_state.pan = request->pan;
|
|
62 |
gaze_state.tilt = request->tilt;
|
|
63 |
gaze_state.roll = request->roll;
|
|
64 |
|
|
65 |
// use timestamp from request
|
|
66 |
gaze_state.timestamp.set(request->gaze_timestamp.sec, request->gaze_timestamp.nsec);
|
|
67 |
|
|
68 |
if (request->gaze_type == hlrc_server::gazetargetGoal::GAZETARGET_ABSOLUTE) {
|
|
69 |
gaze_state.gaze_type = humotion::GazeState::GAZETYPE_ABSOLUTE;
|
|
70 |
}
|
|
71 |
else {
|
|
72 |
gaze_state.gaze_type = humotion::GazeState::GAZETYPE_RELATIVE;
|
|
73 |
} |
|
74 |
|
|
75 |
// default:
|
|
76 |
gaze_state.vergence = request->vergence;
|
|
77 |
gaze_state.pan_offset = request->pan_offset;
|
|
78 |
gaze_state.tilt_offset = request->tilt_offset; |
|
79 |
|
|
80 |
// processing
|
|
81 |
feedback.result = 1;
|
|
82 |
as_.publishFeedback(feedback); |
|
83 |
|
|
84 |
// send to application:
|
|
85 |
mw->gaze_callback(gaze_state); |
|
86 |
|
|
87 |
if (feedback.result) {
|
|
88 |
result.result = feedback.result;
|
|
89 |
as_.setSucceeded(result);
|
|
90 |
}
|
|
91 |
else {
|
|
92 |
as_.setAborted(result); |
|
93 |
} |
|
94 |
}
|
|
95 | 95 |
}; |
Also available in: Unified diff