humotion / src / client / middleware_ros.cpp @ 414a3516
History | View | Annotate | Download (4.151 KB)
1 | 8c6c1163 | Simon Schulz | /*
|
---|---|---|---|
2 | * This file is part of humotion
|
||
3 | *
|
||
4 | * Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
|
||
5 | * http://opensource.cit-ec.de/projects/humotion
|
||
6 | *
|
||
7 | * This file may be licensed under the terms of the
|
||
8 | * GNU Lesser General Public License Version 3 (the ``LGPL''),
|
||
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 LGPL for the specific language
|
||
14 | * governing rights and limitations.
|
||
15 | *
|
||
16 | * You should have received a copy of the LGPL along with this
|
||
17 | * program. If not, go to http://www.gnu.org/licenses/lgpl.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 | #include "client/middleware_ros.h" |
||
29 | |||
30 | 1c758459 | Simon Schulz | #include "humotion/mouth.h" |
31 | #include "humotion/gaze.h" |
||
32 | 8c6c1163 | Simon Schulz | #include <boost/range/algorithm/remove_if.hpp> |
33 | #include <boost/algorithm/string/classification.hpp> |
||
34 | |||
35 | using namespace std; |
||
36 | using namespace boost; |
||
37 | using namespace humotion; |
||
38 | using namespace humotion::client; |
||
39 | |||
40 | //! constructor
|
||
41 | MiddlewareROS::MiddlewareROS(string scope) : Middleware(scope){
|
||
42 | //start ros core
|
||
43 | if (!ros::isInitialized()){
|
||
44 | tick_necessary = true;
|
||
45 | string node_name = "humotion_client__"+ base_scope; |
||
46 | node_name.erase(boost::remove_if(node_name, boost::is_any_of("/")), node_name.end());
|
||
47 | |||
48 | ros::M_string no_remapping; |
||
49 | ros::init(no_remapping, node_name); |
||
50 | }else{
|
||
51 | //another ros thread takes care of spinning
|
||
52 | tick_necessary = false;
|
||
53 | } |
||
54 | |||
55 | 7ed40bef | Simon Schulz | //create node handle
|
56 | 8c6c1163 | Simon Schulz | ros::NodeHandle n; |
57 | |||
58 | 7ed40bef | Simon Schulz | //set up publishers:
|
59 | 8c6c1163 | Simon Schulz | mouth_target_publisher = n.advertise<humotion::mouth>(base_scope + "/humotion/mouth/target", 100); |
60 | gaze_target_publisher = n.advertise<humotion::gaze>(base_scope + "/humotion/gaze/target", 100); |
||
61 | |||
62 | } |
||
63 | |||
64 | //! destructor
|
||
65 | MiddlewareROS::~MiddlewareROS(){ |
||
66 | } |
||
67 | |||
68 | //! connection ok?
|
||
69 | //! \return true if conn is alive
|
||
70 | bool MiddlewareROS::ok(){
|
||
71 | return ros::ok();
|
||
72 | } |
||
73 | |||
74 | //! do a single tick
|
||
75 | void MiddlewareROS::tick(){
|
||
76 | if (tick_necessary){
|
||
77 | ros::spinOnce(); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | |||
82 | //! send mouth target to server
|
||
83 | void MiddlewareROS::send_mouth_target(){
|
||
84 | //build target packet:
|
||
85 | humotion::mouth msg; |
||
86 | |||
87 | //set timestamp
|
||
88 | msg.header.stamp = ros::Time::now(); |
||
89 | |||
90 | msg.position.left = mouth_state.position_left; |
||
91 | msg.position.center = mouth_state.position_center; |
||
92 | msg.position.right = mouth_state.position_right; |
||
93 | |||
94 | msg.opening.left = mouth_state.opening_left; |
||
95 | msg.opening.center = mouth_state.opening_center; |
||
96 | msg.opening.right = mouth_state.opening_right; |
||
97 | |||
98 | |||
99 | //add position to send queue
|
||
100 | mouth_target_publisher.publish(msg); |
||
101 | |||
102 | //allow ros to handle data
|
||
103 | tick(); |
||
104 | } |
||
105 | |||
106 | //! send mouth target to server
|
||
107 | void MiddlewareROS::send_gaze_target(){
|
||
108 | //build target packet:
|
||
109 | humotion::gaze msg; |
||
110 | |||
111 | //set timestamp
|
||
112 | msg.header.stamp = ros::Time::now(); |
||
113 | |||
114 | msg.pan = gaze_state.pan; |
||
115 | msg.tilt = gaze_state.tilt; |
||
116 | msg.roll = gaze_state.roll; |
||
117 | msg.vergence = gaze_state.vergence; |
||
118 | |||
119 | msg.pan_offset = gaze_state.pan_offset; |
||
120 | msg.tilt_offset = gaze_state.tilt_offset; |
||
121 | msg.roll_offset = gaze_state.roll_offset; |
||
122 | |||
123 | msg.eyelid_opening_upper = gaze_state.eyelid_opening_upper; |
||
124 | msg.eyelid_opening_lower = gaze_state.eyelid_opening_lower; |
||
125 | |||
126 | msg.eyebrow_left = gaze_state.eyebrow_left; |
||
127 | msg.eyebrow_right = gaze_state.eyebrow_right; |
||
128 | |||
129 | msg.eyeblink_request_left = gaze_state.eyeblink_request_left; |
||
130 | msg.eyeblink_request_right = gaze_state.eyeblink_request_right; |
||
131 | |||
132 | 1c758459 | Simon Schulz | if (gaze_state.gaze_type == GazeState::GAZETYPE_ABSOLUTE){
|
133 | msg.gaze_type = humotion::gaze::GAZETYPE_ABSOLUTE; |
||
134 | 89374d69 | Simon Schulz | }else{
|
135 | 1c758459 | Simon Schulz | msg.gaze_type = humotion::gaze::GAZETYPE_RELATIVE; |
136 | 89374d69 | Simon Schulz | } |
137 | d21cdd06 | Simon Schulz | msg.gaze_timestamp.sec = gaze_state.timestamp.sec; |
138 | msg.gaze_timestamp.nsec = gaze_state.timestamp.nsec; |
||
139 | 8c6c1163 | Simon Schulz | |
140 | //add position to send queue
|
||
141 | gaze_target_publisher.publish(msg); |
||
142 | |||
143 | //allow ros to handle data
|
||
144 | tick(); |
||
145 | } |