Statistics
| Branch: | Tag: | Revision:

hlrc / server / include / ROS / GazeCallbackWrapperROS.h @ aa1958c6

History | View | Annotate | Download (3.009 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
#pragma once
30
#include "hlrc_server/gazetargetAction.h"
31
#include "CallbackWrapperROS.h"
32

    
33
//callback handler incoming gaze requests:
34
class GazeCallbackWrapper : CallbackWrapper<hlrc_server::gazetargetAction>{
35
protected:
36
    hlrc_server::gazetargetFeedback feedback;
37
    hlrc_server::gazetargetResult result;
38

    
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
    //! this provides a consistent transformation of ros ts to double
46
    double convert_ros_to_timestamp_ms(ros::Time t){
47
            return t.sec + t.nsec/1000000000.0;
48
    }
49

    
50

    
51
    void call(const GoalConstPtr &goal){
52
        feedback.result = 1;
53

    
54
        hlrc_server::gazetargetGoalConstPtr request = goal;
55
        //printf("> incoming gaze (p=%3.1f t=%3.1f r=%3.1f / v=%3.1f)\n", request->pan, request->tilt, request->roll, request->vergence);
56

    
57
        humotion::GazeState gaze_state;
58

    
59
        //fill in gaze
60
        gaze_state.pan   = request->pan;
61
        gaze_state.tilt  = request->tilt;
62
        gaze_state.roll  = request->roll;
63

    
64
        //use timestamp from request
65
        gaze_state.timestamp = convert_ros_to_timestamp_ms(request->timestamp); //get_timestamp();
66
        if (request->gaze_type == hlrc_server::gazetargetGoal::GAZETARGET_ABSOLUTE){
67
            gaze_state.type = humotion::GazeState::ABSOLUTE;
68
        }else{
69
            gaze_state.type = humotion::GazeState::RELATIVE;
70
        }
71

    
72
        //default:
73
        gaze_state.vergence  = request->vergence;
74

    
75
        gaze_state.pan_offset = request->pan_offset;
76
        gaze_state.tilt_offset = request->tilt_offset;
77

    
78
        //processing
79
        feedback.result = 1;
80
        as_.publishFeedback(feedback);
81

    
82
        //send to application:
83
        mw->gaze_callback(gaze_state);
84

    
85
        if (feedback.result){
86
            result.result = feedback.result;
87
            as_.setSucceeded(result);
88
        }else{
89
            as_.setAborted(result);
90
        }
91

    
92

    
93
    }
94
};